From ac33c3fe2c8f8bd866b205ecb844b2f1b9fffcdd Mon Sep 17 00:00:00 2001 From: DavePutz Date: Sat, 4 Jul 2020 21:17:19 -0500 Subject: [PATCH] Implementation of continuous synchronization of RTC during pulsein Flags and code to implement continuous synchronization of RTC during pulsein --- ports/atmel-samd/supervisor/port.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 48bd3211b5..05ce0eb09b 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -91,6 +91,23 @@ #if CIRCUITPY_PEW #include "common-hal/_pew/PewPew.h" #endif +#ifdef SAMD21 +volatile bool hold_interrupt = false; + +void rtc_start_pulsein(void) { + rtc_set_continuous(); + hold_interrupt = true; +} +void rtc_end_pulsein(void) { + hold_interrupt = false; +} + +void rtc_set_continuous(void) { + while (RTC->MODE0.STATUS.bit.SYNCBUSY); + RTC->MODE0.READREQ.reg = RTC_READREQ_RREQ | RTC_READREQ_RCONT | 0x0010; + while (RTC->MODE0.STATUS.bit.SYNCBUSY); +} +#endif extern volatile bool mp_msc_enabled; @@ -489,6 +506,11 @@ void port_interrupt_after_ticks(uint32_t ticks) { // We'll interrupt sooner with an overflow. return; } +#ifdef SAMD21 + if (hold_interrupt == true) { + return; + } +#endif RTC->MODE0.COMP[0].reg = current_ticks + (ticks << 4); RTC->MODE0.INTFLAG.reg = RTC_MODE0_INTFLAG_CMP0; RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_CMP0;