From cdbd46762b944ccc310315e11d865c2ea7cac922 Mon Sep 17 00:00:00 2001 From: "Michael J. Chudobiak" Date: Fri, 2 Nov 2012 09:09:29 -0400 Subject: Add a flag to signal completion of startup. To be expanded. --- bus.c | 4 +--- error_utils.c | 5 +++++ globals.h | 2 ++ instr-daemon.c | 58 +++++++++++++++++++++++++++++++++------------------------- parser.c | 4 ++++ 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/bus.c b/bus.c index c539d16..3f0dbc6 100644 --- a/bus.c +++ b/bus.c @@ -369,9 +369,7 @@ void bus_init() if (!globals.HWDetect.beaglebone) { printf("This doesn't seem to be a beaglebone.. bus stuff disabled!\n"); - } - - if (globals.HWDetect.beaglebone) { + } else { gpmc_setup(); extbus = (uint8_t*) util_mapmemoryblock(0x01000000, 0x100); diff --git a/error_utils.c b/error_utils.c index bb2cd32..d1f8283 100644 --- a/error_utils.c +++ b/error_utils.c @@ -60,6 +60,7 @@ void set_gpib_error_flags (int error_num) case Soft_Limit_Exceeded: case SelfCalError: case NetworkNotFound: + case Startup_Not_Finished: GPIB_Set_Device_Dependent_Error(); break; default: @@ -519,6 +520,10 @@ void get_error_text(gchar **response, int error_num) format_error_text(response,-200,"Invalid execution path. Programming error."); break; + case Startup_Not_Finished: + format_error_text(response,-300,"Not ready for commands yet. Still booting up."); + break; + default: format_error_text(response,-200,"Specific problem unknown."); } diff --git a/globals.h b/globals.h index d7529f0..2fe6de7 100644 --- a/globals.h +++ b/globals.h @@ -87,6 +87,7 @@ #define SelfCalError 73 #define NetworkNotFound 74 #define ThisShouldntHappen 75 +#define Startup_Not_Finished 76 #define YES 1 #define NO 0 @@ -748,6 +749,7 @@ typedef struct { int force_output_fully_off; int shutdown_started; int flash_write_in_progress; + int startup_complete; } FlagStruct; diff --git a/instr-daemon.c b/instr-daemon.c index d79916d..24bfe45 100644 --- a/instr-daemon.c +++ b/instr-daemon.c @@ -238,12 +238,13 @@ int main(int argc, char **argv) LCD_write(3,0,"Warming up, please wait... "); globals.Timers.startup_timer_value = sec_timer (); - long timer_count; - long on_delay = (long)globals.Flash.turn_on_dly; + + Main_Rst(); #define MIN_STARTUP_DELAY 2 #define MAX_STARTUP_DELAY 120 + long on_delay = (long)globals.Flash.turn_on_dly; if (on_delay < MIN_STARTUP_DELAY) { on_delay = MIN_STARTUP_DELAY; } @@ -251,6 +252,7 @@ int main(int argc, char **argv) on_delay = MAX_STARTUP_DELAY; } + long timer_count; while ((timer_count=sec_timer()-globals.Timers.startup_timer_value) < on_delay) { message = g_strdup_printf ("%ld ", on_delay - timer_count); LCD_write(3,27,message); @@ -260,9 +262,10 @@ int main(int argc, char **argv) I2C_Setup_Monitor(); - Main_Rst(); Show_Main_Menu(); + globals.Flags.startup_complete = 1; + // FIXME - self-cal here - or in thread beside user sessions? //register stdin channel @@ -319,7 +322,7 @@ int main(int argc, char **argv) static gboolean periodic_poll (void) { - if (bus_getpin (POWER_FAIL)) { + if (globals.HWDetect.beaglebone && bus_getpin (POWER_FAIL)) { globals.Flags.shutdown_started = TRUE; @@ -350,36 +353,41 @@ static gboolean periodic_poll (void) exit(0); } - int i, output_on_time_so_far; - for (i=0; i<(globals.Flash.ChanKey_output_state?globals.Flash.channels:1); ++i) { - output_on_time_so_far = (int) (sec_timer()-globals.Timers.last_activity_at[i]); - if ((globals.Flash.output_timer[i]>0) && (globals.Timers.last_activity_at[i]>0) && (output_on_time_so_far > globals.Flash.output_timer[i])) { - Set_Output_State(i,output_off); - Show_Main_Menu(); + if (globals.Flags.startup_complete) { + int i, output_on_time_so_far; + + for (i=0; i<(globals.Flash.ChanKey_output_state?globals.Flash.channels:1); ++i) { + output_on_time_so_far = (int) (sec_timer()-globals.Timers.last_activity_at[i]); + if ( (globals.Flash.output_timer[i]>0) && + (globals.Timers.last_activity_at[i]>0) && + (output_on_time_so_far > globals.Flash.output_timer[i])) { + Set_Output_State(i,output_off); + Show_Main_Menu(); + } } - } - Update_Main_Menu_If_Visible(); + Update_Main_Menu_If_Visible(); - Menu_Check_Buttons (); + Menu_Check_Buttons (); - for (i=0; i