Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1997-2016 Wind River Systems, Inc. |
| 3 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: Apache-2.0 |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 7 | #include <kernel.h> |
Anas Nashif | 569f0b4 | 2016-12-17 13:18:45 -0500 | [diff] [blame] | 8 | #include <debug/object_tracing_common.h> |
Allan Stephens | e7d2cc2 | 2016-10-19 16:10:46 -0500 | [diff] [blame] | 9 | #include <init.h> |
Stephanos Ioannidis | 2d74604 | 2019-10-25 00:08:21 +0900 | [diff] [blame] | 10 | #include <ksched.h> |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 11 | #include <wait_q.h> |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 12 | #include <syscall_handler.h> |
Flavio Ceolin | 76b3518 | 2018-12-16 12:48:29 -0800 | [diff] [blame] | 13 | #include <stdbool.h> |
Andy Ross | b29fb22 | 2019-02-05 16:19:30 -0800 | [diff] [blame] | 14 | #include <spinlock.h> |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 15 | |
Andy Ross | b29fb22 | 2019-02-05 16:19:30 -0800 | [diff] [blame] | 16 | static struct k_spinlock lock; |
| 17 | |
Anas Nashif | 2f203c2 | 2016-12-18 06:57:45 -0500 | [diff] [blame] | 18 | #ifdef CONFIG_OBJECT_TRACING |
Allan Stephens | e7d2cc2 | 2016-10-19 16:10:46 -0500 | [diff] [blame] | 19 | |
Maciek Borzecki | 059544d | 2017-05-18 12:16:45 +0200 | [diff] [blame] | 20 | struct k_timer *_trace_list_k_timer; |
| 21 | |
Allan Stephens | e7d2cc2 | 2016-10-19 16:10:46 -0500 | [diff] [blame] | 22 | /* |
| 23 | * Complete initialization of statically defined timers. |
| 24 | */ |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 25 | static int init_timer_module(const struct device *dev) |
Allan Stephens | e7d2cc2 | 2016-10-19 16:10:46 -0500 | [diff] [blame] | 26 | { |
| 27 | ARG_UNUSED(dev); |
| 28 | |
Nicolas Pitre | aa922885 | 2019-06-03 13:01:43 -0400 | [diff] [blame] | 29 | Z_STRUCT_SECTION_FOREACH(k_timer, timer) { |
Allan Stephens | e7d2cc2 | 2016-10-19 16:10:46 -0500 | [diff] [blame] | 30 | SYS_TRACING_OBJ_INIT(k_timer, timer); |
| 31 | } |
| 32 | return 0; |
| 33 | } |
| 34 | |
Andrew Boie | 0b474ee | 2016-11-08 11:06:55 -0800 | [diff] [blame] | 35 | SYS_INIT(init_timer_module, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS); |
Allan Stephens | e7d2cc2 | 2016-10-19 16:10:46 -0500 | [diff] [blame] | 36 | |
Anas Nashif | 2f203c2 | 2016-12-18 06:57:45 -0500 | [diff] [blame] | 37 | #endif /* CONFIG_OBJECT_TRACING */ |
Allan Stephens | e7d2cc2 | 2016-10-19 16:10:46 -0500 | [diff] [blame] | 38 | |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 39 | /** |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 40 | * @brief Handle expiration of a kernel timer object. |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 41 | * |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 42 | * @param t Timeout used by the timer. |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 43 | * |
| 44 | * @return N/A |
| 45 | */ |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 46 | void z_timer_expiration_handler(struct _timeout *t) |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 47 | { |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 48 | struct k_timer *timer = CONTAINER_OF(t, struct k_timer, timeout); |
Benjamin Walsh | b889fa8 | 2016-12-07 22:39:31 -0500 | [diff] [blame] | 49 | struct k_thread *thread; |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 50 | |
Allan Stephens | 6c98c4d | 2016-10-17 14:34:53 -0500 | [diff] [blame] | 51 | /* |
| 52 | * if the timer is periodic, start it again; don't add _TICK_ALIGN |
| 53 | * since we're already aligned to a tick boundary |
| 54 | */ |
Andy Ross | 7832738 | 2020-03-05 15:18:14 -0800 | [diff] [blame] | 55 | if (!K_TIMEOUT_EQ(timer->period, K_NO_WAIT) && |
| 56 | !K_TIMEOUT_EQ(timer->period, K_FOREVER)) { |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 57 | z_add_timeout(&timer->timeout, z_timer_expiration_handler, |
Andy Ross | fe82f1c | 2018-09-26 15:14:21 -0700 | [diff] [blame] | 58 | timer->period); |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 61 | /* update timer's status */ |
Patrik Flykt | 24d7143 | 2019-03-26 19:57:45 -0600 | [diff] [blame] | 62 | timer->status += 1U; |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 63 | |
| 64 | /* invoke timer expiry function */ |
Flavio Ceolin | 76b3518 | 2018-12-16 12:48:29 -0800 | [diff] [blame] | 65 | if (timer->expiry_fn != NULL) { |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 66 | timer->expiry_fn(timer); |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 67 | } |
Benjamin Walsh | b889fa8 | 2016-12-07 22:39:31 -0500 | [diff] [blame] | 68 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 69 | thread = z_waitq_head(&timer->wait_q); |
Benjamin Walsh | b889fa8 | 2016-12-07 22:39:31 -0500 | [diff] [blame] | 70 | |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 71 | if (thread == NULL) { |
Benjamin Walsh | b889fa8 | 2016-12-07 22:39:31 -0500 | [diff] [blame] | 72 | return; |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 73 | } |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 74 | |
Benjamin Walsh | b889fa8 | 2016-12-07 22:39:31 -0500 | [diff] [blame] | 75 | /* |
Andy Ross | 22642cf | 2018-04-02 18:24:58 -0700 | [diff] [blame] | 76 | * Interrupts _DO NOT_ have to be locked in this specific |
| 77 | * instance of thread unpending because a) this is the only |
| 78 | * place a thread can be taken off this pend queue, and b) the |
| 79 | * only place a thread can be put on the pend queue is at |
| 80 | * thread level, which of course cannot interrupt the current |
| 81 | * context. |
Benjamin Walsh | b889fa8 | 2016-12-07 22:39:31 -0500 | [diff] [blame] | 82 | */ |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 83 | z_unpend_thread_no_timeout(thread); |
Benjamin Walsh | b889fa8 | 2016-12-07 22:39:31 -0500 | [diff] [blame] | 84 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 85 | z_ready_thread(thread); |
Benjamin Walsh | b889fa8 | 2016-12-07 22:39:31 -0500 | [diff] [blame] | 86 | |
Andrew Boie | 4f77c2a | 2019-11-07 12:43:29 -0800 | [diff] [blame] | 87 | arch_thread_return_value_set(thread, 0); |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 91 | void k_timer_init(struct k_timer *timer, |
Flavio Ceolin | 118715c | 2018-11-16 19:52:37 -0800 | [diff] [blame] | 92 | k_timer_expiry_t expiry_fn, |
| 93 | k_timer_stop_t stop_fn) |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 94 | { |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 95 | timer->expiry_fn = expiry_fn; |
| 96 | timer->stop_fn = stop_fn; |
Patrik Flykt | 24d7143 | 2019-03-26 19:57:45 -0600 | [diff] [blame] | 97 | timer->status = 0U; |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 98 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 99 | z_waitq_init(&timer->wait_q); |
Peter A. Bigot | 5639ea0 | 2019-09-27 09:20:26 -0500 | [diff] [blame] | 100 | z_init_timeout(&timer->timeout); |
Allan Stephens | e7d2cc2 | 2016-10-19 16:10:46 -0500 | [diff] [blame] | 101 | SYS_TRACING_OBJ_INIT(k_timer, timer); |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 102 | |
Maciek Borzecki | 4fef760 | 2017-05-18 08:49:50 +0200 | [diff] [blame] | 103 | timer->user_data = NULL; |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 104 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 105 | z_object_init(timer); |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
Andy Ross | 7832738 | 2020-03-05 15:18:14 -0800 | [diff] [blame] | 109 | void z_impl_k_timer_start(struct k_timer *timer, k_timeout_t duration, |
| 110 | k_timeout_t period) |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 111 | { |
Andy Ross | a343cf9 | 2020-05-29 07:36:39 -0700 | [diff] [blame] | 112 | if (K_TIMEOUT_EQ(duration, K_FOREVER)) { |
| 113 | return; |
| 114 | } |
| 115 | |
Andy Ross | 7832738 | 2020-03-05 15:18:14 -0800 | [diff] [blame] | 116 | #ifdef CONFIG_LEGACY_TIMEOUT_API |
| 117 | duration = k_ms_to_ticks_ceil32(duration); |
| 118 | period = k_ms_to_ticks_ceil32(period); |
| 119 | #else |
| 120 | /* z_add_timeout() always adds one to the incoming tick count |
| 121 | * to round up to the next tick (by convention it waits for |
| 122 | * "at least as long as the specified timeout"), but the |
| 123 | * period interval is always guaranteed to be reset from |
| 124 | * within the timer ISR, so no round up is desired. Subtract |
| 125 | * one. |
| 126 | * |
| 127 | * Note that the duration (!) value gets the same treatment |
| 128 | * for backwards compatibility. This is unfortunate |
| 129 | * (i.e. k_timer_start() doesn't treat its initial sleep |
| 130 | * argument the same way k_sleep() does), but historical. The |
| 131 | * timer_api test relies on this behavior. |
| 132 | */ |
Andy Ross | 3e729b2 | 2020-04-23 10:05:31 -0700 | [diff] [blame] | 133 | if (period.ticks != 0 && Z_TICK_ABS(period.ticks) < 0) { |
| 134 | period.ticks = MAX(period.ticks - 1, 1); |
| 135 | } |
Andy Ross | 4c7b77a | 2020-03-09 09:35:35 -0700 | [diff] [blame] | 136 | if (Z_TICK_ABS(duration.ticks) < 0) { |
| 137 | duration.ticks = MAX(duration.ticks - 1, 0); |
| 138 | } |
Andy Ross | 7832738 | 2020-03-05 15:18:14 -0800 | [diff] [blame] | 139 | #endif |
Benjamin Walsh | 6ca6c28 | 2016-12-09 13:39:00 -0500 | [diff] [blame] | 140 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 141 | (void)z_abort_timeout(&timer->timeout); |
Andy Ross | 7832738 | 2020-03-05 15:18:14 -0800 | [diff] [blame] | 142 | timer->period = period; |
Patrik Flykt | 24d7143 | 2019-03-26 19:57:45 -0600 | [diff] [blame] | 143 | timer->status = 0U; |
Andy Ross | 7832738 | 2020-03-05 15:18:14 -0800 | [diff] [blame] | 144 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 145 | z_add_timeout(&timer->timeout, z_timer_expiration_handler, |
Andy Ross | 7832738 | 2020-03-05 15:18:14 -0800 | [diff] [blame] | 146 | duration); |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 149 | #ifdef CONFIG_USERSPACE |
Andy Ross | 643701a | 2019-08-13 12:58:38 -0700 | [diff] [blame] | 150 | static inline void z_vrfy_k_timer_start(struct k_timer *timer, |
Andy Ross | 7832738 | 2020-03-05 15:18:14 -0800 | [diff] [blame] | 151 | k_timeout_t duration, |
| 152 | k_timeout_t period) |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 153 | { |
Andrew Boie | 8345e5e | 2018-05-04 15:57:57 -0700 | [diff] [blame] | 154 | Z_OOPS(Z_SYSCALL_OBJ(timer, K_OBJ_TIMER)); |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 155 | z_impl_k_timer_start(timer, duration, period); |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 156 | } |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 157 | #include <syscalls/k_timer_start_mrsh.c> |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 158 | #endif |
| 159 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 160 | void z_impl_k_timer_stop(struct k_timer *timer) |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 161 | { |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 162 | int inactive = z_abort_timeout(&timer->timeout) != 0; |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 163 | |
Benjamin Walsh | d211a52 | 2016-12-06 11:44:01 -0500 | [diff] [blame] | 164 | if (inactive) { |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
Flavio Ceolin | 76b3518 | 2018-12-16 12:48:29 -0800 | [diff] [blame] | 168 | if (timer->stop_fn != NULL) { |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 169 | timer->stop_fn(timer); |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 172 | struct k_thread *pending_thread = z_unpend1_no_timeout(&timer->wait_q); |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 173 | |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 174 | if (pending_thread != NULL) { |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 175 | z_ready_thread(pending_thread); |
| 176 | z_reschedule_unlocked(); |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 177 | } |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 178 | } |
| 179 | |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 180 | #ifdef CONFIG_USERSPACE |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 181 | static inline void z_vrfy_k_timer_stop(struct k_timer *timer) |
| 182 | { |
| 183 | Z_OOPS(Z_SYSCALL_OBJ(timer, K_OBJ_TIMER)); |
| 184 | z_impl_k_timer_stop(timer); |
| 185 | } |
| 186 | #include <syscalls/k_timer_stop_mrsh.c> |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 187 | #endif |
| 188 | |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 189 | uint32_t z_impl_k_timer_status_get(struct k_timer *timer) |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 190 | { |
Andy Ross | b29fb22 | 2019-02-05 16:19:30 -0800 | [diff] [blame] | 191 | k_spinlock_key_t key = k_spin_lock(&lock); |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 192 | uint32_t result = timer->status; |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 193 | |
Patrik Flykt | 24d7143 | 2019-03-26 19:57:45 -0600 | [diff] [blame] | 194 | timer->status = 0U; |
Andy Ross | b29fb22 | 2019-02-05 16:19:30 -0800 | [diff] [blame] | 195 | k_spin_unlock(&lock, key); |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 196 | |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 197 | return result; |
| 198 | } |
| 199 | |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 200 | #ifdef CONFIG_USERSPACE |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 201 | static inline uint32_t z_vrfy_k_timer_status_get(struct k_timer *timer) |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 202 | { |
| 203 | Z_OOPS(Z_SYSCALL_OBJ(timer, K_OBJ_TIMER)); |
| 204 | return z_impl_k_timer_status_get(timer); |
| 205 | } |
| 206 | #include <syscalls/k_timer_status_get_mrsh.c> |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 207 | #endif |
| 208 | |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 209 | uint32_t z_impl_k_timer_status_sync(struct k_timer *timer) |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 210 | { |
Andrew Boie | 4f77c2a | 2019-11-07 12:43:29 -0800 | [diff] [blame] | 211 | __ASSERT(!arch_is_in_isr(), ""); |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 212 | |
Andy Ross | b29fb22 | 2019-02-05 16:19:30 -0800 | [diff] [blame] | 213 | k_spinlock_key_t key = k_spin_lock(&lock); |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 214 | uint32_t result = timer->status; |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 215 | |
Patrik Flykt | 24d7143 | 2019-03-26 19:57:45 -0600 | [diff] [blame] | 216 | if (result == 0U) { |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 217 | if (!z_is_inactive_timeout(&timer->timeout)) { |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 218 | /* wait for timer to expire or stop */ |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 219 | (void)z_pend_curr(&lock, key, &timer->wait_q, K_FOREVER); |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 220 | |
| 221 | /* get updated timer status */ |
Andy Ross | b29fb22 | 2019-02-05 16:19:30 -0800 | [diff] [blame] | 222 | key = k_spin_lock(&lock); |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 223 | result = timer->status; |
| 224 | } else { |
| 225 | /* timer is already stopped */ |
| 226 | } |
| 227 | } else { |
| 228 | /* timer has already expired at least once */ |
| 229 | } |
| 230 | |
Patrik Flykt | 24d7143 | 2019-03-26 19:57:45 -0600 | [diff] [blame] | 231 | timer->status = 0U; |
Andy Ross | b29fb22 | 2019-02-05 16:19:30 -0800 | [diff] [blame] | 232 | k_spin_unlock(&lock, key); |
Allan Stephens | 45bfa37 | 2016-10-12 12:39:42 -0500 | [diff] [blame] | 233 | |
| 234 | return result; |
| 235 | } |
| 236 | |
Andrew Boie | a354d49 | 2017-09-29 16:22:28 -0700 | [diff] [blame] | 237 | #ifdef CONFIG_USERSPACE |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 238 | static inline uint32_t z_vrfy_k_timer_status_sync(struct k_timer *timer) |
Andrew Boie | 225e4c0 | 2017-10-12 09:54:26 -0700 | [diff] [blame] | 239 | { |
Andrew Boie | 8345e5e | 2018-05-04 15:57:57 -0700 | [diff] [blame] | 240 | Z_OOPS(Z_SYSCALL_OBJ(timer, K_OBJ_TIMER)); |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 241 | return z_impl_k_timer_status_sync(timer); |
Andrew Boie | 225e4c0 | 2017-10-12 09:54:26 -0700 | [diff] [blame] | 242 | } |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 243 | #include <syscalls/k_timer_status_sync_mrsh.c> |
| 244 | |
Andy Ross | 5a5d3da | 2020-03-09 13:59:15 -0700 | [diff] [blame] | 245 | static inline k_ticks_t z_vrfy_k_timer_remaining_ticks(struct k_timer *timer) |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 246 | { |
| 247 | Z_OOPS(Z_SYSCALL_OBJ(timer, K_OBJ_TIMER)); |
Andy Ross | 5a5d3da | 2020-03-09 13:59:15 -0700 | [diff] [blame] | 248 | return z_impl_k_timer_remaining_ticks(timer); |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 249 | } |
Andy Ross | 5a5d3da | 2020-03-09 13:59:15 -0700 | [diff] [blame] | 250 | #include <syscalls/k_timer_remaining_ticks_mrsh.c> |
| 251 | |
| 252 | static inline k_ticks_t z_vrfy_k_timer_expires_ticks(struct k_timer *timer) |
| 253 | { |
| 254 | Z_OOPS(Z_SYSCALL_OBJ(timer, K_OBJ_TIMER)); |
| 255 | return z_impl_k_timer_expires_ticks(timer); |
| 256 | } |
| 257 | #include <syscalls/k_timer_expires_ticks_mrsh.c> |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 258 | |
Peter A. Bigot | f1b86ca | 2020-09-18 16:24:57 -0500 | [diff] [blame] | 259 | static inline void *z_vrfy_k_timer_user_data_get(const struct k_timer *timer) |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 260 | { |
| 261 | Z_OOPS(Z_SYSCALL_OBJ(timer, K_OBJ_TIMER)); |
| 262 | return z_impl_k_timer_user_data_get(timer); |
| 263 | } |
| 264 | #include <syscalls/k_timer_user_data_get_mrsh.c> |
| 265 | |
Andy Ross | 643701a | 2019-08-13 12:58:38 -0700 | [diff] [blame] | 266 | static inline void z_vrfy_k_timer_user_data_set(struct k_timer *timer, |
| 267 | void *user_data) |
Andy Ross | 6564974 | 2019-08-06 13:34:31 -0700 | [diff] [blame] | 268 | { |
| 269 | Z_OOPS(Z_SYSCALL_OBJ(timer, K_OBJ_TIMER)); |
| 270 | z_impl_k_timer_user_data_set(timer, user_data); |
| 271 | } |
| 272 | #include <syscalls/k_timer_user_data_set_mrsh.c> |
| 273 | |
Andrew Boie | 225e4c0 | 2017-10-12 09:54:26 -0700 | [diff] [blame] | 274 | #endif |