richard_damon wrote on Monday, June 13, 2011:
No, not directly. If you think about it, how would FreeRTOS know when the time expired?
There are a couple of ways to generate short waits:
1) If it is really shorts, just enter a short spin wait loop, (just make sure your complier doesn’t optimize it out)
2) For longer delays, but needing better than 1 tick accuracy, set up a high speed one shot timer (if your processor has one), and program it to interrupt in the given time delay. Program the interrupt to give a semaphore. To delay, fire off the delay and wait for the semaphore.
Note that I say “1 tick accuracy” as the built-in FreeRTOS delay has that level of inaccuracy. If you ask for a 1 tick delay at a 1 ms tick, you will get somewhere between 0ms and 1ms, if you ask for a 2 tick delay, you will get a delay between 1ms and 2ms. The low end of the range happens if you are at the end of a tick, and just after you call the delay function the tick occurs. Delays of course can also b extended if other tasks at your priority or higher become ready during the delay, as the delay just affect when this task is eligible to get CPU time, not when it will (unless it is the highest priority task)