summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-11-02 10:34:09 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-11-02 10:34:09 -0400
commitfe3ab1a417a4dec82a62edce46595e779d9f3f8b (patch)
tree168bc10039e6de4a0d4f29b21525887695eb462b
parentcdbd46762b944ccc310315e11d865c2ea7cac922 (diff)
split boot-up code into timeouts to allow power-fail during boot
-rw-r--r--instr-daemon.c65
1 files changed, 38 insertions, 27 deletions
diff --git a/instr-daemon.c b/instr-daemon.c
index 24bfe45..c2992fc 100644
--- a/instr-daemon.c
+++ b/instr-daemon.c
@@ -20,6 +20,7 @@
static gboolean periodic_poll (void);
+static gboolean finish_boot (void);
int port=3333; //port to listen
@@ -187,6 +188,7 @@ handler (GThreadedSocketService *service,
return TRUE;
}
+
int main(int argc, char **argv)
{
GSocketService *service = NULL;
@@ -241,33 +243,6 @@ int main(int argc, char **argv)
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;
- }
- if (on_delay > MAX_STARTUP_DELAY) {
- 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);
- g_free (message);
- }
- LCD_write(3,27,"OK");
-
- I2C_Setup_Monitor();
-
- Show_Main_Menu();
-
- globals.Flags.startup_complete = 1;
-
- // FIXME - self-cal here - or in thread beside user sessions?
-
//register stdin channel
stdinChannel = g_io_channel_unix_new(0);
if(stdinChannel == NULL) {
@@ -308,6 +283,7 @@ int main(int argc, char **argv)
GMainLoop *loop = g_main_loop_new (NULL, FALSE);
g_timeout_add (20, (GSourceFunc) periodic_poll, NULL);
+ g_timeout_add (100, (GSourceFunc) finish_boot, NULL);
g_main_loop_run (loop);
@@ -320,6 +296,41 @@ int main(int argc, char **argv)
}
+static gboolean finish_boot (void) {
+
+#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;
+ }
+ if (on_delay > MAX_STARTUP_DELAY) {
+ on_delay = MAX_STARTUP_DELAY;
+ }
+
+ long timer_count;
+
+ if ((timer_count=sec_timer()-globals.Timers.startup_timer_value) < on_delay) {
+ gchar *message = g_strdup_printf ("%ld ", on_delay - timer_count);
+ LCD_write(3,27,message);
+ g_free (message);
+ return TRUE; // exit and call by timeout again
+ }
+
+ LCD_write(3,27,"OK");
+
+ I2C_Setup_Monitor();
+
+ Show_Main_Menu();
+
+ // FIXME - self-cal here - or in thread beside user sessions?
+
+ globals.Flags.startup_complete = 1;
+ return FALSE; // no more calls to this function are needed
+}
+
+
static gboolean periodic_poll (void)
{
if (globals.HWDetect.beaglebone && bus_getpin (POWER_FAIL)) {