summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-04-07 13:07:29 -0700
committerScott Shawcroft <scott@tannewt.org>2020-04-07 13:07:29 -0700
commita8dfba235c6aa4370e7b07ad15539d86f0308edb (patch)
tree06398acaff121293570db0697bb15a2bd339b394
parentc49d2ea278ef01f87c47ecec40524dd2facef5e1 (diff)
Fix alarm so that it is correctly set.
-rw-r--r--ports/mimxrt10xx/common-hal/rtc/RTC.c1
-rw-r--r--ports/mimxrt10xx/supervisor/port.c11
2 files changed, 9 insertions, 3 deletions
diff --git a/ports/mimxrt10xx/common-hal/rtc/RTC.c b/ports/mimxrt10xx/common-hal/rtc/RTC.c
index 5d6cae520..6940a1817 100644
--- a/ports/mimxrt10xx/common-hal/rtc/RTC.c
+++ b/ports/mimxrt10xx/common-hal/rtc/RTC.c
@@ -72,5 +72,6 @@ int common_hal_rtc_get_calibration(void) {
}
void common_hal_rtc_set_calibration(int calibration) {
+ // SNVS has HPCALB_VAL bits for calibration.
mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
}
diff --git a/ports/mimxrt10xx/supervisor/port.c b/ports/mimxrt10xx/supervisor/port.c
index ef6fe2f97..842aa1be4 100644
--- a/ports/mimxrt10xx/supervisor/port.c
+++ b/ports/mimxrt10xx/supervisor/port.c
@@ -328,7 +328,7 @@ uint32_t *port_heap_get_top(void) {
return &_ld_heap_end;
}
-// Place the word to save just after our BSS section that gets blanked.
+// Place the word into the low power section of the SNVS.
void port_set_saved_word(uint32_t value) {
SNVS->LPGPR[1] = value;
}
@@ -366,8 +366,11 @@ void port_interrupt_after_ticks(uint32_t ticks) {
uint8_t subticks;
uint64_t current_ticks = port_get_raw_ticks(&subticks);
current_ticks += ticks;
- SNVS->HPTALR = current_ticks << 5 | subticks;
+ SNVS->HPCR &= ~SNVS_HPCR_HPTA_EN_MASK;
+ // Wait for the alarm to be disabled.
+ while ((SNVS->HPCR & SNVS_HPCR_HPTA_EN_MASK) != 0) {}
SNVS->HPTAMR = current_ticks >> (32 - 5);
+ SNVS->HPTALR = current_ticks << 5 | subticks;
SNVS->HPCR |= SNVS_HPCR_HPTA_EN_MASK;
}
@@ -379,8 +382,10 @@ void port_sleep_until_interrupt(void) {
__set_FPSCR(__get_FPSCR() & ~(0x9f));
(void) __get_FPSCR();
}
- // Call wait for interrupt ourselves if the SD isn't enabled.
+ NVIC_ClearPendingIRQ(SNVS_HP_WRAPPER_IRQn);
+ CLOCK_SetMode(kCLOCK_ModeWait);
__WFI();
+ CLOCK_SetMode(kCLOCK_ModeRun);
}
/**