Bug in vTaskDelayUntil()

abdull wrote on Thursday, May 23, 2019:

I have a task that keeps printing some characters in an infinite loop and I have implemented a delay before each printing iteration using vTaskDelayUntil, but for some reason the delay isn’t working properly.

this is how I specify the vTaskDelayUnti parameters.

portTickType wakeTime;
wakeTime = xTaskGetTickCount();

and this is what the task does (it only prints BYE infinitly)

void print(void* ptr)
{
    portTickType wakeTime;
    wakeTime = xTaskGetTickCount();
    while(1)
    {
        vTaskDelayUntil( &wakeTime, 3000 );
        printf("BYE\n");
    }
 }

This is how the task is created.

xTaskCreate(print, (const signed char*) "print", 1024, NULL, 3, &printH);

The screen shot below shows the output that I got. The characters do not follow the delay specified initially, and when it reaches the part where it looses the character E it starts to follow the delay specified.

Any idea for why the vTaskDelayUntil is not working in a propper way would be appreciated.

Regards,
abdul.

richarddamon wrote on Thursday, May 23, 2019:

First, the code as written can’t be exactly what you are using, as print has the wrong from for a task function, and thus the xTaskCreate should throw an error, task functions MUST have the prototype like:
void taskfun(void* ptr)
but your print takes no parameters.

A second note is that you don’t show the context of how you declare and initialize your wakeTime variable. I can’t think of any way to have those two lines as shown be next to each other and work, except as part of the task function, but they are shown outside of it apparently as some global statement. The decleration could be a global (and if not inside the task function it would need to be), but the assignment can not.

One possible source of your issue would be if the assignment occured well before the task started, in which case the define properties of vTaskDelayUntil is to not delay until the loop ‘caught up’ to the right number of loops. Typically, the initialization of the wakeup time variable (and the decleration of it) is just before the loop itsef, inside the task.

abdull wrote on Thursday, May 23, 2019:

I am sorry for the confusion I did, I have just updated the code that I provided.

portTickType wakeTime;

and

wakeTime = xTaskGetTickCount();

are actually initialized inside the task it self.

I have added the print task parameters as a void pointer, yet the code is resulting the same issues.

rtel wrote on Thursday, May 23, 2019:

How are you printing out the characters. In particular, is your
debugger set to use semihosting? If so that could be the problem. Try
with semihosting turned off. Also try removing the print statement
completely and instead just toggling an LED and measure the toggle
frequency to see if it is ok provided the print function is not called.

abdull wrote on Sunday, May 26, 2019:

abdull wrote on Sunday, May 26, 2019:

I am using a preprogrammed IDE, that was bought with the microprocessor we are working on and unfortunatly I can’t change toggle semihosting neither on or off.

I have also tried to toggle an LED with a delay of 5000 ticks, yet the toggle frequency is not ok.

I also want to add that a few days ago the taskDelayUntil() was working fine and I didn’t change any settings, all I did is turn off my laptop.

abdull wrote on Sunday, May 26, 2019:

I am using a preprogrammed IDE, that was bought with the microprocessor we are working on and unfortunatly I can’t change toggle semihosting neither on or off.

I have also tried to toggle an LED with a delay of 5000 ticks, yet the toggle frequency is not ok.

I also want to add that a few days ago the taskDelayUntil() was working fine and I didn’t change any settings, all I did is turn off my laptop.

abdull wrote on Sunday, May 26, 2019:

Sorry for all these posts, I keep pressing the post button many times thinking that the page is stuck, but it turns out that is just a delay.

heinbali01 wrote on Sunday, May 26, 2019:

Bug in vTaskDelayUntil()

It would be very unlikely that your “Hello World” program reveals a bug in a piece of software that has been successful for more than 15 years.

yet the toggle frequency is not ok

Can you tell exactly what you observe? Is it too slow, too fast, or irregular? How much too slow or fast? When does it become irregular?

Is your application only running a single task?

I am using a preprogrammed IDE, that was bought with the microprocessor

Can you tell what processor it is, and what kind of IDE?

abdull wrote on Sunday, May 26, 2019:

Can you tell exactly what you observe? Is it too slow, too fast, or irregular? How much too slow or fast? When does it become irregular?
well it starts very slow, but later on it goes into the expected delay period. The point where it changes and goes to the expected delay period is seen in the screen shot I provided (It is where a character gets missing).
Is your application only running a single task?
It is running a single task with the priority of 3 and a stack depth of 1024.
Can you tell what processor it is, and what kind of IDE?
processor is: ARM9 (AT91SAM9G20)
IDE: Eclipse Kepler Service Release 2
OS: freeRTOS v7.5.3

abdull wrote on Sunday, May 26, 2019:

Fixed the quotation mess that I did. And sorry I am still new to this forum.

Can you tell exactly what you observe? Is it too slow, too fast, or irregular? How much too slow or fast? When does it become irregular?

well it starts very slow, but later on it goes into the expected delay period. The point where it changes and goes to the expected delay period is seen in the screen shot I provided (It is where a character gets missing).

Is your application only running a single task?

It is running a single task with the priority of 3 and a stack depth of 1024.

Can you tell what processor it is, and what kind of IDE?

processor is: ARM9 (AT91SAM9G20)
IDE: Eclipse Kepler Service Release 2
OS: freeRTOS v7.5.3

rtel wrote on Sunday, May 26, 2019:

Did you reply to this post?
https://sourceforge.net/p/freertos/discussion/382005/thread/475380f75b/#9ed5/f622/5984
?

abdull wrote on Monday, May 27, 2019:

Yes I did.
https://sourceforge.net/p/freertos/discussion/382005/thread/475380f75b/#9ed5/f622/5984/e7a1

heinbali01 wrote on Monday, May 27, 2019:

DE: Eclipse Kepler Service Release 2
and unfortunately I can’t change toggle semihosting neither on or off.

I never use semi-hosting and like Richard said, it is famous for slowing down the processing.

Inside your main(), there will also be some code related to semihosting.
Within Eclipse, there will be some option in the Debug tab.

You can read about semihosting here

Debugging/logging: many boards also have a serial port, which can be connected to your laptop with a serial_to_USB connection (CDC).

OS: freeRTOS v7.5.3

That is very old. You can download the latest source code here
Or here if you prefer github.