FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [April 2009 Threads] The Tick_TaskPosted 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_TaskPosted 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_TaskPosted 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_TaskPosted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|