Preserve ticks for displays across VMs

This commit is contained in:
Dan Halbert 2022-04-27 20:03:28 -04:00
parent 862188d2ee
commit b25d810af9

View File

@ -131,7 +131,11 @@
static volatile bool sleep_ok = true; static volatile bool sleep_ok = true;
#ifdef SAMD21 #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 // Sleeping requires a register write that can stall interrupt handling. Turning
// off sleeps allows for more accurate interrupt timing. (Python still thinks // off sleeps allows for more accurate interrupt timing. (Python still thinks
@ -431,8 +435,15 @@ void reset_port(void) {
pew_reset(); pew_reset();
#endif #endif
#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_event_system();
reset_ticks(); reset_ticks();
}
reset_all_pins(); reset_all_pins();
@ -613,8 +624,8 @@ void port_enable_tick(void) {
RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_PER2; RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_PER2;
#endif #endif
#ifdef SAMD21 #ifdef SAMD21
// SAMD21 ticks won't survive reset_port(). This *should* be ok since it'll // reset_port() preserves the event system if ticks were still enabled after a VM finished,
// be triggered by ticks and no Python will be running. // such as for an on-board display. Normally the event system would be reset between VM instantiations.
if (_tick_event_channel >= EVSYS_SYNCH_NUM) { if (_tick_event_channel >= EVSYS_SYNCH_NUM) {
turn_on_event_system(); turn_on_event_system();
_tick_event_channel = find_sync_event_channel(); _tick_event_channel = find_sync_event_channel();