From 3636beafd37af537f864fb898b7375626236d0a4 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 1 Jan 2000 00:30:55 +0900 Subject: abstract the hardware identification checks --- bus.c | 33 +++++++++++++++++++++------------ globals.h | 5 ++++- gpib.c | 20 ++++++++++---------- instr-daemon.c | 6 +++--- menus.c | 2 +- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/bus.c b/bus.c index 0c13161..9d15537 100644 --- a/bus.c +++ b/bus.c @@ -356,18 +356,23 @@ void bus_init() globals.HWDetect.beaglebone = util_is_beaglebone(); globals.HWDetect.olimex = util_is_olimex(); + // TODO update once Olimex carrier board is ready + globals.HWDetect.has_i2c = globals.HWDetect.beaglebone || globals.HWDetect.olimex; + globals.HWDetect.has_gpmc = globals.HWDetect.beaglebone; + globals.HWDetect.has_gpio = globals.HWDetect.beaglebone; + printf("Beaglebone: %d. Olimex: %d.\n", globals.HWDetect.beaglebone, globals.HWDetect.olimex); - if (!globals.HWDetect.beaglebone && !globals.HWDetect.olimex) { - printf("No recognized hardware. Bus stuff disabled!\n"); - } else { + if (globals.HWDetect.has_gpmc) { gpmc_setup(); - extbus = (uint8_t*) util_mapmemoryblock(0x01000000, 0x100); + gpmc_printinfo(); + } else { + printf("No recognized hardware. gpmc bus stuff disabled!\n"); + } - //gpmc_printinfo(); - + if (globals.HWDetect.has_gpio) { int i; for (i = 0; i < SIZEOFARRAY(gpio_pins); i++) { // these pins all happen to default to the correct mode (7) @@ -386,13 +391,15 @@ void bus_init() g_usleep(10); bus_setpin(RST_GPIB, 1); g_usleep(10); + } else { + printf("No recognized hardware. gpio stuff disabled!\n"); } } int bus_getpin(int pin) { - if (globals.HWDetect.beaglebone) { + if (globals.HWDetect.has_gpio) { return gpio_readvalue(gpio_pins[pin]); } else { return 0; @@ -401,21 +408,21 @@ int bus_getpin(int pin) void bus_setpin(int pin, int value) { - if (globals.HWDetect.beaglebone) { + if (globals.HWDetect.has_gpio) { gpio_writevalue(gpio_pins[pin], value & 0x1); } } void bus_writebyte(uint8_t address, uint8_t data) { - if (globals.HWDetect.beaglebone) { + if (globals.HWDetect.has_gpmc) { *(extbus + address) = data; } } uint8_t bus_readbyte(uint8_t address) { - if (globals.HWDetect.beaglebone) { + if (globals.HWDetect.has_gpmc) { return *(extbus + address); } else { return 0; @@ -424,12 +431,14 @@ uint8_t bus_readbyte(uint8_t address) void bus_shutdown() { - if (globals.HWDetect.beaglebone) { + if (globals.HWDetect.has_gpmc) { util_unmapmemoryblock((void*) extbus, 0x100); + } + + if (globals.HWDetect.has_gpio) { int i; for (i = 0; i < SIZEOFARRAY(gpio_pins); i++) { gpio_unexport(gpio_pins[i]); - } } } diff --git a/globals.h b/globals.h index 83c01a0..90e4173 100644 --- a/globals.h +++ b/globals.h @@ -826,7 +826,10 @@ typedef struct { typedef struct { bool beaglebone; bool olimex; - bool gpib; + bool has_gpib; + bool has_i2c; + bool has_gpmc; + bool has_gpio; char remount_point[128]; } HWDetectStruct; diff --git a/gpib.c b/gpib.c index 4eeaa9b..53c6706 100644 --- a/gpib.c +++ b/gpib.c @@ -261,7 +261,7 @@ void TNT_4882_Status(int status_register,unsigned int byte,int operation) { int set_srq; - if (globals.HWDetect.gpib) { + if (globals.HWDetect.has_gpib) { MR_4882_status[STB] = TNT_In(R_spsr); // Get STB } @@ -419,9 +419,9 @@ void GPIB_initialize(void) Requested_Count=0; // test to detect TNT chip - globals.HWDetect.gpib = 1; + globals.HWDetect.has_gpib = 1; if ((TNT_In(R_sts2) & 0xB0) != 0x90) { - globals.HWDetect.gpib = 0; + globals.HWDetect.has_gpib = 0; printf ("Error: TNT4882 chip not found\n"); return; } @@ -472,7 +472,7 @@ static void TNT_Adr_Mode() void GPIB_change_address(int new_address) { - if (!globals.HWDetect.gpib) { + if (!globals.HWDetect.has_gpib) { return; } @@ -589,7 +589,7 @@ static unsigned long int TNT_DATA_COUNT() static void TNT_Out(int reg, unsigned int byte) { - if (!globals.HWDetect.gpib) { + if (!globals.HWDetect.has_gpib) { return; } @@ -599,7 +599,7 @@ static void TNT_Out(int reg, unsigned int byte) static unsigned char TNT_In(int reg) { - if (!globals.HWDetect.gpib) { + if (!globals.HWDetect.has_gpib) { return (unsigned char) 0; } @@ -641,7 +641,7 @@ int GPIB_check_for_device_clear_signal(void) { /* reset interface if a device clear is received */ - if (!globals.HWDetect.gpib) { + if (!globals.HWDetect.has_gpib) { return FALSE; } @@ -671,7 +671,7 @@ int GPIB_check_for_messages(char *gpib_buf) { #define ib_empty (!(strlen(gpib_buf))) - if (!globals.HWDetect.gpib) { + if (!globals.HWDetect.has_gpib) { return FALSE; } @@ -709,7 +709,7 @@ int GPIB_check_for_messages(char *gpib_buf) int GPIB_handle_new_input(char *gpib_buf) { - if (!globals.HWDetect.gpib) { + if (!globals.HWDetect.has_gpib) { return FALSE; } @@ -932,7 +932,7 @@ void GPIB_finish_query_response() void GPIB_check_remote_status (int *is_remote, int *is_lockout) { *is_remote = *is_lockout = 0; - if (!globals.HWDetect.gpib) { + if (!globals.HWDetect.has_gpib) { return; } diff --git a/instr-daemon.c b/instr-daemon.c index 4c72997..8b2d0e6 100644 --- a/instr-daemon.c +++ b/instr-daemon.c @@ -369,7 +369,7 @@ static gboolean finish_boot (void) Show_Main_Menu(); // report error if GPIB chip not found - if (!globals.HWDetect.gpib) { + if (!globals.HWDetect.has_gpib) { queue_error_and_display_on_LCD(GPIB_missing); } @@ -380,12 +380,12 @@ static gboolean periodic_poll (void) { gboolean power_fail; - power_fail = (globals.HWDetect.beaglebone && bus_getpin (POWER_FAIL)); + power_fail = (globals.HWDetect.has_gpio && bus_getpin (POWER_FAIL)); if (power_fail) { // verify after a short delay (25 ms), to ignore short power glitches g_usleep (25e3); - power_fail = (globals.HWDetect.beaglebone && bus_getpin (POWER_FAIL)); + power_fail = (globals.HWDetect.has_gpio && bus_getpin (POWER_FAIL)); } if (power_fail) { diff --git a/menus.c b/menus.c index 0cc5891..a17869c 100644 --- a/menus.c +++ b/menus.c @@ -2922,7 +2922,7 @@ void Menu_Check_Buttons(void) int encoder_change; // abort if not running on the target board with the I2C bus - if (!globals.HWDetect.beaglebone) { + if (!globals.HWDetect.has_i2c) { return; } -- cgit