Embedded Freaks..

February 19, 2009

Programming Timeout under FreeRTOS

Filed under: programming-tips — Tags: — kunilkuda @ 11:23 am

It seems like the FreeRTOS has some support to program a timeout, but unpublished anywhere. I’ve checked the FreeRTOS source code, regarding the usage, and it seems like it’s quite safe to use it under user’s application.

Here’s what I’ve found:

xTimeOutType x_timeout; //< Var to hold the current time
portTickType openTimeout; //< Var to hold the timeout

// Set the initial time, where timeout will be started
vTaskSetTimeOutState(&x_timeout);
// Set the timeout value
openTimeout = 512; //< In RTOS tick

// To check the timeout
if(xTaskCheckForTimeOut(&x_timeout, &openTimeout) == pdTRUE)
{
  // It’s timeout
} else {
  // It’s not timeout yet.
}

You can also combined the technique with do-while loop (see my previous post).

1 Comment »

  1. As far as I can see, vTaskSetTimeOutState is not safe on a 16 bits systems if 32 bits ticks are used, unless interrupts are disabled first.

    Comment by Samuel Tardieu — April 5, 2009 @ 6:52 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.