diff --git a/cpu/cc26xx-cc13xx/dev/soc-rtc.c b/cpu/cc26xx-cc13xx/dev/soc-rtc.c index fb5394947..08d9a7cce 100644 --- a/cpu/cc26xx-cc13xx/dev/soc-rtc.c +++ b/cpu/cc26xx-cc13xx/dev/soc-rtc.c @@ -142,14 +142,12 @@ soc_rtc_last_isr_time(void) void soc_rtc_isr(void) { - uint32_t now, next; + uint32_t next; ENERGEST_ON(ENERGEST_TYPE_IRQ); last_isr_time = RTIMER_NOW(); - now = ti_lib_aon_rtc_current_compare_value_get(); - /* Adjust the s/w tick counter irrespective of which event trigger this */ clock_update(); @@ -161,7 +159,8 @@ soc_rtc_isr(void) * event on the next 512 tick boundary. If we drop to deep sleep before it * happens, lpm_drop() will reschedule us in the 'distant' future */ - next = (now + COMPARE_INCREMENT) & MULTIPLE_512_MASK; + next = ((ti_lib_aon_rtc_current_compare_value_get() + 5) + + COMPARE_INCREMENT) & MULTIPLE_512_MASK; ti_lib_aon_rtc_compare_value_set(AON_RTC_CH1, next); } diff --git a/cpu/cc26xx-cc13xx/lpm.c b/cpu/cc26xx-cc13xx/lpm.c index c9e874824..6af58e899 100644 --- a/cpu/cc26xx-cc13xx/lpm.c +++ b/cpu/cc26xx-cc13xx/lpm.c @@ -244,8 +244,18 @@ lpm_drop() uint32_t domains = LOCKABLE_DOMAINS; + /* Critical. Don't get interrupted! */ + ti_lib_int_master_disable(); + + /* Check if any events fired before we turned interrupts off. If so, abort */ + if(process_nevents()) { + ti_lib_int_master_enable(); + return; + } + if(RTIMER_CLOCK_LT(soc_rtc_get_next_trigger(), RTIMER_NOW() + STANDBY_MIN_DURATION)) { + ti_lib_int_master_enable(); lpm_sleep(); return; } @@ -261,30 +271,20 @@ lpm_drop() } } - /* Check if any events fired during this process. Last chance to abort */ - if(process_nevents()) { - return; + /* Reschedule AON RTC CH1 to fire just in time for the next etimer event */ + next_event = etimer_next_expiration_time(); + + if(etimer_pending()) { + next_event = next_event - clock_time(); + soc_rtc_schedule_one_shot(AON_RTC_CH1, soc_rtc_last_isr_time() + + (next_event * (RTIMER_SECOND / CLOCK_SECOND))); } /* Drop */ if(max_pm == LPM_MODE_SLEEP) { + ti_lib_int_master_enable(); lpm_sleep(); } else { - /* Critical. Don't get interrupted! */ - ti_lib_int_master_disable(); - - /* - * Reschedule AON RTC CH1 to fire an event N ticks before the next etimer - * event - */ - next_event = etimer_next_expiration_time(); - - if(next_event) { - next_event = next_event - clock_time(); - soc_rtc_schedule_one_shot(AON_RTC_CH1, soc_rtc_last_isr_time() + - (next_event * (RTIMER_SECOND / CLOCK_SECOND))); - } - /* * Notify all registered modules that we are dropping to mode X. We do not * need to do this for simple sleep.