Lines Matching full:timer
23 * @brief Handle expiration of a kernel timer object.
25 * @param t Timeout used by the timer.
29 struct k_timer *timer = CONTAINER_OF(t, struct k_timer, timeout); in z_timer_expiration_handler() local
36 * this function. Usually, the timeout structure related to the timer in z_timer_expiration_handler()
39 * interrupts are locked again, a given timer gets restarted from an in z_timer_expiration_handler()
40 * interrupt context that has a priority higher than the system timer in z_timer_expiration_handler()
41 * interrupt. Then, the timeout structure for this timer will turn out in z_timer_expiration_handler()
42 * to be linked to the timeout list. And in such case, since the timer in z_timer_expiration_handler()
52 * if the timer is periodic, start it again; don't add _TICK_ALIGN in z_timer_expiration_handler()
55 if (!K_TIMEOUT_EQ(timer->period, K_NO_WAIT) && in z_timer_expiration_handler()
56 !K_TIMEOUT_EQ(timer->period, K_FOREVER)) { in z_timer_expiration_handler()
57 k_timeout_t next = timer->period; in z_timer_expiration_handler()
76 z_add_timeout(&timer->timeout, z_timer_expiration_handler, in z_timer_expiration_handler()
80 /* update timer's status */ in z_timer_expiration_handler()
81 timer->status += 1U; in z_timer_expiration_handler()
83 /* invoke timer expiry function */ in z_timer_expiration_handler()
84 if (timer->expiry_fn != NULL) { in z_timer_expiration_handler()
87 timer->expiry_fn(timer); in z_timer_expiration_handler()
96 thread = z_waitq_head(&timer->wait_q); in z_timer_expiration_handler()
113 void k_timer_init(struct k_timer *timer, in k_timer_init() argument
117 timer->expiry_fn = expiry_fn; in k_timer_init()
118 timer->stop_fn = stop_fn; in k_timer_init()
119 timer->status = 0U; in k_timer_init()
122 z_waitq_init(&timer->wait_q); in k_timer_init()
125 z_init_timeout(&timer->timeout); in k_timer_init()
127 SYS_PORT_TRACING_OBJ_INIT(k_timer, timer); in k_timer_init()
129 timer->user_data = NULL; in k_timer_init()
131 k_object_init(timer); in k_timer_init()
134 k_obj_core_init_and_link(K_OBJ_CORE(timer), &obj_type_timer); in k_timer_init()
139 void z_impl_k_timer_start(struct k_timer *timer, k_timeout_t duration, in z_impl_k_timer_start() argument
142 SYS_PORT_TRACING_OBJ_FUNC(k_timer, start, timer, duration, period); in z_impl_k_timer_start()
147 * timer instance. in z_impl_k_timer_start()
160 * within the timer ISR, so no round up is desired and 1 is in z_impl_k_timer_start()
173 (void)z_abort_timeout(&timer->timeout); in z_impl_k_timer_start()
174 timer->period = period; in z_impl_k_timer_start()
175 timer->status = 0U; in z_impl_k_timer_start()
177 z_add_timeout(&timer->timeout, z_timer_expiration_handler, in z_impl_k_timer_start()
184 static inline void z_vrfy_k_timer_start(struct k_timer *timer, in z_vrfy_k_timer_start() argument
188 K_OOPS(K_SYSCALL_OBJ(timer, K_OBJ_TIMER)); in z_vrfy_k_timer_start()
189 z_impl_k_timer_start(timer, duration, period); in z_vrfy_k_timer_start()
194 void z_impl_k_timer_stop(struct k_timer *timer) in z_impl_k_timer_stop() argument
196 SYS_PORT_TRACING_OBJ_FUNC(k_timer, stop, timer); in z_impl_k_timer_stop()
198 bool inactive = (z_abort_timeout(&timer->timeout) != 0); in z_impl_k_timer_stop()
204 if (timer->stop_fn != NULL) { in z_impl_k_timer_stop()
205 timer->stop_fn(timer); in z_impl_k_timer_stop()
209 struct k_thread *pending_thread = z_unpend1_no_timeout(&timer->wait_q); in z_impl_k_timer_stop()
219 static inline void z_vrfy_k_timer_stop(struct k_timer *timer) in z_vrfy_k_timer_stop() argument
221 K_OOPS(K_SYSCALL_OBJ(timer, K_OBJ_TIMER)); in z_vrfy_k_timer_stop()
222 z_impl_k_timer_stop(timer); in z_vrfy_k_timer_stop()
227 uint32_t z_impl_k_timer_status_get(struct k_timer *timer) in z_impl_k_timer_status_get() argument
230 uint32_t result = timer->status; in z_impl_k_timer_status_get()
232 timer->status = 0U; in z_impl_k_timer_status_get()
239 static inline uint32_t z_vrfy_k_timer_status_get(struct k_timer *timer) in z_vrfy_k_timer_status_get() argument
241 K_OOPS(K_SYSCALL_OBJ(timer, K_OBJ_TIMER)); in z_vrfy_k_timer_status_get()
242 return z_impl_k_timer_status_get(timer); in z_vrfy_k_timer_status_get()
247 uint32_t z_impl_k_timer_status_sync(struct k_timer *timer) in z_impl_k_timer_status_sync() argument
250 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_timer, status_sync, timer); in z_impl_k_timer_status_sync()
258 if (!z_is_inactive_timeout(&timer->timeout)) { in z_impl_k_timer_status_sync()
259 result = *(volatile uint32_t *)&timer->status; in z_impl_k_timer_status_sync()
260 timer->status = 0U; in z_impl_k_timer_status_sync()
266 result = timer->status; in z_impl_k_timer_status_sync()
276 uint32_t result = timer->status; in z_impl_k_timer_status_sync()
279 if (!z_is_inactive_timeout(&timer->timeout)) { in z_impl_k_timer_status_sync()
280 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_timer, status_sync, timer, K_FOREVER); in z_impl_k_timer_status_sync()
282 /* wait for timer to expire or stop */ in z_impl_k_timer_status_sync()
283 (void)z_pend_curr(&lock, key, &timer->wait_q, K_FOREVER); in z_impl_k_timer_status_sync()
285 /* get updated timer status */ in z_impl_k_timer_status_sync()
287 result = timer->status; in z_impl_k_timer_status_sync()
289 /* timer is already stopped */ in z_impl_k_timer_status_sync()
292 /* timer has already expired at least once */ in z_impl_k_timer_status_sync()
295 timer->status = 0U; in z_impl_k_timer_status_sync()
301 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_timer, status_sync, timer, result); in z_impl_k_timer_status_sync()
307 static inline uint32_t z_vrfy_k_timer_status_sync(struct k_timer *timer) in z_vrfy_k_timer_status_sync() argument
309 K_OOPS(K_SYSCALL_OBJ(timer, K_OBJ_TIMER)); in z_vrfy_k_timer_status_sync()
310 return z_impl_k_timer_status_sync(timer); in z_vrfy_k_timer_status_sync()
315 const struct k_timer *timer) in z_vrfy_k_timer_remaining_ticks() argument
317 K_OOPS(K_SYSCALL_OBJ(timer, K_OBJ_TIMER)); in z_vrfy_k_timer_remaining_ticks()
318 return z_impl_k_timer_remaining_ticks(timer); in z_vrfy_k_timer_remaining_ticks()
323 const struct k_timer *timer) in z_vrfy_k_timer_expires_ticks() argument
325 K_OOPS(K_SYSCALL_OBJ(timer, K_OBJ_TIMER)); in z_vrfy_k_timer_expires_ticks()
326 return z_impl_k_timer_expires_ticks(timer); in z_vrfy_k_timer_expires_ticks()
330 static inline void *z_vrfy_k_timer_user_data_get(const struct k_timer *timer) in z_vrfy_k_timer_user_data_get() argument
332 K_OOPS(K_SYSCALL_OBJ(timer, K_OBJ_TIMER)); in z_vrfy_k_timer_user_data_get()
333 return z_impl_k_timer_user_data_get(timer); in z_vrfy_k_timer_user_data_get()
337 static inline void z_vrfy_k_timer_user_data_set(struct k_timer *timer, in z_vrfy_k_timer_user_data_set() argument
340 K_OOPS(K_SYSCALL_OBJ(timer, K_OBJ_TIMER)); in z_vrfy_k_timer_user_data_set()
341 z_impl_k_timer_user_data_set(timer, user_data); in z_vrfy_k_timer_user_data_set()
350 /* Initialize timer object type */ in init_timer_obj_core_list()
357 STRUCT_SECTION_FOREACH(k_timer, timer) { in init_timer_obj_core_list()
358 k_obj_core_init_and_link(K_OBJ_CORE(timer), &obj_type_timer); in init_timer_obj_core_list()