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


vTaskDelay() in non-preemptive port

Posted by Tzu-Chien Chiu on August 29, 2006
Hello, everyone:

I have a non-preemptive port and I need a vTaskDelay. Using tick ISR is not an option (as it's a non-preemptive one), and I'm looking for an approximate solution.

The best one I come up with so far is inserting as many taskYIELD() as possbile, and having the port of portYIELD():

#define taskYIELD portYEILD

#define portYIELD do { \
vTaskIncrementTick(); \
here are same assembly to
switch context, and call
} while (0)

The call to vTaskIncrementTick() is required because it moves the tasks in the delayed list to ready list. Without it, the task calling vTaskDelay() will be suspend forever.

Is there better solution?

RE: vTaskDelay() in non-preemptive port

Posted by Nobody/Anonymous on August 29, 2006
You cannot increment the tick each time yield is called. This will loose all track of time.

Why cannot you use task delay in cooperative mode? The tick interrupt will increment the time, wake any unblocked tasks BUT WILL NOT switch context until another task calles yield or blocks.

RE: vTaskDelay() in non-preemptive port

Posted by Tzu-Chien Chiu on August 29, 2006
Thanks for reminding me the lose of time track.

Unfortunately, using tick interrupt is not an
option because of buggy hardware implementation.

RE: vTaskDelay() in non-preemptive port

Posted by David Hawks on August 29, 2006
I get the impression that you are trying to use vTaskDelay() incorrectly.

If you just want to switch between multiple tasks, you can use taskYIELD() like you mentioned in your previous thread. However, the tasks must be at the same priority. Your problem with starving Task 1 was due to the fact that Task 2 was at a higher priority.

You will probably run into the same problem if you use vTaskDelay() and then call vTaskIncrementTick() within taskYIELD().

In other words, if you are running in cooperative mode and you are not tracking time and you want to switch between multiple tasks, you can make the priority of the tasks the same and use taskYIELD().

RE: vTaskDelay() in non-preemptive port

Posted by Tzu-Chien Chiu on August 30, 2006
I have several tasks, and one of them does *audio-video synchronization* and needs trigger the hardware after a *cacluated delay* time (the parameter to vTaskDelay). It cannot just spin for the specified time, because the processor time will be wasted, and our application cannot afford it.

/* spin without yield */
int begin = tick();
while (1) {
if (tick() - begin > DELAY) break;

I know that in the cooperative mode the delay couldn't be accurate, so I am just look for an approximated solution.

RE: vTaskDelay() in non-preemptive port

Posted by David Hawks on August 30, 2006
A design assumption made in the FreeRTOS code is that a timer with an interrupt is available for keeping track of time. You are attempting to run FreeRTOS without this. I think you may still be able to get what you need, but it requires some creativity.

This is an "approximate" solution that does have some potential holes.

I assume your "buggy hardware implementation" at least provides you with a timer that you can poll. You can add a poll of the timer in the idle task and call vTaskIncrementTick() when the timer fires. This will work as long as the idle task gets sufficient execution time. You will miss ticks (causing your delays to increase) if the idle task is starved.

[ 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