static void rtc_update(drv_rtc_t const * const p_instance)
{
while(1)
{
app_timer_t * p_next = sortlist_peek();
bool rtc_reconf = false;
if (p_next) //Candidate for active timer
{
if (mp_active_timer == NULL)
{
//There is no active timer so candidate will become active timer.
rtc_reconf = true;
}
else if (p_next->end_val < mp_active_timer->end_val)
{
//Candidate has shorter timeout than current active timer. Candidate will replace active timer.
//Active timer is put back into sorted list.
rtc_reconf = true;
if (mp_active_timer->active)
{
NRF_LOG_INST_DEBUG(mp_active_timer->p_log, "Timer preempted.");
nrf_sortlist_add(&m_app_timer_sortlist, &mp_active_timer->list_item);
}
}
if (rtc_reconf)
{
bool rerun;
p_next = sortlist_pop();
NRF_LOG_INST_DEBUG(p_next->p_log, "Activating timer (CC:%d/%08x).", p_next->end_val, p_next->end_val);
if (rtc_schedule(p_next, &rerun))
{
if (!APP_TIMER_KEEPS_RTC_ACTIVE && (mp_active_timer == NULL))
{
drv_rtc_start(p_instance);
}
mp_active_timer = p_next;
if (rerun == false)
{
//RTC was successfully updated and sortlist was not updated. Function can be terminated.
//printf("RTC was successfully updated\n");
break;
}
}
else
{
//If RTC driver indicated that timeout already occured a new candidate will be taken from sorted list.
//NRF_LOG_INST_DEBUG(p_next->p_log,"Timer expired before scheduled to RTC.");
//printf("Timer expired before scheduled to RTC\n");
mp_active_timer = NULL;
}
}
else
{
//RTC will not be updated. Function can terminate.
break;
}
}
else //No candidate for active timer.
{
if (!APP_TIMER_KEEPS_RTC_ACTIVE && (mp_active_timer == NULL))
{
drv_rtc_stop(p_instance);
}
break;
}
}
}
其中代码片段:
if (rtc_schedule(p_next, &rerun))
{
if (!APP_TIMER_KEEPS_RTC_ACTIVE && (mp_active_timer == NULL))
{
drv_rtc_start(p_instance);
}
mp_active_timer = p_next; if (rerun == false)
{
//RTC was successfully updated and sortlist was not updated. Function can be terminated.
//printf("RTC was successfully updated\n");
break;
}
} }
rtc_schedule后,每次都会 drv_rtc_start(p_instance),重新启动RTC1计数器,会清零Counter吗
|