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 Jul 2025

xQueueReceiveFromISR

[Queue Management]

queue. h

1 BaseType_t xQueueReceiveFromISR
2 (
3 QueueHandle_t xQueue,
4 void *pvBuffer,
5 BaseType_t *pxHigherPriorityTaskWoken
6 );

Receive an item from a queue. It is safe to use this function from within an interrupt service routine.

Parameters:

  • xQueue

    The handle to the queue from which the item is to be received.

  • pvBuffer

    Pointer to the buffer into which the received item will be copied.

  • pxHigherPriorityTaskWoken

    A task may be blocked waiting for space to become available on the queue. If

    xQueueReceiveFromISR
    causes such a task to unblock
    *pxHigherPriorityTaskWoken
    will get set to
    pdTRUE
    , otherwise
    *pxHigherPriorityTaskWoken
    will remain unchanged. From FreeRTOS V7.3.0
    pxHigherPriorityTaskWoken
    is an optional parameter and can be set to NULL.

Returns:

  • pdPASS if an item was successfully received from the queue,
  • pdFAIL otherwise.

Example usage:

1QueueHandle_t xQueue;
2
3/* Function to create a queue and post some values. */
4void vAFunction( void *pvParameters )
5{
6 char cValueToPost;
7 const TickType_t xTicksToWait = ( TickType_t )0xff;
8
9 /* Create a queue capable of containing 10 characters. */
10 xQueue = xQueueCreate( 10, sizeof( char ) );
11 if( xQueue == 0 )
12 {
13 /* Failed to create the queue. */
14 }
15
16 /* ... */
17
18 /* Post some characters that will be used within an ISR. If the queue
19 is full then this task will block for xTicksToWait ticks. */
20 cValueToPost = 'a';
21 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
22 cValueToPost = 'b';
23 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
24
25 /* ... keep posting characters ... this task may block when the queue
26 becomes full. */
27
28 cValueToPost = 'c';
29 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
30}
31
32/* ISR that outputs all the characters received on the queue. */
33void vISR_Routine( void )
34{
35BaseType_t xTaskWokenByReceive = pdFALSE;
36char cRxedChar;
37
38 while( xQueueReceiveFromISR( xQueue,
39 ( void * ) &cRxedChar,
40 &xTaskWokenByReceive) )
41 {
42 /* A character was received. Output the character now. */
43 vOutputCharacter( cRxedChar );
44
45 /* If removing the character from the queue woke the task that was
46 posting onto the queue xTaskWokenByReceive will have been set to
47 pdTRUE. No matter how many times this loop iterates only one
48 task will be woken. */
49 }
50
51 if( xTaskWokenByReceive != pdFALSE )
52 {
53 /* We should switch context so the ISR returns to a different task.
54 NOTE: How this is done depends on the port you are using. Check
55 the documentation and examples for your port. */
56 taskYIELD ();
57 }
58}