Quality RTOS & Embedded Software

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


vTaskDelayUntil + vTaskSuspend

Posted by totti001 on April 8, 2014

Hello everybody!

I have problem with task control. I have 2 task:

    xLastWakeTime = xTaskGetTickCount();
        //do something
        vTaskDelayUntil( &xLastWakeTime, 30000);

task2 { xLastWakeTime = xTaskGetTickCount(); while(1) { if(buttonpressed) { if(stopmode) { vTaskSuspend(task1); Entersleepmode(); } else { vTaskResume(task1); } button_pressed = false; } vTaskDelayUntil( &xLastWakeTime, 10); } }

ISR(button) { button_pressed = 1; }

So the program running 2 task. The task2 is a power task, this checked a power button to switch on or switch off the device. In the sleeping state, the device wake up at every 25 seconds to send a message, then go back sleep. The task2 do this, so this is running always. But the task1 running only when the device is in switch on state. So in task2 I suspend and resume task1. But what I see, that if I switch on the device after sleeping, the task1 is running always, not every 30 seconds. I check xLastWakeTime and this is a big number e.g. 612000 and the tick number is 25000. What is the problem? If I not use suspend and resume, everything is ok.

vTaskDelayUntil + vTaskSuspend

Posted by rtel on April 8, 2014

All the usual questions:

  1. Which chip are you using?
  2. Are you running a recent version of FreeRTOS with configASSERT() defined (the later versions have extra asserts to help catch common errors?
  3. Are you interrupts being defined in accordance with the documentation for your port
  4. Have you read the FAQ item "My application does not run, what could be wrong
  5. Have you read the FAQ item that requests you post this information in your first port?
  6. etc.

When you are in sleep mode, does the tick keep incrementing, or is it halted?

xLastWakeTime expects the tick to increment at a steady rate, and for the task to unblock when the tick reaches xLastWakeTime + [the period time]. I would have to look at the code to see what happens when the task is unsuspended if it was suspended when its expected block time was reached (and so is passed when the task actually next runs).


vTaskDelayUntil + vTaskSuspend

Posted by totti001 on April 8, 2014

1, Stm32f407vg 2, I running 7.6.0 3, Interrupts is running well

The sleep mode is stop mode, so everything is stopped, only external it wake up the micro. Van the micro wake up the tick is incrementing, and task2 running well. Task2 send a message or check the button state than go back stop mode. Tomorrow I upload the code of this.

vTaskDelayUntil + vTaskSuspend

Posted by davedoors on April 9, 2014

if the tick carried counting when the task was suspended then following calls to vTaskDelayUntil() would return immediately until the xLastWakeTime parameter had caught up with the tick. In your case you are stopping everything and I don't know what will happen, you may find you get all kinds of race conditions, but FreeRTOS has a built in way of doing what you are trying to do manually. Look at the two links below http://www.freertos.org/low-power-tickless-rtos.html http://www.freertos.org/low-power-ARM-cortex-rtos.html

vTaskDelayUntil + vTaskSuspend

Posted by totti001 on April 9, 2014

Here is the 3 files from project. Task 1 is in the main.c task2 in the power_api.c


Power_api.c (19409 bytes)
RTOS_api.c (13833 bytes)
main.c (1989 bytes)

vTaskDelayUntil + vTaskSuspend

Posted by rtel on April 9, 2014

I'm not going to spend lots of time looking at your source code because at first glance I see the following line:


which is an error, and had you spent the time to follow up on the information people have already spent the time to provide you you would have known that, and your application would have asserted to inform you of the same.

I have not looked past that so don't know what other errors may exist.


vTaskDelayUntil + vTaskSuspend

Posted by totti001 on April 9, 2014

I'm testing the code, and the problem is appear when the system tick not reach the next task1 wakeup tickcount. So if I send sleep the task at tickcount 215000, and the task call vtaskdelayuntil at 210000 with a 30000 wait time, sot next run at 240000. IF the tick count is between 21000 and 240000 and I wake up the resume the task, the lastwaketime value is wrong, and the task run fast. If the tickcount reach 240000 and wake up the task everything is ok.

Phase2: The problem found: So if a task called vtaskuntildelay, next call tasksuspend and taskresume in the delay time, the task will be running after the resume, not wait for the delay. Then call the vTaskDelayUntil and check the laswaketime higher than actual tickcount, the function do nothing, so the delay has no effect, and the task running always bacause the lastwaketime always higher than systickcount.

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

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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.

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