Quality RTOS & Embedded Software

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


vTaskSetTimeOutState and Task Execution

Posted by groger57 on October 24, 2017


I am presently using a task that waits for a binary semaphore "give" from the ISR. This works good. Now, I want to change that to a task that executes differently based on the existence of a response, or timeout, whicever occurs first.

1 - A command is transmitted 2 - A response (1 byte) should be received in 2000ms. If not, set the sequence as "incomplete"

I know that I will be using vTaskSetTimeOutState. My question is this. How does the task that uses vTaskSetTimeOutState know that it should start executing and subsequently using up the 2000ms timeout? Does the task get created like any other task, then suspended, and resumed just after transmitting the command?

Thanks for your help, always appreciated!

FYI: The current sempahore task:

static void prvCOMprocessTask( void pvParameters ) { configASSERT( xCOMsemaphore ); / Take semaphore to get it to correct state. */ xSemaphoreTake( xCOMsemaphore, mainDONT_BLOCK );

for( ;; )
xSemaphoreTake( xCOMsemaphore, portMAX_DELAY );
    /* do some stuff, I got a message.... */


vTaskSetTimeOutState and Task Execution

Posted by richard_damon on October 24, 2017

It sounds like what you want to do is rather than wait for portMAX_DELAY, you wait for your timeout period, and check the return value of xSemaphoreTake(). If it is success, they you got the message, if it is a timeout error, you didn't in the time period.

vTaskSetTimeOutState and Task Execution

Posted by groger57 on October 25, 2017

Ok, thanks! It makes sense...I will try it. Just one other question - is there any advantage/disadvantage between this, and using vTaskSetTimeOutState ?

vTaskSetTimeOutState and Task Execution

Posted by richard_damon on October 25, 2017

I would use vTaskSetTimeOutState if you need to abort a wait for some other reason than a timeout, but still want a 'failure'. Maybe something like the task is blocked on a queue waiting for a reply, but you get some sort of NAK or error instead, No need at that point to wait for the timeout, you can just tell the task no answer is comming.

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

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

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

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

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


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

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

Xilinx Microblaze and Zynq partner