MCPcopy Create free account
hub / github.com/ARMmbed/DAPLink / svcRtxMessageQueuePut

Function svcRtxMessageQueuePut

source/rtos2/RTX/Source/rtx_msgqueue.c:392–464  ·  view source on GitHub ↗

Put a Message into a Queue or timeout if Queue is full. \note API identical to osMessageQueuePut

Source from the content-addressed store, hash-verified

390/// Put a Message into a Queue or timeout if Queue is full.
391/// \note API identical to osMessageQueuePut
392static osStatus_t svcRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) {
393 os_message_queue_t *mq = osRtxMessageQueueId(mq_id);
394 os_message_t *msg;
395 os_thread_t *thread;
396 uint32_t *reg;
397 void *ptr;
398 osStatus_t status;
399
400 // Check parameters
401 if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL)) {
402 EvrRtxMessageQueueError(mq, (int32_t)osErrorParameter);
403 //lint -e{904} "Return statement before end of function" [MISRA Note 1]
404 return osErrorParameter;
405 }
406
407 // Check if Thread is waiting to receive a Message
408 if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessageGet)) {
409 EvrRtxMessageQueueInserted(mq, msg_ptr);
410 // Wakeup waiting Thread with highest Priority
411 thread = osRtxThreadListGet(osRtxObject(mq));
412 osRtxThreadWaitExit(thread, (uint32_t)osOK, TRUE);
413 // Copy Message (R2: void *msg_ptr, R3: uint8_t *msg_prio)
414 reg = osRtxThreadRegPtr(thread);
415 //lint -e{923} "cast from unsigned int to pointer"
416 ptr = (void *)reg[2];
417 memcpy(ptr, msg_ptr, mq->msg_size);
418 if (reg[3] != 0U) {
419 //lint -e{923} -e{9078} "cast from unsigned int to pointer"
420 *((uint8_t *)reg[3]) = msg_prio;
421 }
422 EvrRtxMessageQueueRetrieved(mq, ptr);
423 status = osOK;
424 } else {
425 // Try to allocate memory
426 //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
427 msg = osRtxMemoryPoolAlloc(&mq->mp_info);
428 if (msg != NULL) {
429 // Copy Message
430 memcpy(&msg[1], msg_ptr, mq->msg_size);
431 // Put Message into Queue
432 msg->id = osRtxIdMessage;
433 msg->flags = 0U;
434 msg->priority = msg_prio;
435 MessageQueuePut(mq, msg);
436 EvrRtxMessageQueueInserted(mq, msg_ptr);
437 status = osOK;
438 } else {
439 // No memory available
440 if (timeout != 0U) {
441 EvrRtxMessageQueuePutPending(mq, msg_ptr, timeout);
442 // Suspend current Thread
443 if (osRtxThreadWaitEnter(osRtxThreadWaitingMessagePut, timeout)) {
444 osRtxThreadListPut(osRtxObject(mq), osRtxThreadGetRunning());
445 // Save arguments (R2: const void *msg_ptr, R3: uint8_t msg_prio)
446 //lint -e{923} -e{9078} "cast from unsigned int to pointer"
447 reg = (uint32_t *)(__get_PSP());
448 //lint -e{923} -e{9078} "cast from pointer to unsigned int"
449 reg[2] = (uint32_t)msg_ptr;

Callers

nothing calls this directly

Calls 14

EvrRtxMessageQueueErrorFunction · 0.85
osRtxThreadListGetFunction · 0.85
osRtxThreadWaitExitFunction · 0.85
osRtxThreadRegPtrFunction · 0.85
osRtxMemoryPoolAllocFunction · 0.85
MessageQueuePutFunction · 0.85
osRtxThreadWaitEnterFunction · 0.85
osRtxThreadListPutFunction · 0.85

Tested by

no test coverage detected