From 545645d2505ab5f98f4724550d3d183b643a99f9 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Wed, 14 Sep 2011 09:10:39 +0100 Subject: [PATCH] core: added new states States cpu_Done and cpu_Crashed allow graceful exit and cleanup of simavr applications. Signed-off-by: Markus Lampert Signed-off-by: Michel Pollet --- simavr/sim/run_avr.c | 7 +++++-- simavr/sim/sim_avr.c | 12 +++++++----- simavr/sim/sim_avr.h | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/simavr/sim/run_avr.c b/simavr/sim/run_avr.c index 9356c95..e43424f 100644 --- a/simavr/sim/run_avr.c +++ b/simavr/sim/run_avr.c @@ -166,8 +166,11 @@ int main(int argc, char *argv[]) signal(SIGINT, sig_int); signal(SIGTERM, sig_int); - for (;;) - avr_run(avr); + for (;;) { + int state = avr_run(avr); + if ( state == cpu_Done || state == cpu_Crashed) + break; + } avr_terminate(avr); } diff --git a/simavr/sim/sim_avr.c b/simavr/sim/sim_avr.c index 6d7f088..885bbdc 100644 --- a/simavr/sim/sim_avr.c +++ b/simavr/sim/sim_avr.c @@ -99,7 +99,7 @@ void avr_sadly_crashed(avr_t *avr, uint8_t signal) avr_gdb_init(avr); } if (!avr->gdb) - exit(1); // no gdb ? + avr->state = cpu_Crashed; } static void _avr_io_command_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, void * param) @@ -210,9 +210,10 @@ void avr_callback_run_gdb(avr_t * avr) if (avr->state == cpu_Sleeping) { if (!avr->sreg[S_I]) { - printf("simavr: sleeping with interrupts off, quitting gracefully\n"); + if ( avr->log_level) printf("simavr: sleeping with interrupts off, quitting gracefully\n"); avr_terminate(avr); - exit(0); + avr->state = cpu_Done; + return; } /* * try to sleep for as long as we can (?) @@ -262,9 +263,10 @@ void avr_callback_run_raw(avr_t * avr) if (avr->state == cpu_Sleeping) { if (!avr->sreg[S_I]) { - printf("simavr: sleeping with interrupts off, quitting gracefully\n"); + if ( avr->log_level) printf("simavr: sleeping with interrupts off, quitting gracefully\n"); avr_terminate(avr); - exit(0); + avr->state = cpu_Done; + return; } /* * try to sleep for as long as we can (?) diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index 4ab0a38..b8091b6 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -73,6 +73,8 @@ enum { cpu_Step, // run ONE instruction, then... cpu_StepDone, // tell gdb it's all OK, and give it registers + cpu_Done, // avr software stopped gracefully + cpu_Crashed, // avr software crashed (watchdog fired) }; // this is only ever used if CONFIG_SIMAVR_TRACE is defined -- 2.39.5