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

The Tick_Task

Posted by Bill Yang on April 23, 2009
Hi,

I am implementing 802.1d Spanning Tree algorithm on LM3S6965 Cortex-M3 micro. There is a section pseudo code from the algorithm to implement a timer as below. I wonder if the tick() routine can be replaced by a FreeRTOS Task.

typedef struct {
bool active;
time value;
} Timer;
Timer hello_timer;

tick()
{
if(hello_timer_expired())
{
hello_timer_reset();
}
}
/* where */
hello_timer_expired()
{
if(hello_timer_active && (++hello_timer.value >= 100))
{
hello_timer.active = false;
return true;
}
return false;
}
hello_timer_reset()
{
/* TO DO some jobs here */

start_hello_timer();
}
start_hello_timer()
{
hello_timer.value = 0;
hello_timer.active = true;
}

/* the below Tick_Task() is similar to vuIP_Task() from uIP.c, I want it to replace the tick() function, if is possible?*/
struct timer {
clock_time_t start;
clock_time_t interval;
};
timer hello_timer;
void timer_set(struct timer *t, clock_time_t interval)
{
t->interval = interval;
t->start = clock_time();
}
clock_time_t clock_time( void )
{
return xTaskGetTickCount();
}
timer_reset(struct timer *t)
{
t->start += t->interval;
}
timer_expired(struct timer *t)
{
return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;
}
Tick_Task()
{
vSemaphoreCreateBinary( xHelloSemaphore );
timer_set(&hello_timer, configTICK_RATE_HZ / 2); /* configTICK_RATE_HZ = 200, so the timer is set to count of 100 ticks*/

for(;;)
{
if(timer_expired(&hello_timer)
{
timer_reset(&hello_timer)
/* TO DO some jobs here */
}
else
{
xSemaphoreTake( xHelloSemaphore, configTICK_RATE_HZ / 2 );
/*Note: used xHelloSemaphore to block here,
it will wake up every 100 tick-count. */
}
}
}
/*Question: since the hello_timer is also set to expire in count of 100 ticks, does any confliction or inaccurate tick count happen with the xHelloSemaphore?*/

I wonder if some one has any suggestion to do better job than above code.

Regards,

RE: The Tick_Task

Posted by Dave on April 24, 2009
I cannot really read the code because of the crappy formatting in this forum, but take a look at the uIP examples. These block on a semaphore with a timeout. If an Ethernet event occurs it unblocks the task using the semaphore. Timers expiring are implemented simply by allowing the block time to expire and so causing the task to unblock.

An alternative would be to use a tick hook to implement a time, with the tick hook giving the semaphore to unblock the task each time the timer expired. The same semaphore can be used to handle both Ethernet and timer events.

RE: The Tick_Task

Posted by Bill Yang on April 24, 2009
Thanks Dave,

I got your idea that suggested me to use the void vApplicationTickHook( void ) with the semaphore to handle and unblock a task.

Question: Does the ApplicationTickHook() use the same count of tick as it is defined by configTICK_RATE_HZ?

My understood that means the tick hook interrupts every 1/200 second because the configTICK_RATE_HZ is 200. Am I correct?

Regards,
Bill

RE: The Tick_Task

Posted by Dave on April 24, 2009
configTICK_RATE_HZ sets the frequency of the tick so yes, if configTICK_RATE_HZ is 200 then the tick will occur 200 times a second.


[ 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