|
关于CMSIS_OS中osMessageGet()函数返回的问题
[复制链接]
本帖最后由 liutogo 于 2015-7-15 08:18 编辑
看CMSIS_os的代码,觉得有点问题
- /**
- * @brief Get a Message or Wait for a Message from a Queue.
- * @param queue_id message queue ID obtained with \ref osMessageCreate.
- * @param millisec timeout value or 0 in case of no time-out.
- * @retval event information that includes status code.
- * @note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
- */
- osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec)
- {
- portBASE_TYPE taskWoken;
- portTickType ticks;
- osEvent event;
-
- event.def.message_id = queue_id;
-
- if (queue_id == NULL) {
- event.status = osErrorParameter;
- return event;
- }
-
- taskWoken = pdFALSE;
-
- ticks = 0;
- if (millisec == osWaitForever) {
- ticks = portMAX_DELAY;
- }
- else if (millisec != 0) {
- ticks = millisec / portTICK_RATE_MS;
- if (ticks == 0) {
- ticks = 1;
- }
- }
-
- if (inHandlerMode()) {
- if (xQueueReceiveFromISR(queue_id, &event.value.v, &taskWoken) == pdTRUE) {
- /* We have mail */
- event.status = osEventMessage;
- }
- else {
- event.status = osOK;
- }
- portEND_SWITCHING_ISR(taskWoken);
- }
- else {
- if (xQueueReceive(queue_id, &event.value.v, ticks) == pdTRUE) {
- /* We have mail */
- event.status = osEventMessage;
- }
- else {
- event.status = (ticks == 0) ? osOK : osEventTimeout;
- }
- }
-
- return event;
- }
复制代码
osMessageGet()函数最终返回的是osEvent event结构体(定义如下)
- /// Event structure contains detailed information about an event.
- /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS.
- /// However the struct may be extended at the end.
- typedef struct {
- osStatus status; ///< status code: event or error information
- union {
- uint32_t v; ///< message as 32-bit value
- void *p; ///< message or mail as void pointer
- int32_t signals; ///< signal flags
- } value; ///< event value
- union {
- osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
- osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
- } def; ///< event definition
- } osEvent;
复制代码 问题是,osEvent event是作为局部变量在osMessageGet()中声明的,在osMessageGet()中获取消息队列中的消息并将消息填充到了event中,函数直接返回event让我很是不解。
这个返回应该是osEvent event结构体的指针吧,返回后osEvent event的生命周期应该已经结束了,这样返回有什么意义呢?
|
|