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

Preserve ticks for displays across VMs #6321

Merged
merged 1 commit into from
Apr 28, 2022
Merged
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
21 changes: 16 additions & 5 deletions ports/atmel-samd/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@
static volatile bool sleep_ok = true;

#ifdef SAMD21
uint8_t _tick_event_channel;
static uint8_t _tick_event_channel = EVSYS_SYNCH_NUM;

static bool tick_enabled(void) {
return _tick_event_channel != EVSYS_SYNCH_NUM;
}

// Sleeping requires a register write that can stall interrupt handling. Turning
// off sleeps allows for more accurate interrupt timing. (Python still thinks
Expand Down Expand Up @@ -431,8 +435,15 @@ void reset_port(void) {
pew_reset();
#endif

reset_event_system();
reset_ticks();
#ifdef SAMD21
if (!tick_enabled())
// SAMD21 ticks depend on the event system, so don't disturb the event system if we need ticks,
// such as for a display that lives across VM instantiations.
#endif
{
reset_event_system();
reset_ticks();
}

reset_all_pins();

Expand Down Expand Up @@ -613,8 +624,8 @@ void port_enable_tick(void) {
RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_PER2;
#endif
#ifdef SAMD21
// SAMD21 ticks won't survive reset_port(). This *should* be ok since it'll
// be triggered by ticks and no Python will be running.
// reset_port() preserves the event system if ticks were still enabled after a VM finished,
// such as for an on-board display. Normally the event system would be reset between VM instantiations.
if (_tick_event_channel >= EVSYS_SYNCH_NUM) {
turn_on_event_system();
_tick_event_channel = find_sync_event_channel();
Expand Down