Quality RTOS & Embedded Software

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


Loading

Biasing task start times with vTaskDelayUntil

Posted by Richard on October 19, 2005
[moved from bug report to support forum]

Hello,

I'm trying to bias or stagger task start times using
xLastWakeTime as in the examples for vTaskDelayUntil().

For example,

task1() does something like:

xLastWakeTime = xTaskGetTickCount();

for (EVER)
{

// Wait for the next cycle.
vTaskDelayUntil( &xLastWakeTime, xFrequency );
...

which is fine - it's my understanding since the tasks
are created before the scheduler starts - that
xLastWakeTime will be 0.

task2() does this:

xLastWakeTime = (xTaskGetTickCount() +
((portTickType)15 / portTICK_RATE_MS ));

for (EVER)
{

vTaskDelayUntil( &xLastWakeTime, xFrequency );


....

In this case - I'd expect task2() to run 15 ms after
task1 -
but at the same rate since xFrequency is the same in
both examples. Also - portTICK_RATE_MS = 1 since the
system
is running with a 1KHz tick rate.

What I'm seeing is that task2() is running much more
frequently than task1 - in some instances almost 15 times
more frequently. I don't understand why this is happening.

Thanks In Advance for your help,

RE: Biasing task start times with vTaskDelayUntil

Posted by Richard on October 19, 2005
I think the scenario is likely to be as follows:

For task 1 the first start time is 0.
For task 2 the second start time is 15.

Now if the scheduler started instantaniously task 2 would start 15 ticks after task 1, provided task 1 had either completed and blocked, or task 2 had priority higher than task 1.

However, the scheduler does not start instantly, and other code will first execute. If more than 15 ticks has gone by the start time for task 2 will have expired before it makes its first call to vTaskDelayUnilt(). As the time it wants to start is in the past it will execute immediately. It may therefore execute immediately following task 1 - or even before task 1 depending on their relative priorities and creation order.

I cannot explain yet while one task would run more frequently than the others. Can you provide a more full example of code exhibiting this problem? Is there any conflict between the various xLastWakeTime variables being used?

I have sent you a suggestion for how the desired task staggering might be accomplished.

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.0.1 is available for immediate download. Now MIT licensed.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

New FAQ page about the FreeRTOS kernel and Amazon FreeRTOS.


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

Xilinx Microblaze and Zynq partner