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




Loading

How many ticks till a timer expires?

Posted by mizer on December 5, 2011
Hi,

Let's say I've created and started a timer for period X ticks. Now, some unknown number of ticks later I want to change it's period to Y and restart it. But ONLY do this if the new period Y will cause the timer to expire later than the presently ticking down balance of the original period X. I may have missed it but I didn't see an obvious way to do this.

I was hoping to avoid creating and running a whole slew of timers. As in my case this will take up to 24 timers. Even though they all can reference a single callback function.

Thanking...

RE: How many ticks till a timer expires?

Posted by Richard on December 6, 2011
There is no way of doing that currently, but you could add something like the following to timers.c [read caveats below]:

portTickType xTimerGetExpireTime( xTimerHandle xTimer )
{
xTIMER *pxTimer = ( xTIMER * ) xTimer;
portTickType xTimeNow, xExpireTime, xReturn;
const portTickType xMaxTime = -1;

vTaskSuspendAll();
{
configASSERT( pxTimer );
xTimeNow = xTaskGetTickCount();
xExpireTime = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );

if( xExpireTime >= xTimeNow )
{
xReturn = xExpireTime - xTimeNow;
}
else
{
xReturn = ( xMaxTime - xTimeNow ) + xExpireTime;
}
}
xTaskResumeAll();
}


Caveats:

1) This code is completely untested, not even compiled, it is here for demonstration of how it could be done only.

2) You have to take into account that time may pass between calling this function and the function returning - especially if it is called from a low priority task.

Hope that helps.

Regards.

RE: How many ticks till a timer expires?

Posted by mizer on December 6, 2011
Yes Richard. That surely helps. I pictured something like that, including the suspends, but wasn't sure how to get at the expiration time. I'll try to work with this. But for safety sake may end up with the brute force approach with an array of timers waiting for the last one to expire.

Thanks for your help.


[ 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