void crQUEUE_RECEIVE(
xCoRoutineHandle xHandle,
xQueueHandle xQueue,
void *pvBuffer,
portTickType xTicksToWait,
portBASE_TYPE *pxResult
)
crQUEUE_RECEIVE is a macro. The data types are shown in the prototype above for reference only.
The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
equivalent to the xQueueSend() and xQueueReceive() functions used by tasks.
crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas
xQueueSend() and xQueueReceive() can only be used from tasks. Note that co-routines
can only send data to other co-routines. A co-routine cannot use a queue to send data to a
task or visa versa.
crQUEUE_RECEIVE can only be called from the co-routine function itself - not
from within a function called by the co-routine function. This is because
co-routines do not maintain their own stack.
See the co-routine section of the web documentation for information on
passing data between tasks and co-routines and between ISR's and
co-routines.
// A co-routine receives the number of an LED to flash from a queue. It
// blocks on the queue until the number is received.
static void prvCoRoutineFlashWorkTask( xCoRoutineHandle xHandle,
unsigned portBASE_TYPE uxIndex )
{
// Variables in co-routines must be declared static if they must maintain
// value across a blocking call.
static portBASE_TYPE xResult;
static unsigned portBASE_TYPE uxLEDToFlash;
// All co-routines must start with a call to crSTART().
crSTART( xHandle );
for( ;; )
{
// Wait for data to become available on the queue.
crQUEUE_RECEIVE( xHandle,
xCoRoutineQueue,
&uxLEDToFlash,
portMAX_DELAY,
&xResult );
if( xResult == pdPASS )
{
// We received the LED to flash - flash it!
vParTestToggleLED( uxLEDToFlash );
}
}
crEND();
}