Fix alarm so that it is correctly set.

This commit is contained in:
Scott Shawcroft 2020-04-07 13:07:29 -07:00
parent c49d2ea278
commit a8dfba235c
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
2 changed files with 9 additions and 3 deletions

View File

@ -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"));
}

View File

@ -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);
}
/**