Updated Jul 2025
xQueueReceiveFromISR
queue. h
1 BaseType_t xQueueReceiveFromISR2 (3 QueueHandle_t xQueue,4 void *pvBuffer,5 BaseType_t *pxHigherPriorityTaskWoken6 );
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
causes such a task to unblockxQueueReceiveFromISRwill get set to*pxHigherPriorityTaskWoken, otherwisepdTRUEwill remain unchanged. From FreeRTOS V7.3.0*pxHigherPriorityTaskWokenis an optional parameter and can be set to NULL.pxHigherPriorityTaskWoken
Returns:
- pdPASS if an item was successfully received from the queue,
- pdFAIL otherwise.
Example usage:
1QueueHandle_t xQueue;23/* 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;89 /* 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 }1516 /* ... */1718 /* Post some characters that will be used within an ISR. If the queue19 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 );2425 /* ... keep posting characters ... this task may block when the queue26 becomes full. */2728 cValueToPost = 'c';29 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );30}3132/* ISR that outputs all the characters received on the queue. */33void vISR_Routine( void )34{35BaseType_t xTaskWokenByReceive = pdFALSE;36char cRxedChar;3738 while( xQueueReceiveFromISR( xQueue,39 ( void * ) &cRxedChar,40 &xTaskWokenByReceive) )41 {42 /* A character was received. Output the character now. */43 vOutputCharacter( cRxedChar );4445 /* If removing the character from the queue woke the task that was46 posting onto the queue xTaskWokenByReceive will have been set to47 pdTRUE. No matter how many times this loop iterates only one48 task will be woken. */49 }5051 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. Check55 the documentation and examples for your port. */56 taskYIELD ();57 }58}