jalegre2003 wrote on Tuesday, January 31, 2017:


Can xQueueReset be used from within an ISR?
If not, which function should be used?

Thanks in advance.

heinbali01 wrote on Tuesday, January 31, 2017:

As you might have guessed, xQueueReset() doesn’t end with fromISR and it is not supposed to be called from an ISR.

I wouldn’t know a good reason to reset a queue from within an ISR.
All I ever do with a queue from within an interrupt is post a message, give to a semaphore, and always using the fromISR functions.

Can you explain why you would want to reset a queue ?

rtel wrote on Tuesday, January 31, 2017:

Only functions that end if FromISR can be used in an ISR.

If you want to reset a queue from an interrupt then one option would be
to create a function that wraps the xQueueReset() API, and pend the
function from the ISR. Be aware that the queue won’t actually get reset
until the ISR has exited though:

jalegre2003 wrote on Tuesday, January 31, 2017:

I’m making a kind of simple SPI <–> UART bridge.
Through SPI commands I am able to configure, write, read… the UART ports.

For example, I use a queue to hold the bytes received from the UART side.
In the SPI side, when a RECEIVE_UART_CHAR command is received, the SPI ISR takes one character out of that queue and resends it through SPI.

One of the possible commands is CLEAR_BUFFER, which, as expected, should empty/reset that queue.
A xQueueResetFromISR would perfectly do the work.

Any ideas?


rtel wrote on Tuesday, January 31, 2017:

Something like the following should work, but note this is completely
untested, not even compiled.

BaseType_t xQueueResetFromISR( QueueHandle_t xQueue )
Queue_t * const pxQueue = ( Queue_t * ) xQueue;
UBaseType_t uxSavedInterruptStatus;

     configASSERT( pxQueue );

     uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
         pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * 
pxQueue->uxItemSize );
         pxQueue->uxMessagesWaiting = ( UBaseType_t ) 0U;
         pxQueue->pcWriteTo = pxQueue->pcHead;
         pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength 
- ( UBaseType_t ) 1U ) * pxQueue->uxItemSize );
         pxQueue->cRxLock = queueUNLOCKED;
         pxQueue->cTxLock = queueUNLOCKED;
         vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
         vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
     portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );

jalegre2003 wrote on Wednesday, February 01, 2017:

Thanks a lot!
I’ve tried that code and it compiles ok. It also seems that it works ok but, anyway, I’m going to use the pending mechanism option because I think it’s, for now, a safer option, until Real Time Engineers decide to release (I hope so) such a feature (xQueueResetFromISR).

Again, thanks for the provided solutions.