Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training



Posted by jalegre2003 on January 31, 2017


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

Thanks in advance.


Posted by heinbali01 on 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 ?


Posted by rtel on 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: http://www.freertos.org/xTimerPendFunctionCallFromISR.html


Posted by jalegre2003 on 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 RECEIVEUARTCHAR 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?



Posted by rtel on 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 );


Posted by jalegre2003 on February 1, 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.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists