Get a Message from Queue with Highest Priority. \param[in] mq message queue object. \return message object or NULL.
| 88 | /// \param[in] mq message queue object. |
| 89 | /// \return message object or NULL. |
| 90 | static os_message_t *MessageQueueGet (os_message_queue_t *mq) { |
| 91 | #if (EXCLUSIVE_ACCESS == 0) |
| 92 | uint32_t primask = __get_PRIMASK(); |
| 93 | #endif |
| 94 | os_message_t *msg; |
| 95 | uint32_t count; |
| 96 | uint8_t flags; |
| 97 | |
| 98 | #if (EXCLUSIVE_ACCESS == 0) |
| 99 | __disable_irq(); |
| 100 | |
| 101 | count = mq->msg_count; |
| 102 | if (count != 0U) { |
| 103 | mq->msg_count--; |
| 104 | } |
| 105 | |
| 106 | if (primask == 0U) { |
| 107 | __enable_irq(); |
| 108 | } |
| 109 | #else |
| 110 | count = atomic_dec32_nz(&mq->msg_count); |
| 111 | #endif |
| 112 | |
| 113 | if (count != 0U) { |
| 114 | msg = mq->msg_first; |
| 115 | |
| 116 | while (msg != NULL) { |
| 117 | #if (EXCLUSIVE_ACCESS == 0) |
| 118 | __disable_irq(); |
| 119 | |
| 120 | flags = msg->flags; |
| 121 | msg->flags = 1U; |
| 122 | |
| 123 | if (primask == 0U) { |
| 124 | __enable_irq(); |
| 125 | } |
| 126 | #else |
| 127 | flags = atomic_wr8(&msg->flags, 1U); |
| 128 | #endif |
| 129 | if (flags == 0U) { |
| 130 | break; |
| 131 | } |
| 132 | msg = msg->next; |
| 133 | } |
| 134 | } else { |
| 135 | msg = NULL; |
| 136 | } |
| 137 | |
| 138 | return msg; |
| 139 | } |
| 140 | |
| 141 | /// Remove a Message from Queue |
| 142 | /// \param[in] mq message queue object. |
no test coverage detected