diff --git a/simavr/sim/avr/avr_mcu_section.h b/simavr/sim/avr/avr_mcu_section.h index ebeceb0a3..bdf141d85 100644 --- a/simavr/sim/avr/avr_mcu_section.h +++ b/simavr/sim/avr/avr_mcu_section.h @@ -70,6 +70,8 @@ enum { SIMAVR_CMD_VCD_START_TRACE, SIMAVR_CMD_VCD_STOP_TRACE, SIMAVR_CMD_UART_LOOPBACK, + SIMAVR_CMD_EXIT_CODE_0, + SIMAVR_CMD_EXIT_CODE_1, }; #if __AVR__ diff --git a/simavr/sim/sim_cmds.c b/simavr/sim/sim_cmds.c index 587f259e1..b35984f85 100644 --- a/simavr/sim/sim_cmds.c +++ b/simavr/sim/sim_cmds.c @@ -180,6 +180,26 @@ _simavr_cmd_uart_loopback( return 0; } +static int +_simavr_cmd_exit_code_0( + avr_t * avr, + uint8_t v, + void * param) +{ + exit(0); + return 0; //we never execute this, but it prevents a compiler warning +} + +static int +_simavr_cmd_exit_code_1( + avr_t * avr, + uint8_t v, + void * param) +{ + exit(1); + return 0; //we never execute this, but it prevents a compiler warning +} + void avr_cmd_init( avr_t * avr) @@ -190,4 +210,6 @@ avr_cmd_init( avr_cmd_register(avr, SIMAVR_CMD_VCD_START_TRACE, &_simavr_cmd_vcd_start_trace, NULL); avr_cmd_register(avr, SIMAVR_CMD_VCD_STOP_TRACE, &_simavr_cmd_vcd_stop_trace, NULL); avr_cmd_register(avr, SIMAVR_CMD_UART_LOOPBACK, &_simavr_cmd_uart_loopback, NULL); + avr_cmd_register(avr, SIMAVR_CMD_EXIT_CODE_0, &_simavr_cmd_exit_code_0, NULL); + avr_cmd_register(avr, SIMAVR_CMD_EXIT_CODE_1, &_simavr_cmd_exit_code_1, NULL); } diff --git a/tests/atmega88_uart_echo.c b/tests/atmega88_uart_echo.c index 31f0ab48a..0740a5503 100644 --- a/tests/atmega88_uart_echo.c +++ b/tests/atmega88_uart_echo.c @@ -19,6 +19,7 @@ * The macro adds a section to the ELF file with useful * information for the simulator */ +#define F_CPU 8000000L #include "avr_mcu_section.h" AVR_MCU(F_CPU, "atmega88"); // tell simavr to listen to commands written in this (unused) register @@ -95,7 +96,7 @@ int main() cli(); printf("Received: %s", buffer); - // this quits the simulator, since interupts are off - // this is a "feature" that allows running tests cases and exit - sleep_cpu(); + + // this tells simavr to quit with error code 1 + GPIOR0 = SIMAVR_CMD_EXIT_CODE_1; }