已更新 2025年7月
crQUEUE_RECEIVE
[协程专用]
croutine.h
1void crQUEUE_RECEIVE(2 CoRoutineHandle_t xHandle,3 QueueHandle_t xQueue,4 void *pvBuffer,5 TickType_t xTicksToWait,6 BaseType_t *pxResult7 )
crQUEUE_RECEIVE
crQUEUE_SEND()
crQUEUE_RECEIVE()
xQueueSend()
xQueueReceive()
crQUEUE_SEND
crQUEUE_RECEIVE
xQueueSend()
xQueueReceive()
crQUEUE_RECEIVE
请参阅在线文档中的协程部分, 了解有关在任务与协程之间以及 ISR 与 协程之间传递数据的信息。
参数:
-
xHandle
调用协程的句柄。这是协程函数的
参数。xHandle -
xQueue
要接收数据的队列的句柄。使用
API 函数创建队列时,该句柄作为返回值获得。xQueueCreate() -
pvBuffer
将接收到的项目复制到其中的缓冲区。每个排队项的字节数 是在创建队列时指定的。此字节数已复制到
。pvBuffer -
xTickToDelay
在无立即可用数据的情况下, 协程处于阻塞状态以等待队列中可用数据时的滴答 数。此滴答数可以转换为实际时间,实际时间 由
(在 FreeRTOSConfig.h 中设置)定义。常量configTICK_RATE_HZ可用于 将滴答数转换为毫秒(请参阅portTICK_PERIOD_MS示例)。crQUEUE_SEND -
pxResult
如果从队列中成功检索到数据,则 pxResult 指向的变量将设置为
, 否则设置为 ProjDefs.h 中定义的错误代码。pdPASS
用法示例:
1// A co-routine receives the number of an LED to flash from a queue. It2// blocks on the queue until the number is received.3static void prvCoRoutineFlashWorkTask( CoRoutineHandle_t xHandle,4 UBaseType_t uxIndex )5{6 // Variables in co-routines must be declared static if they must maintain7 // value across a blocking call.8 static BaseType_t xResult;9 static UBaseType_t uxLEDToFlash;1011 // All co-routines must start with a call to crSTART().12 crSTART( xHandle );1314 for( ;; )15 {16 // Wait for data to become available on the queue.17 crQUEUE_RECEIVE( xHandle,18 xCoRoutineQueue,19 &uxLEDToFlash,20 portMAX_DELAY,21 &xResult );2223 if( xResult == pdPASS )24 {25 // We received the LED to flash - flash it!26 vParTestToggleLED( uxLEDToFlash );27 }28 }2930 crEND();31}