Lines Matching full:timer

15 #include <zephyr/drivers/timer/system_timer.h>
22 /* Maximum time interval between timer interrupts (in hw_cycles) */
36 /* Global timer state */
42 bool initialized; /* Set to true when timer is initialized */
43 sl_sleeptimer_timer_handle_t handle; /* Timer handle for system timer */
50 struct sleeptimer_timer_data *timer = data; in sleeptimer_cb() local
53 uint32_t prev = atomic_get(&timer->last_count); in sleeptimer_cb()
57 uint32_t unannounced = pending / timer->cyc_per_tick; in sleeptimer_cb()
59 atomic_set(&timer->last_count, prev + unannounced * timer->cyc_per_tick); in sleeptimer_cb()
64 static void sleeptimer_clock_set_timeout(int32_t ticks, struct sleeptimer_timer_data *timer) in sleeptimer_clock_set_timeout() argument
70 ticks = (ticks == K_TICKS_FOREVER) ? timer->max_timeout_ticks : ticks; in sleeptimer_clock_set_timeout()
71 ticks = CLAMP(ticks, 0, timer->max_timeout_ticks); in sleeptimer_clock_set_timeout()
73 k_spinlock_key_t key = k_spin_lock(&timer->lock); in sleeptimer_clock_set_timeout()
76 uint32_t prev = atomic_get(&timer->last_count); in sleeptimer_clock_set_timeout()
78 uint32_t next = ticks * timer->cyc_per_tick; in sleeptimer_clock_set_timeout()
85 next += timer->cyc_per_tick; in sleeptimer_clock_set_timeout()
89 sl_sleeptimer_restart_timer(&timer->handle, next, sleeptimer_cb, timer, 0, 0); in sleeptimer_clock_set_timeout()
90 k_spin_unlock(&timer->lock, key); in sleeptimer_clock_set_timeout()
93 static uint32_t sleeptimer_clock_elapsed(struct sleeptimer_timer_data *timer) in sleeptimer_clock_elapsed() argument
95 if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL) || !timer->initialized) { in sleeptimer_clock_elapsed()
99 return (sl_sleeptimer_get_tick_count() - atomic_get(&timer->last_count)) / in sleeptimer_clock_elapsed()
100 timer->cyc_per_tick; in sleeptimer_clock_elapsed()
124 struct sleeptimer_timer_data *timer = &g_sleeptimer_timer_data; in sleeptimer_init() local
137 timer->cyc_per_tick = z_clock_hw_cycles_per_sec / CONFIG_SYS_CLOCK_TICKS_PER_SEC; in sleeptimer_init()
139 __ASSERT(timer->cyc_per_tick >= MIN_DELAY_CYC, in sleeptimer_init()
142 "%d and timer frequency is %u", in sleeptimer_init()
143 timer->cyc_per_tick, MIN_DELAY_CYC, CONFIG_SYS_CLOCK_TICKS_PER_SEC, in sleeptimer_init()
146 timer->max_timeout_ticks = MAX_TIMEOUT_CYC / timer->cyc_per_tick; in sleeptimer_init()
147 timer->initialized = true; in sleeptimer_init()
149 atomic_set(&timer->last_count, sl_sleeptimer_get_tick_count()); in sleeptimer_init()
151 /* Start the timer and announce 1 kernel tick */ in sleeptimer_init()
153 status = sl_sleeptimer_start_timer(&timer->handle, timer->cyc_per_tick, in sleeptimer_init()
154 sleeptimer_cb, timer, 0, 0); in sleeptimer_init()
156 status = sl_sleeptimer_start_periodic_timer(&timer->handle, timer->cyc_per_tick, in sleeptimer_init()
157 sleeptimer_cb, timer, 0, 0); in sleeptimer_init()