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

Posted by Mike Nastin on September 5, 2011
Using port to windows i was wondered that vTaskDelay not work correctly, i.e. for example vTaskDelay(100) will delay task on 2000ms. Is it problem only for windows 7 and how solve that?

RE: vTaskDelay in Windows 7

Posted by Richard on September 5, 2011
The Windows port is a FreeRTOS "Simulator". As it says on the documentation page for the port "The tick interrupt generation is simulated by a high priority Windows thread that will periodically pre-empt the low priority threads that are running tasks. The tick rate achievable is limited by the Windows system clock, which in normal FreeRTOS terms is very slow and has a very low precision. True real time behaviour cannot therefore be obtained."

While it is common to have ticks running at 100Hz or even 1KHz on a microcontroller, the Windows clock is in comparison extremely clunky. The resolution is dependent on your hardware, but often in the 40ms range (with huge jitter too). Therefore, attempting to use this clock to get near real time performance would prevent any tasks being able to accurately block for any time that was not a multiple of this 40 (ish) ms, and the average accuracy would be 40/2 ms - not very good.

For those reasons, the port simulates a real time system by making time run slowly, where it pretends every 'n' ms is 1 ms. Asking for a 100ms delay should always result in approximately the same delay being achieved, but it will be nothing like 100ms.

The simulator is a convenient place to develop code, that can then be moved relatively easy onto a real target, it is not in itself intended to be a real time system.


RE: vTaskDelay in Windows 7

Posted by Mike Nastin on September 6, 2011
Ok, i understood. Also i looked at freertos process cpu loading and it was always above 25%. In my mind all of this restrictions make no sense to using windows port. I supposed that windows port of freertos is just wrapper above winapi functions and not realize freertos algorithms. Earlier i wrote own wrappers for threads, seamphores etc (in windows it wrap winapi in device it wrap freertos api) but when i saw freertos windows port i thought that can use just freertos api on both platforms without any wrappers.
Thanks anyway.

RE: vTaskDelay in Windows 7

Posted by Dave on September 6, 2011
Read the documentation page for the project.

RE: vTaskDelay in Windows 7

Posted by Alfredo Rainho on September 19, 2011
HI All,

Actually windows can generate clock ticks of 1000 or more with no problems under windows. Windows does have special counters that can be used to generate these high tick clocks. For those interrested below is my version of the "prvSimulatedPeripheralTimer" routine which creates the clock ticks. Just substitute the current one in port.c and start ticking away. In my PC the reported max frequency is of about 2mhz!!!

I have not tested this on single core computers, but on twin core one core is used at 100% and the other is left free which gives the system good response.



// Modification by: Alfredo Rainho Neves
// This is an updated version that will actually responde a few thousand times
// a second.
// The CPU load will show very high, but the routine actualy yield
// giving other tasks a chance. In a multicore CPU only one core will have
// a 100% CPU usage
static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
LARGE_INTEGER lpFrequency;
LARGE_INTEGER currentTime;
unsigned long countPerTick;
unsigned long elapsed;

/* Just to prevent compiler warnings. */
( void ) lpParameter;

// Get the performance counter frequency

// Calculate the count per ticks
countPerTick = lpFrequency.LowPart / configTICK_RATE_HZ;

while(1) {
// Get the start time

// Wait for time period to elapse
do {
// Yield to another task to make the system more responsive

// Get the current time

// Calculate the elpased time
elapsed = currentTime.LowPart - startTime.LowPart;

} while (elapsed < countPerTick);

WaitForSingleObject( pvInterruptEventMutex, INFINITE );

/* The timer has expired, generate the simulated tick event. */
ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );

/* The interrupt is now pending - notify the simulated interrupt
handler thread. */
SetEvent( pvInterruptEvent );

/* Give back the mutex so the simulated interrupt handler unblocks
and canaccess the interrupt handler variables. */
ReleaseMutex( pvInterruptEventMutex );

#ifdef __GNUC__
/* Should never reach here - MingW complains if you leave this line out,
MSVC complains if you put it in. */
return 0;

[ 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