Perform as little work as possible in the interrupt callbacks

This commit is contained in:
Alessandro Genova
2025-08-09 11:47:57 -04:00
parent 9770ad4fe9
commit a71967a015
2 changed files with 85 additions and 35 deletions
+4 -5
View File
@@ -207,7 +207,7 @@ void watch_rtc_schedule_next_comp(void) {
}
// Because of the hardware, the soonest we can schedule is the next tick
curr_counter +=1;
// curr_counter +=1;
bool schedule_any = false;
rtc_counter_t comp_counter;
@@ -278,9 +278,8 @@ void watch_rtc_disable_comp_callback_no_schedule(uint8_t index) {
void watch_rtc_callback(uint16_t interrupt_cause) {
// First read all relevant registers, to ensure no changes occurr during the callbacks
uint16_t interrupt_enabled = RTC->MODE0.INTENSET.reg;
rtc_counter_t counter = watch_rtc_get_counter();
uint16_t interrupt_enabled = (uint16_t)RTC->MODE0.INTENSET.reg;
if ((interrupt_cause & interrupt_enabled) & RTC_MODE0_INTFLAG_PER_Msk) {
// handle the tick callback first, it's what we do the most.
@@ -309,12 +308,12 @@ void watch_rtc_callback(uint16_t interrupt_cause) {
if ((interrupt_cause & interrupt_enabled) & RTC_MODE0_INTFLAG_CMP0) {
// The comp interrupt is generated one tick after the matched counter
rtc_counter_t comp_counter = counter - 1;
// rtc_counter_t comp_counter = counter - 1;
for (uint8_t index = 0; index < WATCH_RTC_N_COMP_CB; ++index) {
// Give it a little bit of wiggle room, if a comp callback is enabled and is just passed
if (comp_callbacks[index].enabled &&
(comp_counter - comp_callbacks[index].counter) <= RTC_CNT_HZ
(counter - comp_callbacks[index].counter) <= RTC_CNT_HZ
) {
comp_callbacks[index].enabled = false;
comp_callbacks[index].callback();