Quality RTOS & Embedded Software

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


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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists