From f1ce544edfec2a00d171ccac805c3336b50e704a Mon Sep 17 00:00:00 2001 From: Christian Balles Date: Tue, 19 Oct 2010 23:45:58 +0200 Subject: [PATCH] core: added extra init/deinit functions to avr_t allows programs like the simduino example to modify the init/deinit function to fix a crash Signed-off-by: Christian Balles --- simavr/sim/sim_avr.c | 13 +++++++++---- simavr/sim/sim_avr.h | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/simavr/sim/sim_avr.c b/simavr/sim/sim_avr.c index 7add414..d21f109 100644 --- a/simavr/sim/sim_avr.c +++ b/simavr/sim/sim_avr.c @@ -41,6 +41,8 @@ int avr_init(avr_t * avr) // cpu is in limbo before init is finished. avr->state = cpu_Limbo; avr->frequency = 1000000; // can be overriden via avr_mcu_section + if (avr->special_init) + avr->special_init(avr); if (avr->init) avr->init(avr); avr->state = cpu_Running; @@ -50,13 +52,16 @@ int avr_init(avr_t * avr) void avr_terminate(avr_t * avr) { - if (avr->vcd) + if (avr->special_deinit) + avr->special_deinit(avr); + if (avr->vcd) { avr_vcd_close(avr->vcd); - avr->vcd = NULL; + avr->vcd = NULL; + } avr_deallocate_ios(avr); - free(avr->flash); - free(avr->data); + if (avr->flash) free(avr->flash); + if (avr->data) free(avr->data); avr->flash = avr->data = NULL; } diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index 9695c05..6d205d4 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -100,6 +100,10 @@ typedef struct avr_t { // called at init time void (*init)(struct avr_t * avr); + // called at init time (for special purposes like using a memory mapped file as flash see: simduino) + void (*special_init)(struct avr_t * avr); + // called at termination time ( to clean special initalizations) + void (*special_deinit)(struct avr_t * avr); // called at reset time void (*reset)(struct avr_t * avr); -- 2.39.5