void os_tick_idle(os_time_t ticks) { uint32_t ocmp; OS_ASSERT_CRITICAL(); if (ticks > 0) { /* * Enter tickless regime during long idle durations. */ if (ticks > g_hal_os_tick.max_idle_ticks) { ticks = g_hal_os_tick.max_idle_ticks; } ocmp = g_hal_os_tick.lastocmp + (ticks*g_hal_os_tick.ticks_per_ostick); nrf52_os_tick_set_ocmp(ocmp); } __DSB(); __WFI(); if (ticks > 0) { /* * Update OS time before anything else when coming out of * the tickless regime. */ nrf52_timer_handler(); } }
static void nrf52_timer_handler(void) { int delta; int ticks; os_sr_t sr; uint32_t counter; os_trace_enter_isr(); OS_ENTER_CRITICAL(sr); /* Calculate elapsed ticks and advance OS time. */ counter = nrf52_os_tick_counter(); delta = sub24(counter, g_hal_os_tick.lastocmp); ticks = delta / g_hal_os_tick.ticks_per_ostick; os_time_advance(ticks); /* Clear timer interrupt */ OS_TICK_TIMER->EVENTS_COMPARE[OS_TICK_CMPREG] = 0; /* Update the time associated with the most recent tick */ g_hal_os_tick.lastocmp = (g_hal_os_tick.lastocmp + (ticks * g_hal_os_tick.ticks_per_ostick)) & 0xffffff; /* Update the output compare to interrupt at the next tick */ nrf52_os_tick_set_ocmp(g_hal_os_tick.lastocmp + g_hal_os_tick.ticks_per_ostick); OS_EXIT_CRITICAL(sr); os_trace_exit_isr(); }