Lines Matching +full:tx +full:- +full:buffer +full:- +full:descriptors
4 * SPDX-License-Identifier: Apache-2.0
36 /* stack of unused asynchronous message descriptors */
52 * Do run-time initialization of mailbox object subsystem.
56 /* array of asynchronous message descriptors */ in init_mbox_module()
60 * Create pool of asynchronous message descriptors. in init_mbox_module()
89 z_waitq_init(&mbox->tx_msg_queue); in k_mbox_init()
90 z_waitq_init(&mbox->rx_msg_queue); in k_mbox_init()
91 mbox->lock = (struct k_spinlock) {}; in k_mbox_init()
101 * @brief Check compatibility of sender's and receiver's message descriptors.
103 * Compares sender's and receiver's message descriptors to see if they are
110 * @return 0 if successfully matched, otherwise -1.
117 if (((tx_msg->tx_target_thread == (k_tid_t)K_ANY) || in mbox_message_match()
118 (tx_msg->tx_target_thread == rx_msg->tx_target_thread)) && in mbox_message_match()
119 ((rx_msg->rx_source_thread == (k_tid_t)K_ANY) || in mbox_message_match()
120 (rx_msg->rx_source_thread == tx_msg->rx_source_thread))) { in mbox_message_match()
122 /* update thread identifier fields for both descriptors */ in mbox_message_match()
123 rx_msg->rx_source_thread = tx_msg->rx_source_thread; in mbox_message_match()
124 tx_msg->tx_target_thread = rx_msg->tx_target_thread; in mbox_message_match()
126 /* update application info fields for both descriptors */ in mbox_message_match()
127 temp_info = rx_msg->info; in mbox_message_match()
128 rx_msg->info = tx_msg->info; in mbox_message_match()
129 tx_msg->info = temp_info; in mbox_message_match()
132 if (rx_msg->size > tx_msg->size) { in mbox_message_match()
133 rx_msg->size = tx_msg->size; in mbox_message_match()
137 rx_msg->tx_data = tx_msg->tx_data; in mbox_message_match()
140 rx_msg->_syncing_thread = tx_msg->_syncing_thread; in mbox_message_match()
145 return -1; in mbox_message_match()
161 if (rx_msg->_syncing_thread == NULL) { in mbox_message_dispose()
166 sending_thread = rx_msg->_syncing_thread; in mbox_message_dispose()
167 rx_msg->_syncing_thread = NULL; in mbox_message_dispose()
168 tx_msg = (struct k_mbox_msg *)sending_thread->base.swap_data; in mbox_message_dispose()
171 tx_msg->size = rx_msg->size; in mbox_message_dispose()
178 if ((sending_thread->base.thread_state & _THREAD_DUMMY) != 0U) { in mbox_message_dispose()
179 struct k_sem *async_sem = tx_msg->_async_sem; in mbox_message_dispose()
208 * @return 0 if successful, -ENOMSG if failed immediately, -EAGAIN if timed out
219 tx_msg->rx_source_thread = arch_current_thread(); in mbox_message_put()
222 sending_thread = tx_msg->_syncing_thread; in mbox_message_put()
223 sending_thread->base.swap_data = tx_msg; in mbox_message_put()
226 key = k_spin_lock(&mbox->lock); in mbox_message_put()
230 _WAIT_Q_FOR_EACH(&mbox->rx_msg_queue, receiving_thread) { in mbox_message_put()
231 rx_msg = (struct k_mbox_msg *)receiving_thread->base.swap_data; in mbox_message_put()
249 if ((sending_thread->base.thread_state & _THREAD_DUMMY) in mbox_message_put()
251 z_reschedule(&mbox->lock, key); in mbox_message_put()
261 int ret = z_pend_curr(&mbox->lock, key, NULL, K_FOREVER); in mbox_message_put()
271 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, message_put, mbox, timeout, -ENOMSG); in mbox_message_put()
273 k_spin_unlock(&mbox->lock, key); in mbox_message_put()
274 return -ENOMSG; in mbox_message_put()
278 /* asynchronous send: dummy thread waits on tx queue for receiver */ in mbox_message_put()
279 if ((sending_thread->base.thread_state & _THREAD_DUMMY) != 0U) { in mbox_message_put()
280 z_pend_thread(sending_thread, &mbox->tx_msg_queue, K_FOREVER); in mbox_message_put()
281 k_spin_unlock(&mbox->lock, key); in mbox_message_put()
287 /* synchronous send: sender waits on tx queue for receiver or timeout */ in mbox_message_put()
288 int ret = z_pend_curr(&mbox->lock, key, &mbox->tx_msg_queue, timeout); in mbox_message_put()
299 tx_msg->_syncing_thread = arch_current_thread(); in k_mbox_put()
324 async->thread.prio = arch_current_thread()->base.prio; in k_mbox_async_put()
326 async->tx_msg = *tx_msg; in k_mbox_async_put()
327 async->tx_msg._syncing_thread = (struct k_thread *)&async->thread; in k_mbox_async_put()
328 async->tx_msg._async_sem = sem; in k_mbox_async_put()
330 (void)mbox_message_put(mbox, &async->tx_msg, K_FOREVER); in k_mbox_async_put()
335 void k_mbox_data_get(struct k_mbox_msg *rx_msg, void *buffer) in k_mbox_data_get() argument
338 if (buffer == NULL) { in k_mbox_data_get()
339 rx_msg->size = 0; in k_mbox_data_get()
344 /* copy message data to buffer, then dispose of message */ in k_mbox_data_get()
345 if ((rx_msg->tx_data != NULL) && (rx_msg->size > 0U)) { in k_mbox_data_get()
346 (void)memcpy(buffer, rx_msg->tx_data, rx_msg->size); in k_mbox_data_get()
358 * 1) The receiver requested immediate retrieval by supplying a buffer
363 * @param buffer Pointer to buffer to receive data.
367 static int mbox_message_data_check(struct k_mbox_msg *rx_msg, void *buffer) in mbox_message_data_check() argument
369 if (buffer != NULL) { in mbox_message_data_check()
371 k_mbox_data_get(rx_msg, buffer); in mbox_message_data_check()
372 } else if (rx_msg->size == 0U) { in mbox_message_data_check()
382 int k_mbox_get(struct k_mbox *mbox, struct k_mbox_msg *rx_msg, void *buffer, in k_mbox_get() argument
391 rx_msg->tx_target_thread = arch_current_thread(); in k_mbox_get()
393 /* search mailbox's tx queue for a compatible sender */ in k_mbox_get()
394 key = k_spin_lock(&mbox->lock); in k_mbox_get()
398 _WAIT_Q_FOR_EACH(&mbox->tx_msg_queue, sending_thread) { in k_mbox_get()
399 tx_msg = (struct k_mbox_msg *)sending_thread->base.swap_data; in k_mbox_get()
402 /* take sender out of mailbox's tx queue */ in k_mbox_get()
405 k_spin_unlock(&mbox->lock, key); in k_mbox_get()
408 result = mbox_message_data_check(rx_msg, buffer); in k_mbox_get()
418 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, get, mbox, timeout, -ENOMSG); in k_mbox_get()
421 k_spin_unlock(&mbox->lock, key); in k_mbox_get()
422 return -ENOMSG; in k_mbox_get()
428 arch_current_thread()->base.swap_data = rx_msg; in k_mbox_get()
429 result = z_pend_curr(&mbox->lock, key, &mbox->rx_msg_queue, timeout); in k_mbox_get()
433 result = mbox_message_data_check(rx_msg, buffer); in k_mbox_get()