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
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.
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/portTICK_RATE_MS).
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/portTICK_RATE_MS).The response time of vTestTask (End Time- Start Time) is 3seconde+300ms+ few microsecondes. which is not what expected.
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()?