Quality RTOS & Embedded Software

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




Loading

Strategy to implement a periodic task.

Posted by simointe on March 6, 2017

Setup: FreeRTOS version is V9.0.0 (comes from here, download link at file menu), port TMS570.

My current implementation uses wait on notification and timeout value on this notification to be able to react on different events along have a periodic execution in case of no event. BaseTypet xResult = xTaskNotifyWait( pdFALSE, // Don't clear bits on entry. ULONGMAX, // Clear all bits on exit. &ulNotifiedValue, // Stores the notified value. nbTick ); The problem is that this design don't take into accompt the time to execute the thread itself. For instance, if it takes 200us to run my periodic thread of 1Khz, the resulting frequency will be around 800Hz instead of 1Khz. A solution could be to use auto-reload timer to notify the task to run, which is in fact to use default timer task to notify my thread. Is there another solution to make the thread more stand alone than using timer ?


Strategy to implement a periodic task.

Posted by rtel on March 6, 2017

Am I right in interpreting this to mean you want to perform periodic processing, and handle events in between each processing cycle?

There are two things that might work:

1) Use vTaskDelayUntil() to get a fixed period, then use xTaskAbortDelay() to unblock the task when an event needs processing.

2) Continue with a scheme similar to the one you are already using, and use vTaskSetTimeOutState() and xTaskCheckForTimeOut() to adjust the time the task blocks to wait for the event so that the task always unblocks when it is time to perform the periodic processing again.


Strategy to implement a periodic task.

Posted by simointe on March 7, 2017

That's right I want to perform periodic processing, and handle events in between each processing cycle. But that's not my problem here. My problem is that I "restart" my waiting (on timeout) AFTER I've done the execution of my task, so this execution time is added to the overall period. Is there some API functions to soustract this execution time to the next timeout value ?


Strategy to implement a periodic task.

Posted by edwards3 on March 8, 2017

thats what vTaskDelayUntil() does. When it unblocks is relative to the last time it unblocked so the time between calls doesnt matter.


Strategy to implement a periodic task.

Posted by simointe on March 9, 2017

Ok, I see. It's look like there is not the same built-in feature within Notification API. I guess I should to it by hand.


Strategy to implement a periodic task.

Posted by richarddamon on March 9, 2017

Yes, the timeout parameters for the various API doesn't have the same 'until' feature as DelayUntil.

If you want a timeout for a given period from the point you last got an event, you would need to read the tick couter yourself and adjust. For me, most of the time the timeout period isn't that crutial, but is mostly to detect that something has gone wrong or away, so the variation isn't that important, if it is, you will need to correct for it.


[ 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