From: Peter Michael Green Date: Sat, 8 Dec 2018 12:18:12 +0000 (+0000) Subject: Add code to detect if the system is in fact a raspberry pi. X-Git-Tag: archive/raspbian/1.68-2+rpi1~29 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a0c405ca6f3f8a430a56cd527bd937abaefd08af;p=pigpio.git Add code to detect if the system is in fact a raspberry pi. --- diff --git a/pigpio.c b/pigpio.c index b63b4a8..ff0af86 100644 --- a/pigpio.c +++ b/pigpio.c @@ -1198,6 +1198,7 @@ typedef struct /* initialise once then preserve */ static volatile uint32_t piCores = 0; +static volatile uint32_t pi_ispi = 0; static volatile uint32_t pi_peri_phys = 0x20000000; static volatile uint32_t pi_dram_bus = 0x40000000; static volatile uint32_t pi_mem_flag = 0x0C; @@ -7198,6 +7199,17 @@ static int initCheckPermitted(void) { DBG(DBG_STARTUP, ""); + if (!pi_ispi) + { + DBG(DBG_ALWAYS, + "\n" \ + "+---------------------------------------------------------+\n" \ + "|Sorry, this system does not appear to be a raspberry pi. |\n" \ + "|aborting. |\n" \ + "+---------------------------------------------------------+\n\n"); + return -1; + } + if ((fdMem = open("/dev/mem", O_RDWR | O_SYNC) ) < 0) { DBG(DBG_ALWAYS, @@ -13327,6 +13339,13 @@ unsigned gpioHardwareRevision(void) } } + if (!strncasecmp("hardware\t: BCM", buf, 14)) { + int bcmno = atoi(buf+14); + if ((bcmno == 2708) || (bcmno == 2709) || (bcmno == 2710) || (bcmno == 2835) || (bcmno == 2836) || (bcmno == 2837)) { + pi_ispi = 1; + } + } + if (!strncasecmp("revision\t:", buf, 10)) { if (sscanf(buf+10, "%x%c", &rev, &term) == 2)