diff options
-rw-r--r-- | bus.c | 42 | ||||
-rw-r--r-- | globals.h | 6 |
2 files changed, 39 insertions, 9 deletions
@@ -59,13 +59,38 @@ static int devmemfd = -1; -static bool util_isbeaglebone() + +static bool util_model_is (char *check_model) +{ + FILE *fp; + char content[100]; + + if ((fp=fopen("/sys/firmware/devicetree/base/model", "r"))==NULL) { + return FALSE; + } + + while(fgets(content, sizeof(content), fp)) { + if(strstr(content,check_model)) { + return TRUE; + } + } + + return FALSE; +} + + +static bool util_is_beaglebone() +{ + return util_model_is ("TI AM335x BeagleBone"); +} + + +static bool util_is_olimex() { - int fd = open("/sys/devices/avtech.9/modalias", O_RDONLY); - close(fd); - return fd > -1; + return util_model_is ("Olimex AM335x SOM"); } + static void* util_mapmemoryblock(off_t offset, size_t len) { devmemfd = open("/dev/mem", O_RDWR | O_SYNC); @@ -323,11 +348,14 @@ static volatile uint8_t* extbus; void bus_init() { + globals.HWDetect.beaglebone = util_is_beaglebone(); + globals.HWDetect.olimex = util_is_olimex(); - globals.HWDetect.beaglebone = util_isbeaglebone(); + printf("Beaglebone: %d. Olimex: %d.\n", + globals.HWDetect.beaglebone, globals.HWDetect.olimex); - if (!globals.HWDetect.beaglebone) { - printf("This doesn't seem to be a beaglebone.. bus stuff disabled!\n"); + if (!globals.HWDetect.beaglebone && !globals.HWDetect.olimex) { + printf("No recognized hardware. Bus stuff disabled!\n"); } else { gpmc_setup(); @@ -5,6 +5,7 @@ #include <string.h> #include <stdlib.h> #include <glib.h> +#include <stdbool.h> #define DEBUG_ON - uncomment this to have debug messages @@ -823,8 +824,9 @@ typedef struct { typedef struct { - int beaglebone; - int gpib; + bool beaglebone; + bool olimex; + bool gpib; } HWDetectStruct; |