Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

xQueueReset

Posted by jalegre2003 on January 31, 2017

Hello,

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

Thanks in advance.


xQueueReset

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 ?


xQueueReset

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


xQueueReset

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?

Thanks.


xQueueReset

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 );
}

xQueueReset

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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner