From 33f4345e466eeba688c2c916bc9d6ababe471af0 Mon Sep 17 00:00:00 2001 From: Thammi Date: Mon, 26 Aug 2013 02:30:05 +0200 Subject: [PATCH] Make the non-working skeleton work --- firmware/include/pentabug/lifecycle.h | 8 ++++++-- firmware/lib/lifecycle.c | 2 +- firmware/main.c | 25 ++++++++++++------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/firmware/include/pentabug/lifecycle.h b/firmware/include/pentabug/lifecycle.h index 597c13f..706a751 100644 --- a/firmware/include/pentabug/lifecycle.h +++ b/firmware/include/pentabug/lifecycle.h @@ -5,13 +5,17 @@ #include extern jmp_buf app_jmp_buf; -extern uint8_t should_stop; +extern volatile uint8_t should_stop; +// this code does not work ... i have no idea why +// putting the exact same statements at the calling line works ... +/* // initialize lifecycle, stopped if return != 0 -inline static int enter_app(void) { +static int enter_app(void) { should_stop = 0; return setjmp(app_jmp_buf); } +*/ // stop the running app inline static void stop_app(void) { diff --git a/firmware/lib/lifecycle.c b/firmware/lib/lifecycle.c index 3f5491d..57531db 100644 --- a/firmware/lib/lifecycle.c +++ b/firmware/lib/lifecycle.c @@ -1,4 +1,4 @@ #include jmp_buf app_jmp_buf; -uint8_t should_stop; +volatile uint8_t should_stop; diff --git a/firmware/main.c b/firmware/main.c index ac62e32..73a0977 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -22,23 +22,24 @@ static inline void reset_hw(void) { } static inline void run_app(struct app_t* app) { - if(enter_app()) { - // this is the exit - if(app->cleanup) { - app->cleanup(); + should_stop = 0; + if(setjmp(app_jmp_buf) == 0) { + if(app->init) { + app->init(); } - return; + for(;;) { + app->run(); + test_stop_app(); + } } - if(app->init) { - app->init(); + // this is the exit + if(app->cleanup) { + app->cleanup(); } - for(;;) { - app->run(); - test_stop_app(); - } + return; } int main(void) { @@ -57,8 +58,6 @@ int main(void) { run_app(&apps[app_index]); - for(;;); - if(direction > 0) { app_index++;