FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2014 Threads] vtaskDelayuntill Posted by chaabanemalki on August 14, 2014 Hello,
I have this simple 2 tasks
~~~~~~~~~~
void vTestTask (void *pvParameter)
{
portTickType xLastExecutionTime;
xLastExecutionTime = xTaskGetTickCount();
char x = 5;
for(;;)
{
xSemaphoreTake(SwitchTaskSemaphore,portMAX_DELAY);
vTaskDelayUntil(&xLastExecutionTime, 300/portTICK_RATE_MS);
x++;
x+=x;
vTaskDelayUntil(&xLastExecutionTime, T4s);
x++;
x+=x;
xSemaphoreGive(SwitchTaskSemaphore1);
}
}
void vOneSecTask(void *pvParameter)
{
portTickType xLastExecutionTime;
xLastExecutionTime = xTaskGetTickCount();
char x;
xSemaphoreTake(SwitchTaskSemaphore,0);
xSemaphoreTake(SwitchTaskSemaphore1,0);
for(;;)
{
vTaskDelayUntil(&xLastExecutionTime, DelayTime);
xSemaphoreGive(SwitchTaskSemaphore);
xSemaphoreTake(SwitchTaskSemaphore1,portMAX_DELAY);
x++;
}
}
~~~~~~~~~~
I'm using FreeRTOS+Trace to visualize what happends in the code
when DelayTime to zero. vTestTask works just fine and I can see in FreeRTOS+Trace that the response time for vTestTask is around 4s 300ms
If I change DelayTime to 1 seconde the response time for vTestTask becomes ~3s 300ms
If I change DelayTime to 2 seconde the response time for vTestTask becomes ~2s 300ms
I'm not sure what I'm missing here, Any ideas ??
vtaskDelayuntill Posted by rtel on August 14, 2014 It is not clear to me what your code is supposed to be doing, or what it is not doing that you expect it to.
Please state how you expect the code to behave, how the behaviour deviates from your expectation - along with the priority at which the two tasks are created, the function used to create the semaphore, the value of T4s, and what x is doing.
Regards.
vtaskDelayuntill Posted by chaabanemalki on August 14, 2014 Okey, I forget to add all the details
I have simplified the code to do tests with basic things an show it here too.
The code is suppose to reset a device : pull down a device's pin during 300ms, pull it up and then wait for T4s = 4 secondes ( #define T4s 4000/portTICKRATEMS).
To do that, vOneSecTask wish has priority of 2, gives SwitchTaskSemaphore and vTestTask (priority 1) should take it and pull down a pin, wait for 300ms and then pull the pin back, and wait for 4 secondes, in the end vTestTask gives back SwitchTaskSemaphore1 to vOneSecTask indicating that the reset sequence has ended.
x is just something i put to add debug breakpoints.
and I use vSemaphoreCreateBinary to create the 2 semaphores.
When running this without any delay in vOneSecTask (DelayTime = 0).The response time of vTestTask (End Time- Start Time) is exactly as expected 4seconde+300ms+ few microsecondes
When running this with delay in vOneSecTask (DelayTime = 1000/portTICKRATEMS).The response time of vTestTask (End Time- Start Time) is 3seconde+300ms+ few microsecondes. which is not what expected.
hope this cleared things
Regards
vtaskDelayuntill Posted by davedoors on August 14, 2014 I'm still confused. If you use vTaskDelay() in vTestTask() then it will wait 300ms between receiving the semaphore and x++, which I think is what you want. But you are using vTaskDelayUntil() so it will wait 300ms from the last call to vTaskDelayUntil(), not from when it receives the semaphore. The longer vOneSecTask() delays before giving the semaphore the shorter this time will be, which is what you are reporting. Does it do what you expect if you change vTaskDelayUntil() to vTaskDelay()?
vtaskDelayuntill Posted by chaabanemalki on August 14, 2014 Okey, I miss understand how vTaskDelayUntil() work.
Now everything works just fine.
Thank you very much, it's always helpful to come here
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|