Skip to content

Commit

Permalink
#315 - WaitForReset() (#316)
Browse files Browse the repository at this point in the history
* Implement #315
  • Loading branch information
vintagepc authored Jun 27, 2021
1 parent bb0a4e2 commit 86699d2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
14 changes: 14 additions & 0 deletions parts/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion parts/Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -191,7 +199,8 @@ namespace Boards
Reset,
Wait,
Pause,
Unpause
Unpause,
WaitReset
};

EEPROM m_EEPROM;
Expand Down
56 changes: 56 additions & 0 deletions scripts/tests/test_script_WFR.c
Original file line number Diff line number Diff line change
@@ -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 <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <avr/sleep.h>
#include <util/delay.h>

/*
* 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();
}
8 changes: 8 additions & 0 deletions scripts/tests/test_script_WFR.txt
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 86699d2

Please sign in to comment.