Skip to content

Commit 816a26e

Browse files
authored
Merge pull request #6321 from dhalbert/samd21-ticks-for-display
Preserve ticks for displays across VMs
2 parents 02280b8 + b25d810 commit 816a26e

File tree

1 file changed

+16
-5
lines changed
  • ports/atmel-samd/supervisor

1 file changed

+16
-5
lines changed

ports/atmel-samd/supervisor/port.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@
131131
static volatile bool sleep_ok = true;
132132

133133
#ifdef SAMD21
134-
uint8_t _tick_event_channel;
134+
static uint8_t _tick_event_channel = EVSYS_SYNCH_NUM;
135+
136+
static bool tick_enabled(void) {
137+
return _tick_event_channel != EVSYS_SYNCH_NUM;
138+
}
135139

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

434-
reset_event_system();
435-
reset_ticks();
438+
#ifdef SAMD21
439+
if (!tick_enabled())
440+
// SAMD21 ticks depend on the event system, so don't disturb the event system if we need ticks,
441+
// such as for a display that lives across VM instantiations.
442+
#endif
443+
{
444+
reset_event_system();
445+
reset_ticks();
446+
}
436447

437448
reset_all_pins();
438449

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

0 commit comments

Comments
 (0)