Quality RTOS & Embedded Software

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



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;


    vTaskDelayUntil(&xLastExecutionTime, 300/portTICK_RATE_MS);
    vTaskDelayUntil(&xLastExecutionTime, T4s);


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 ??


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.



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



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()?


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

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

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