Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Updated May 2025

crQUEUE_SEND_FROM_ISR

[Co-Routine Specific]

croutine.h

1BaseType_t crQUEUE_SEND_FROM_ISR
2 (
3 QueueHandle_t xQueue,
4 void *pvItemToQueue,
5 BaseType_t xCoRoutinePreviouslyWoken
6 )

crQUEUE_SEND_FROM_ISR()
is a macro. The data types are shown in the prototype above for reference only.

The macros

crQUEUE_SEND_FROM_ISR()
and
crQUEUE_RECEIVE_FROM_ISR()
are the co-routine equivalent to the
xQueueSendFromISR()
and
xQueueReceiveFromISR()
functions used by tasks.

crQUEUE_SEND_FROM_ISR()
and
crQUEUE_RECEIVE_FROM_ISR()
can only be used to pass data between a co-routine and and ISR, whereas
xQueueSendFromISR()
and
xQueueReceiveFromISR()
can only be used to pass data between a task and and ISR.

crQUEUE_SEND_FROM_ISR
can only be called from an ISR to send data to a queue that is being used from within a co-routine.

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.

Parameters:

  • xQueue

    The handle to the queue on which the item is to be posted.

  • pvItemToQueue

    A pointer to the item that is to be placed on the queue. The size of the items the queue will hold was defined when the queue was created, so this many bytes will be copied from

    pvItemToQueue
    into the queue storage area.

  • xCoRoutinePreviouslyWoken

    This is included so an ISR can post onto the same queue multiple times from a single interrupt. The first call should always pass in

    pdFALSE
    . Subsequent calls should pass in the value returned from the previous call.

Returns:

  • pdTRUE if a co-routine was woken by posting onto the queue. This is used by the ISR to determine if a context switch may be required following the ISR.

Example usage:

1// A co-routine that blocks on a queue waiting for characters to be received.
2static void vReceivingCoRoutine( CoRoutineHandle_t xHandle,
3 UBaseType_t uxIndex )
4{
5 char cRxedChar;
6 BaseType_t xResult;
7
8 // All co-routines must start with a call to crSTART().
9 crSTART( xHandle );
10
11 for( ;; )
12 {
13 // Wait for data to become available on the queue. This assumes the
14 // queue xCommsRxQueue has already been created!
15 crQUEUE_RECEIVE( xHandle,
16 xCommsRxQueue,
17 &uxLEDToFlash,
18 portMAX_DELAY,
19 &xResult );
20
21 // Was a character received?
22 if( xResult == pdPASS )
23 {
24 // Process the character here.
25 }
26 }
27
28 // All co-routines must end with a call to crEND().
29 crEND();
30}
31
32// An ISR that uses a queue to send characters received on a serial port to
33// a co-routine.
34void vUART_ISR( void )
35{
36 char cRxedChar;
37 BaseType_t xCRWokenByPost = pdFALSE;
38
39 // We loop around reading characters until there are none left in the UART.
40 while( UART_RX_REG_NOT_EMPTY() )
41 {
42 // Obtain the character from the UART.
43 cRxedChar = UART_RX_REG;
44
45 // Post the character onto a queue. xCRWokenByPost will be pdFALSE
46 // the first time around the loop. If the post causes a co-routine
47 // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE.
48 // In this manner we can ensure that if more than one co-routine is
49 // blocked on the queue only one is woken by this ISR no matter how
50 // many characters are posted to the queue.
51 xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue,
52 &cRxedChar,
53 xCRWokenByPost );
54 }
55}