Add code to detect if the system is in fact a raspberry pi.
authorPeter Michael Green <plugwash@debian.org>
Sat, 8 Dec 2018 12:18:12 +0000 (12:18 +0000)
committerPeter Michael Green <plugwash@debian.org>
Sat, 8 Dec 2018 12:18:12 +0000 (12:18 +0000)
pigpio.c

index b63b4a895452b62a9f7372fdff638f366eccb5fc..ff0af86cd86ecba84fb0a1510a3744ca9e4b7287 100644 (file)
--- 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)