|
@@ -831,72 +831,41 @@ int piBoardRev (void) |
|
|
|
|
|
|
|
|
void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) |
|
|
void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) |
|
|
{ |
|
|
{ |
|
|
FILE *cpuFd ; |
|
|
|
|
|
char line [120] ; |
|
|
|
|
|
|
|
|
FILE *dtcFd ; |
|
|
char *c ; |
|
|
char *c ; |
|
|
unsigned int revision ; |
|
|
unsigned int revision ; |
|
|
int bRev, bType, bProc, bMfg, bMem, bWarranty ; |
|
|
int bRev, bType, bProc, bMfg, bMem, bWarranty ; |
|
|
|
|
|
unsigned char buffer[4]; |
|
|
|
|
|
|
|
|
// Will deal with the properly later on - for now, lets just get it going... |
|
|
// Will deal with the properly later on - for now, lets just get it going... |
|
|
// unsigned int modelNum ; |
|
|
// unsigned int modelNum ; |
|
|
|
|
|
|
|
|
(void)piGpioLayout () ; // Call this first to make sure all's OK. Don't care about the result. |
|
|
(void)piGpioLayout () ; // Call this first to make sure all's OK. Don't care about the result. |
|
|
|
|
|
|
|
|
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL) |
|
|
|
|
|
piGpioLayoutOops ("Unable to open /proc/cpuinfo") ; |
|
|
|
|
|
|
|
|
|
|
|
while (fgets (line, 120, cpuFd) != NULL) |
|
|
|
|
|
if (strncmp (line, "Revision", 8) == 0) |
|
|
|
|
|
break ; |
|
|
|
|
|
|
|
|
|
|
|
fclose (cpuFd) ; |
|
|
|
|
|
|
|
|
|
|
|
if (strncmp (line, "Revision", 8) != 0) |
|
|
|
|
|
piGpioLayoutOops ("No \"Revision\" line") ; |
|
|
|
|
|
|
|
|
|
|
|
// Chomp trailing CR/NL |
|
|
|
|
|
|
|
|
|
|
|
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c) |
|
|
|
|
|
*c = 0 ; |
|
|
|
|
|
|
|
|
|
|
|
if (wiringPiDebug) |
|
|
|
|
|
printf ("piBoardId: Revision string: %s\n", line) ; |
|
|
|
|
|
|
|
|
|
|
|
// Need to work out if it's using the new or old encoding scheme: |
|
|
|
|
|
|
|
|
|
|
|
// Scan to the first character of the revision number |
|
|
|
|
|
|
|
|
|
|
|
for (c = line ; *c ; ++c) |
|
|
|
|
|
if (*c == ':') |
|
|
|
|
|
break ; |
|
|
|
|
|
|
|
|
|
|
|
if (*c != ':') |
|
|
|
|
|
piGpioLayoutOops ("Bogus \"Revision\" line (no colon)") ; |
|
|
|
|
|
|
|
|
|
|
|
// Chomp spaces |
|
|
|
|
|
|
|
|
|
|
|
++c ; |
|
|
|
|
|
while (isspace (*c)) |
|
|
|
|
|
++c ; |
|
|
|
|
|
|
|
|
|
|
|
if (!isxdigit (*c)) |
|
|
|
|
|
piGpioLayoutOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ; |
|
|
|
|
|
|
|
|
if ((dtcFd = fopen("/proc/device-tree/system/linux,revision", "r")) == NULL){ |
|
|
|
|
|
piGpioLayoutOops ("Unable to open /proc/device-tree/system/linux,revision") ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x |
|
|
|
|
|
|
|
|
fread(buffer,sizeof(buffer),1,dtcFd); |
|
|
|
|
|
|
|
|
// Check for new way: |
|
|
// Check for new way: |
|
|
|
|
|
|
|
|
|
|
|
revision = (unsigned int)buffer[0] << 24 | |
|
|
|
|
|
(unsigned int)buffer[1] << 16 | |
|
|
|
|
|
(unsigned int)buffer[2] << 8 | |
|
|
|
|
|
(unsigned int)buffer[3]; |
|
|
|
|
|
|
|
|
if ((revision & (1 << 23)) != 0) // New way |
|
|
if ((revision & (1 << 23)) != 0) // New way |
|
|
{ |
|
|
{ |
|
|
if (wiringPiDebug) |
|
|
if (wiringPiDebug) |
|
|
printf ("piBoardId: New Way: revision is: 0x%08X\n", revision) ; |
|
|
printf ("piBoardId: New Way: revision is: 0x%08X\n", revision) ; |
|
|
|
|
|
|
|
|
bRev = (revision & (0x0F << 0)) >> 0 ; |
|
|
|
|
|
bType = (revision & (0xFF << 4)) >> 4 ; |
|
|
|
|
|
bProc = (revision & (0x0F << 12)) >> 12 ; // Not used for now. |
|
|
|
|
|
bMfg = (revision & (0x0F << 16)) >> 16 ; |
|
|
|
|
|
bMem = (revision & (0x07 << 20)) >> 20 ; |
|
|
|
|
|
bWarranty = (revision & (0x03 << 24)) != 0 ; |
|
|
|
|
|
|
|
|
bRev = (buffer[1] & (0x0F << 0)) >> 0 ; |
|
|
|
|
|
bType = (buffer[1] & (0xFF << 4)) >> 4 ; |
|
|
|
|
|
bProc = (buffer[2] & (0xFF << 4)) >> 4 ; // Not used for now. |
|
|
|
|
|
bMfg = (buffer[2] & (0x0F << 0)) >> 0 ; |
|
|
|
|
|
bMem = (buffer[3] & (0x07 << 4)) >> 4 ; |
|
|
|
|
|
bWarranty = (buffer[3] & (0x03 << 0)) != 0 ; |
|
|
|
|
|
|
|
|
*model = bType ; |
|
|
*model = bType ; |
|
|
*rev = bRev ; |
|
|
*rev = bRev ; |
|
@@ -907,6 +876,8 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) |
|
|
if (wiringPiDebug) |
|
|
if (wiringPiDebug) |
|
|
printf ("piBoardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n", |
|
|
printf ("piBoardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n", |
|
|
bRev, bType, bProc, bMfg, bMem, bWarranty) ; |
|
|
bRev, bType, bProc, bMfg, bMem, bWarranty) ; |
|
|
|
|
|
|
|
|
|
|
|
fclose(dtcFd); |
|
|
} |
|
|
} |
|
|
else // Old way |
|
|
else // Old way |
|
|
{ |
|
|
{ |
|
|