allows programs like the simduino example to modify the init/deinit function
to fix a crash
Signed-off-by: Christian Balles <code@ballessay.de>
2 files changed:
// 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;
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;
}
// 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);