Make the non-working skeleton work

This commit is contained in:
Thammi 2013-08-26 02:30:05 +02:00
parent 0002eb48e7
commit 33f4345e46
3 changed files with 19 additions and 16 deletions

View File

@ -5,13 +5,17 @@
#include <stdint.h> #include <stdint.h>
extern jmp_buf app_jmp_buf; 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 // initialize lifecycle, stopped if return != 0
inline static int enter_app(void) { static int enter_app(void) {
should_stop = 0; should_stop = 0;
return setjmp(app_jmp_buf); return setjmp(app_jmp_buf);
} }
*/
// stop the running app // stop the running app
inline static void stop_app(void) { inline static void stop_app(void) {

View File

@ -1,4 +1,4 @@
#include <pentabug/lifecycle.h> #include <pentabug/lifecycle.h>
jmp_buf app_jmp_buf; jmp_buf app_jmp_buf;
uint8_t should_stop; volatile uint8_t should_stop;

View File

@ -22,15 +22,8 @@ static inline void reset_hw(void) {
} }
static inline void run_app(struct app_t* app) { static inline void run_app(struct app_t* app) {
if(enter_app()) { should_stop = 0;
// this is the exit if(setjmp(app_jmp_buf) == 0) {
if(app->cleanup) {
app->cleanup();
}
return;
}
if(app->init) { if(app->init) {
app->init(); app->init();
} }
@ -39,6 +32,14 @@ static inline void run_app(struct app_t* app) {
app->run(); app->run();
test_stop_app(); test_stop_app();
} }
}
// this is the exit
if(app->cleanup) {
app->cleanup();
}
return;
} }
int main(void) { int main(void) {
@ -57,8 +58,6 @@ int main(void) {
run_app(&apps[app_index]); run_app(&apps[app_index]);
for(;;);
if(direction > 0) { if(direction > 0) {
app_index++; app_index++;