This commit is contained in:
@@ -61,7 +61,8 @@ SRC = wiringPi.c \
|
|||||||
bmp180.c htu21d.c ds18b20.c rht03.c \
|
bmp180.c htu21d.c ds18b20.c rht03.c \
|
||||||
drcSerial.c drcNet.c \
|
drcSerial.c drcNet.c \
|
||||||
pseudoPins.c \
|
pseudoPins.c \
|
||||||
wpiExtensions.c
|
wpiExtensions.c \
|
||||||
|
wiringPiLegacy.c
|
||||||
|
|
||||||
HEADERS = $(shell ls *.h)
|
HEADERS = $(shell ls *.h)
|
||||||
|
|
||||||
|
|||||||
@@ -70,12 +70,14 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <asm/ioctl.h>
|
#include <asm/ioctl.h>
|
||||||
|
#include <byteswap.h>
|
||||||
|
|
||||||
#include "softPwm.h"
|
#include "softPwm.h"
|
||||||
#include "softTone.h"
|
#include "softTone.h"
|
||||||
|
|
||||||
#include "wiringPi.h"
|
#include "wiringPi.h"
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
|
#include "wiringPiLegacy.h"
|
||||||
|
|
||||||
// Environment Variables
|
// Environment Variables
|
||||||
|
|
||||||
@@ -874,7 +876,7 @@ static void usingGpioMemCheck (const char *what)
|
|||||||
*********************************************************************************
|
*********************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void piGpioLayoutOops (const char *why)
|
void piGpioLayoutOops (const char *why)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Oops: Unable to determine board revision from /proc/cpuinfo\n") ;
|
fprintf (stderr, "Oops: Unable to determine board revision from /proc/cpuinfo\n") ;
|
||||||
fprintf (stderr, " -> %s\n", why) ;
|
fprintf (stderr, " -> %s\n", why) ;
|
||||||
@@ -1006,7 +1008,7 @@ int piGpioLayout (void)
|
|||||||
gpioLayout = 2 ; // Covers everything else from the B revision 2 to the B+, the Pi v2, v3, zero and CM's.
|
gpioLayout = 2 ; // Covers everything else from the B revision 2 to the B+, the Pi v2, v3, zero and CM's.
|
||||||
|
|
||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf ("piGpioLayoutOops: Returning revision: %d\n", gpioLayout) ;
|
printf ("piGpioLayout: Returning revision: %d\n", gpioLayout) ;
|
||||||
|
|
||||||
return gpioLayout ;
|
return gpioLayout ;
|
||||||
}
|
}
|
||||||
@@ -1023,6 +1025,36 @@ int piBoardRev (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* revfile = "/proc/device-tree/system/linux,revision";
|
||||||
|
|
||||||
|
|
||||||
|
const char* GetPiRevision(char* line, int linelength, unsigned int* revision) {
|
||||||
|
|
||||||
|
const char* c = NULL;
|
||||||
|
uint32_t Revision = 0;
|
||||||
|
_Static_assert(sizeof(Revision)==4, "should be unsigend integer with 4 byte size");
|
||||||
|
|
||||||
|
FILE* fp = fopen(revfile,"rb");
|
||||||
|
if (!fp) {
|
||||||
|
if (wiringPiDebug)
|
||||||
|
perror(revfile);
|
||||||
|
return NULL; // revision file not found or no access
|
||||||
|
}
|
||||||
|
int result = fread(&Revision, sizeof(Revision), 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
if (result<1) {
|
||||||
|
if (wiringPiDebug)
|
||||||
|
perror(revfile);
|
||||||
|
return NULL; // read error
|
||||||
|
}
|
||||||
|
Revision = bswap_32(Revision);
|
||||||
|
snprintf(line, linelength, "Revision\t: %x", Revision);
|
||||||
|
c = &line[11];
|
||||||
|
*revision = Revision;
|
||||||
|
if (wiringPiDebug)
|
||||||
|
printf("GetPiRevision: Revision string: \"%s\" (%s) - 0x%x\n", line, c, *revision);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* piBoardId:
|
* piBoardId:
|
||||||
@@ -1093,10 +1125,10 @@ 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 ;
|
const int maxlength = 120;
|
||||||
char line [120] ;
|
char line [maxlength+1] ;
|
||||||
char *c ;
|
const char *c ;
|
||||||
unsigned int revision ;
|
unsigned int revision = 0x00 ;
|
||||||
int bRev, bType, bProc, bMfg, bMem, bWarranty ;
|
int bRev, bType, bProc, bMfg, bMem, bWarranty ;
|
||||||
|
|
||||||
// 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...
|
||||||
@@ -1104,47 +1136,13 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
|
|||||||
|
|
||||||
(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)
|
c = GetPiRevision(line, maxlength, &revision); // device tree
|
||||||
piGpioLayoutOops ("Unable to open /proc/cpuinfo") ;
|
if (NULL==c) {
|
||||||
|
c = GetPiRevisionLegacy(line, maxlength, &revision); // proc/cpuinfo
|
||||||
while (fgets (line, 120, cpuFd) != NULL)
|
}
|
||||||
if (strncmp (line, "Revision", 8) == 0)
|
if (NULL==c) {
|
||||||
break ;
|
piGpioLayoutOops ("GetPiRevision failed!") ;
|
||||||
|
}
|
||||||
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)") ;
|
|
||||||
|
|
||||||
revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x
|
|
||||||
|
|
||||||
// Check for new way:
|
// Check for new way:
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ extern "C" {
|
|||||||
// Data
|
// Data
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
|
extern void piGpioLayoutOops (const char *why);
|
||||||
extern int wiringPiFailure (int fatal, const char *message, ...) ;
|
extern int wiringPiFailure (int fatal, const char *message, ...) ;
|
||||||
|
|
||||||
// Core wiringPi functions
|
// Core wiringPi functions
|
||||||
|
|||||||
57
wiringPi/wiringPiLegacy.c
Normal file
57
wiringPi/wiringPiLegacy.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
#include <wiringPi.h>
|
||||||
|
#include "wiringPiLegacy.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
extern int wiringPiDebug ;
|
||||||
|
|
||||||
|
const char* GetPiRevisionLegacy(char* line, int linelength, unsigned int* revision) {
|
||||||
|
FILE *cpuFd ;
|
||||||
|
char *c = NULL;
|
||||||
|
|
||||||
|
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
|
||||||
|
piGpioLayoutOops ("Unable to open /proc/cpuinfo") ;
|
||||||
|
|
||||||
|
while (fgets (line, linelength, 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 ("GetPiRevisionLegacy: 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)") ;
|
||||||
|
|
||||||
|
*revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x
|
||||||
|
return c;
|
||||||
|
}
|
||||||
2
wiringPi/wiringPiLegacy.h
Normal file
2
wiringPi/wiringPiLegacy.h
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
const char* GetPiRevisionLegacy(char* line, int linelength, unsigned int* revision);
|
||||||
Reference in New Issue
Block a user