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


problem with crDELAY (delay start reference?)

Posted by dcraw on December 14, 2007
This may be how crDELAY is intended to operate, but it looks like this macro is not delaying a consistent amount of time. The following code is in the body of my coroutine:

static uint16_t tick1, tick2, elapsed;
tick1 = xTaskGetTickCount();
crDELAY(xHandle, 9); //portTICK_RATE_MS is 100
tick2 = xTaskGetTickCount();
elapsed = tick2 - tick1;

If I comment out crDELAY and only have the busy waits then the elapsed ticks are 9. If I comment out the busy waits and just have the crDELAY then the elapsed ticks are also 9. But if I have both the busy waits followed by the crDELAY then the elpased ticks is still 9 (I would have expected 18). It appears that the timer for the crDELAY starts as soon as the coroutine becomes active, whereas I would expect the timer to not start until crDELAY is called.

RE: problem with crDELAY (delay start reference?)

Posted by Dave on December 17, 2007
I dont know much about coroutines but a quick look at the code shows that his would be the expected behavior which does not look too good. The coroutine tick count is only incremented when the coroutine schedule function is called. This behavior could be changed easily enough.

RE: problem with crDELAY (delay start reference?)

Posted by Dave on December 17, 2007
I have added the change request.

"The coroutine tick count is only incremented during the coroutine schedule function meaning it remains unchanged during parts of the coroutine application code. It would be better then for the coroutine delay function to use the RTOS tick as its base time when calculating a wake time rather than the coroutine time time."

RE: problem with crDELAY (delay start reference?)

Posted by Richard on December 18, 2007
In croutine.c, there is a function vCoRoutineAddToDelayedList(). At the top of this you will find the line:

xTimeToWake = xCoRoutineTickCount + xTicksToDelay;

If you change this to:

xTimeToWake = xTaskGetTickCount() + xTicksToDelay;

Then the behaviour should change so the delay is relative to the current real time, rather than the co-routine time.

Caveat: I have not actually tried this myself yet, nor analysed in detail the effect of changing this. I think it should be fine, the place to take special care is the case where an overflow in times occurs although this should be handled automatically.


[ 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