Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added commands to end the simulation with a zero or a non zero exit code #363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions simavr/sim/avr/avr_mcu_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
22 changes: 22 additions & 0 deletions simavr/sim/sim_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
7 changes: 4 additions & 3 deletions tests/atmega88_uart_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}