/** * @brief Get a message from the queue. */ osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec) { msg_t msg; osEvent event; event.def.message_id = queue_id; if (port_is_isr_context()) { /* Waiting makes no sense in ISRs so any value except "immediate" makes no sense.*/ if (millisec != 0) { event.status = osErrorValue; return event; } chSysLockFromISR(); msg = chMBFetchI((mailbox_t *)queue_id, (msg_t*)&event.value.v); chSysUnlockFromISR(); } else { msg = chMBFetch((mailbox_t *)queue_id, (msg_t*)&event.value.v, (systime_t)millisec); } /* Returned event type.*/ event.status = msg == MSG_OK ? osEventMessage : osEventTimeout; return event; }
/** * @brief Restores the specified execution status and leaves a critical zone. * @note A call to @p chSchRescheduleS() is automatically performed * if exiting the critical zone and if not in ISR context. * * @param[in] sts the system status to be restored. * * @xclass */ void chSysRestoreStatusX(syssts_t sts) { if (port_irq_enabled(sts)) { if (port_is_isr_context()) { chSysUnlockFromISR(); } else { chSchRescheduleS(); chSysUnlock(); } } }
/** * @brief Returns the execution status and enters a critical zone. * @details This functions enters into a critical zone and can be called * from any context. Because its flexibility it is less efficient * than @p chSysLock() which is preferable when the calling context * is known. * @post The system is in a critical zone. * * @return The previous system status, the encoding of this * status word is architecture-dependent and opaque. * * @xclass */ syssts_t chSysGetStatusAndLockX(void) { syssts_t sts = port_get_irq_status(); if (port_irq_enabled(sts)) { if (port_is_isr_context()) { chSysLockFromISR(); } else { chSysLock(); } } return sts; }
/** * @brief Put a message in the queue. */ osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec) { msg_t msg; if (port_is_isr_context()) { /* Waiting makes no sense in ISRs so any value except "immediate" makes no sense.*/ if (millisec != 0) return osErrorValue; chSysLockFromISR(); msg = chMBPostI((mailbox_t *)queue_id, (msg_t)info); chSysUnlockFromISR(); } else msg = chMBPost((mailbox_t *)queue_id, (msg_t)info, (systime_t)millisec); return msg == MSG_OK ? osOK : osEventTimeout; }