diff --git a/parts/Board.cpp b/parts/Board.cpp index 362d8350..1498dbed 100644 --- a/parts/Board.cpp +++ b/parts/Board.cpp @@ -57,6 +57,7 @@ namespace Boards { RegisterActionAndMenu("Pause","Pauses the simulated AVR execution.", ScriptAction::Pause); RegisterActionAndMenu("Resume","Resumes simulated AVR execution.", ScriptAction::Unpause); RegisterAction("WaitMs","Waits the specified number of milliseconds (in AVR-clock time)", ScriptAction::Wait,{ArgType::Int}); + RegisterAction("WaitForReset","Waits for the board to reset", ScriptAction::WaitReset); RegisterKeyHandler('r', "Resets the AVR/board"); RegisterKeyHandler('z', "Pauses/resumes AVR execution"); @@ -411,6 +412,16 @@ namespace Boards { case Unpause: m_bPaused.store(false); return LineStatus::Finished; + case WaitReset: + if (m_stResetWaitFlag == StateReset::IDLE) { + m_stResetWaitFlag = StateReset::WAITING; + } + if (m_stResetWaitFlag == StateReset::FINISHED) { + m_stResetWaitFlag = StateReset::IDLE; + return LineStatus::Finished; + } else { + return LineStatus::Waiting; + } } return LineStatus::Unhandled; } @@ -520,6 +531,9 @@ namespace Boards { if (uiMCUSR) // only run on change and not changed to 0 { OnAVRReset(); + if (m_stResetWaitFlag == StateReset::WAITING) { + m_stResetWaitFlag = StateReset::FINISHED; + } } } OnAVRCycle(); diff --git a/parts/Board.h b/parts/Board.h index 8947fb13..02b0dac7 100644 --- a/parts/Board.h +++ b/parts/Board.h @@ -171,6 +171,14 @@ namespace Boards bool m_bLostTimeLogged = false; + enum class StateReset { + IDLE, + WAITING, + FINISHED + } ; + + StateReset m_stResetWaitFlag = StateReset::IDLE; + pthread_t m_thread = 0; const Wirings::Wiring &m_wiring; std::string m_strBoard = ""; @@ -191,7 +199,8 @@ namespace Boards Reset, Wait, Pause, - Unpause + Unpause, + WaitReset }; EEPROM m_EEPROM; diff --git a/scripts/tests/test_script_WFR.c b/scripts/tests/test_script_WFR.c new file mode 100644 index 00000000..172b7583 --- /dev/null +++ b/scripts/tests/test_script_WFR.c @@ -0,0 +1,56 @@ +/* + atmega88_uart_echo.c + + This test case enables uart RX interupts, does a "printf" and then receive characters + via the interupt handler until it reaches a \r. + + This tests the uart reception fifo system. It relies on the uart "irq" input and output + to be wired together (see simavr.c) + */ + +#include +#include +#include +#include +#include +#include + +/* + * This demonstrate how to use the avr_mcu_section.h file + * The macro adds a section to the ELF file with useful + * information for the simulator + */ +#include "avr_mcu_section.h" +AVR_MCU(16000000, "atmega2560"); + +#define PIN(x,y) PORT##x>>y & 1U + +volatile uint8_t done = 0; + +static int uart_putchar(char c, FILE *stream) +{ + loop_until_bit_is_set(UCSR0A, UDRE0); + UDR0 = c; + return 0; +} +static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, + _FDEV_SETUP_WRITE); +int main() +{ + stdout = &mystdout; + sei(); + + printf("READY\n"); + + + while(1){}; + + cli(); + + + printf("FINISHED\n"); + + // this quits the simulator, since interupts are off + // this is a "feature" that allows running tests cases and exit + sleep_cpu(); +} diff --git a/scripts/tests/test_script_WFR.txt b/scripts/tests/test_script_WFR.txt new file mode 100644 index 00000000..1f611bf8 --- /dev/null +++ b/scripts/tests/test_script_WFR.txt @@ -0,0 +1,8 @@ +# This script is a component test script for use with the test firmware and printer. +ScriptHost::SetTimeoutMs(2000) +ScriptHost::SetQuitOnTimeout(1) +Serial0::NextLineMustBe(READY) +Board::Reset() +Board::WaitForReset() +Serial0::NextLineMustBe(READY) +Board::Quit()