Lines Matching refs:msgq

33 static inline void handle_poll_events(struct k_msgq *msgq, uint32_t state)  in handle_poll_events()  argument
35 z_handle_obj_poll_events(&msgq->poll_events, state); in handle_poll_events()
39 void k_msgq_init(struct k_msgq *msgq, char *buffer, size_t msg_size, in k_msgq_init() argument
42 msgq->msg_size = msg_size; in k_msgq_init()
43 msgq->max_msgs = max_msgs; in k_msgq_init()
44 msgq->buffer_start = buffer; in k_msgq_init()
45 msgq->buffer_end = buffer + (max_msgs * msg_size); in k_msgq_init()
46 msgq->read_ptr = buffer; in k_msgq_init()
47 msgq->write_ptr = buffer; in k_msgq_init()
48 msgq->used_msgs = 0; in k_msgq_init()
49 msgq->flags = 0; in k_msgq_init()
50 z_waitq_init(&msgq->wait_q); in k_msgq_init()
51 msgq->lock = (struct k_spinlock) {}; in k_msgq_init()
53 sys_dlist_init(&msgq->poll_events); in k_msgq_init()
57 k_obj_core_init_and_link(K_OBJ_CORE(msgq), &obj_type_msgq); in k_msgq_init()
60 SYS_PORT_TRACING_OBJ_INIT(k_msgq, msgq); in k_msgq_init()
62 k_object_init(msgq); in k_msgq_init()
65 int z_impl_k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size, in z_impl_k_msgq_alloc_init() argument
72 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, alloc_init, msgq); in z_impl_k_msgq_alloc_init()
79 k_msgq_init(msgq, buffer, msg_size, max_msgs); in z_impl_k_msgq_alloc_init()
80 msgq->flags = K_MSGQ_FLAG_ALLOC; in z_impl_k_msgq_alloc_init()
87 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, alloc_init, msgq, ret); in z_impl_k_msgq_alloc_init()
93 int z_vrfy_k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size, in z_vrfy_k_msgq_alloc_init() argument
96 K_OOPS(K_SYSCALL_OBJ_NEVER_INIT(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_alloc_init()
98 return z_impl_k_msgq_alloc_init(msgq, msg_size, max_msgs); in z_vrfy_k_msgq_alloc_init()
103 int k_msgq_cleanup(struct k_msgq *msgq) in k_msgq_cleanup() argument
105 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, cleanup, msgq); in k_msgq_cleanup()
107 CHECKIF(z_waitq_head(&msgq->wait_q) != NULL) { in k_msgq_cleanup()
108 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, cleanup, msgq, -EBUSY); in k_msgq_cleanup()
113 if ((msgq->flags & K_MSGQ_FLAG_ALLOC) != 0U) { in k_msgq_cleanup()
114 k_free(msgq->buffer_start); in k_msgq_cleanup()
115 msgq->flags &= ~K_MSGQ_FLAG_ALLOC; in k_msgq_cleanup()
118 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, cleanup, msgq, 0); in k_msgq_cleanup()
124 int z_impl_k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t timeout) in z_impl_k_msgq_put() argument
132 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_put()
134 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, put, msgq, timeout); in z_impl_k_msgq_put()
136 if (msgq->used_msgs < msgq->max_msgs) { in z_impl_k_msgq_put()
138 pending_thread = z_unpend_first_thread(&msgq->wait_q); in z_impl_k_msgq_put()
140 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, 0); in z_impl_k_msgq_put()
144 msgq->msg_size); in z_impl_k_msgq_put()
148 z_reschedule(&msgq->lock, key); in z_impl_k_msgq_put()
152 __ASSERT_NO_MSG(msgq->write_ptr >= msgq->buffer_start && in z_impl_k_msgq_put()
153 msgq->write_ptr < msgq->buffer_end); in z_impl_k_msgq_put()
154 (void)memcpy(msgq->write_ptr, (char *)data, msgq->msg_size); in z_impl_k_msgq_put()
155 msgq->write_ptr += msgq->msg_size; in z_impl_k_msgq_put()
156 if (msgq->write_ptr == msgq->buffer_end) { in z_impl_k_msgq_put()
157 msgq->write_ptr = msgq->buffer_start; in z_impl_k_msgq_put()
159 msgq->used_msgs++; in z_impl_k_msgq_put()
161 handle_poll_events(msgq, K_POLL_STATE_MSGQ_DATA_AVAILABLE); in z_impl_k_msgq_put()
169 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, put, msgq, timeout); in z_impl_k_msgq_put()
174 result = z_pend_curr(&msgq->lock, key, &msgq->wait_q, timeout); in z_impl_k_msgq_put()
175 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, result); in z_impl_k_msgq_put()
179 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, result); in z_impl_k_msgq_put()
181 z_reschedule(&msgq->lock, key); in z_impl_k_msgq_put()
187 static inline int z_vrfy_k_msgq_put(struct k_msgq *msgq, const void *data, in z_vrfy_k_msgq_put() argument
190 K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_put()
191 K_OOPS(K_SYSCALL_MEMORY_READ(data, msgq->msg_size)); in z_vrfy_k_msgq_put()
193 return z_impl_k_msgq_put(msgq, data, timeout); in z_vrfy_k_msgq_put()
198 void z_impl_k_msgq_get_attrs(struct k_msgq *msgq, struct k_msgq_attrs *attrs) in z_impl_k_msgq_get_attrs() argument
200 attrs->msg_size = msgq->msg_size; in z_impl_k_msgq_get_attrs()
201 attrs->max_msgs = msgq->max_msgs; in z_impl_k_msgq_get_attrs()
202 attrs->used_msgs = msgq->used_msgs; in z_impl_k_msgq_get_attrs()
206 static inline void z_vrfy_k_msgq_get_attrs(struct k_msgq *msgq, in z_vrfy_k_msgq_get_attrs() argument
209 K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_get_attrs()
211 z_impl_k_msgq_get_attrs(msgq, attrs); in z_vrfy_k_msgq_get_attrs()
216 int z_impl_k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout) in z_impl_k_msgq_get() argument
224 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_get()
226 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, get, msgq, timeout); in z_impl_k_msgq_get()
228 if (msgq->used_msgs > 0U) { in z_impl_k_msgq_get()
230 (void)memcpy((char *)data, msgq->read_ptr, msgq->msg_size); in z_impl_k_msgq_get()
231 msgq->read_ptr += msgq->msg_size; in z_impl_k_msgq_get()
232 if (msgq->read_ptr == msgq->buffer_end) { in z_impl_k_msgq_get()
233 msgq->read_ptr = msgq->buffer_start; in z_impl_k_msgq_get()
235 msgq->used_msgs--; in z_impl_k_msgq_get()
238 pending_thread = z_unpend_first_thread(&msgq->wait_q); in z_impl_k_msgq_get()
240 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, get, msgq, timeout); in z_impl_k_msgq_get()
243 __ASSERT_NO_MSG(msgq->write_ptr >= msgq->buffer_start && in z_impl_k_msgq_get()
244 msgq->write_ptr < msgq->buffer_end); in z_impl_k_msgq_get()
245 (void)memcpy(msgq->write_ptr, (char *)pending_thread->base.swap_data, in z_impl_k_msgq_get()
246 msgq->msg_size); in z_impl_k_msgq_get()
247 msgq->write_ptr += msgq->msg_size; in z_impl_k_msgq_get()
248 if (msgq->write_ptr == msgq->buffer_end) { in z_impl_k_msgq_get()
249 msgq->write_ptr = msgq->buffer_start; in z_impl_k_msgq_get()
251 msgq->used_msgs++; in z_impl_k_msgq_get()
256 z_reschedule(&msgq->lock, key); in z_impl_k_msgq_get()
258 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, 0); in z_impl_k_msgq_get()
267 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, get, msgq, timeout); in z_impl_k_msgq_get()
272 result = z_pend_curr(&msgq->lock, key, &msgq->wait_q, timeout); in z_impl_k_msgq_get()
273 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, result); in z_impl_k_msgq_get()
277 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, result); in z_impl_k_msgq_get()
279 k_spin_unlock(&msgq->lock, key); in z_impl_k_msgq_get()
285 static inline int z_vrfy_k_msgq_get(struct k_msgq *msgq, void *data, in z_vrfy_k_msgq_get() argument
288 K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_get()
289 K_OOPS(K_SYSCALL_MEMORY_WRITE(data, msgq->msg_size)); in z_vrfy_k_msgq_get()
291 return z_impl_k_msgq_get(msgq, data, timeout); in z_vrfy_k_msgq_get()
296 int z_impl_k_msgq_peek(struct k_msgq *msgq, void *data) in z_impl_k_msgq_peek() argument
301 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_peek()
303 if (msgq->used_msgs > 0U) { in z_impl_k_msgq_peek()
305 (void)memcpy((char *)data, msgq->read_ptr, msgq->msg_size); in z_impl_k_msgq_peek()
312 SYS_PORT_TRACING_OBJ_FUNC(k_msgq, peek, msgq, result); in z_impl_k_msgq_peek()
314 k_spin_unlock(&msgq->lock, key); in z_impl_k_msgq_peek()
320 static inline int z_vrfy_k_msgq_peek(struct k_msgq *msgq, void *data) in z_vrfy_k_msgq_peek() argument
322 K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_peek()
323 K_OOPS(K_SYSCALL_MEMORY_WRITE(data, msgq->msg_size)); in z_vrfy_k_msgq_peek()
325 return z_impl_k_msgq_peek(msgq, data); in z_vrfy_k_msgq_peek()
330 int z_impl_k_msgq_peek_at(struct k_msgq *msgq, void *data, uint32_t idx) in z_impl_k_msgq_peek_at() argument
338 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_peek_at()
340 if (msgq->used_msgs > idx) { in z_impl_k_msgq_peek_at()
341 bytes_to_end = (msgq->buffer_end - msgq->read_ptr); in z_impl_k_msgq_peek_at()
342 byte_offset = idx * msgq->msg_size; in z_impl_k_msgq_peek_at()
343 start_addr = msgq->read_ptr; in z_impl_k_msgq_peek_at()
349 start_addr = msgq->buffer_start; in z_impl_k_msgq_peek_at()
351 (void)memcpy(data, start_addr + byte_offset, msgq->msg_size); in z_impl_k_msgq_peek_at()
358 SYS_PORT_TRACING_OBJ_FUNC(k_msgq, peek, msgq, result); in z_impl_k_msgq_peek_at()
360 k_spin_unlock(&msgq->lock, key); in z_impl_k_msgq_peek_at()
366 static inline int z_vrfy_k_msgq_peek_at(struct k_msgq *msgq, void *data, uint32_t idx) in z_vrfy_k_msgq_peek_at() argument
368 K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_peek_at()
369 K_OOPS(K_SYSCALL_MEMORY_WRITE(data, msgq->msg_size)); in z_vrfy_k_msgq_peek_at()
371 return z_impl_k_msgq_peek_at(msgq, data, idx); in z_vrfy_k_msgq_peek_at()
376 void z_impl_k_msgq_purge(struct k_msgq *msgq) in z_impl_k_msgq_purge() argument
381 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_purge()
383 SYS_PORT_TRACING_OBJ_FUNC(k_msgq, purge, msgq); in z_impl_k_msgq_purge()
386 for (pending_thread = z_unpend_first_thread(&msgq->wait_q); pending_thread != NULL; in z_impl_k_msgq_purge()
387 pending_thread = z_unpend_first_thread(&msgq->wait_q)) { in z_impl_k_msgq_purge()
392 msgq->used_msgs = 0; in z_impl_k_msgq_purge()
393 msgq->read_ptr = msgq->write_ptr; in z_impl_k_msgq_purge()
395 z_reschedule(&msgq->lock, key); in z_impl_k_msgq_purge()
399 static inline void z_vrfy_k_msgq_purge(struct k_msgq *msgq) in z_vrfy_k_msgq_purge() argument
401 K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_purge()
402 z_impl_k_msgq_purge(msgq); in z_vrfy_k_msgq_purge()
406 static inline uint32_t z_vrfy_k_msgq_num_free_get(struct k_msgq *msgq) in z_vrfy_k_msgq_num_free_get() argument
408 K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_num_free_get()
409 return z_impl_k_msgq_num_free_get(msgq); in z_vrfy_k_msgq_num_free_get()
413 static inline uint32_t z_vrfy_k_msgq_num_used_get(struct k_msgq *msgq) in z_vrfy_k_msgq_num_used_get() argument
415 K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ)); in z_vrfy_k_msgq_num_used_get()
416 return z_impl_k_msgq_num_used_get(msgq); in z_vrfy_k_msgq_num_used_get()
432 STRUCT_SECTION_FOREACH(k_msgq, msgq) { in init_msgq_obj_core_list()
433 k_obj_core_init_and_link(K_OBJ_CORE(msgq), &obj_type_msgq); in init_msgq_obj_core_list()