Quality RTOS & Embedded Software

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




Loading

xQueueReceive return value

Posted by rrrum on June 27, 2015

After queue is created and then used to receive with Maximum delay parameter as in example bellow:

xStatus = xQueueReceive( xReceiveTestprocess, &evt, portMAX_DELAY);

if(xStatus == pdPASS ){ ... }

I would like to optimize code. Should return value always be tested for pdPASS before processing received data as shown in some examples? I mean xQueueReceive can ever return errQUEUE_EMPTY if maximum delay is specified? What do you recommend? Thanks


xQueueReceive return value

Posted by rtel on June 27, 2015

If you block indefinitely using portMAX_DELAY then you don't need to check the return value because, as you say, it will only return if data was received.

Although lots of examples use infinite block times for simplicity, it is not recommended to use infinite delays in real code is they offer no neat method of recovering from errors (for example if something had happened that meant data was never posted to your queue the task would carry on blocking indefinitely so you would need another task to check for the error condition).

Note portMAXDELAY is only an infinite block time if configINCLUDEvTaskSuspend is set to 1.

Regards.


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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