摘要: 本文簡單介紹了Contiki系統(tǒng)5種定時器用途,進而著重介紹etimer,并圖示timerlist。
一、定時器概述
Contiki包含一個時鐘模型和5個定時器模型(timer, stimer, ctimer, etimer, and rtimer)[1],5種timer簡述如下:
timer--be used to check if a time period has passed[1]
stimer--be used to check if a time period has passed[1]
ctimer--Active timer, calls a functionwhen it expires, Used by Rime[2]
etimer--Active timer, sends an event whenit expires[2]
rtimer--Real-time timer, calls a functionat an exact time[2]
注:
(1) timer與stimer區(qū)別在于the resolution of time:timers use system clock ticks while stimers use seconds to allow much longer time periods[1]。
(2) Unlike the other timers, the timer and stimer libraries can be safely used from interrupts which makes them especially useful in low level drivers.
二、etimer
2.1 etimer結構體
etimer提供一種timer機制產生timed events,可以理解成etimer是Contiki特殊的一種事件。當etimer到期時,會給相應的進程傳遞事件PROCESS_EVENT_TIMER,從而使該進程啟動 。etimer結構體源碼如下: - struct etimer
-
{
-
struct timer timer;
-
struct etimer *next;
-
struct process *p;
-
};
-
-
/*****timer定義*****/
-
struct timer
-
{
-
clock_time_t start;
-
clock_time_t interval;
-
};
-
-
typedef unsigned int clock_time_t;
timer僅包含起始時刻和間隔時間,所以timer只記錄到期時間。通過比較到到期時間和新的當前時鐘,從而判斷該定時器是不是到期。
2.2 timerlist
全局靜態(tài)變量timerlist,指向系統(tǒng)第一個etimer,圖示timerlist如下:
- static struct etimer *timerlist;

etimer相關的API:參考《Contiki 2.5: core/sys/etimer.h File Reference》
參考資料:
[1] Timers - ContikiWiki :http://www.sics.se/contiki/wiki/index.php/Timers
[2] 博文《contiki代碼學習之二:淺探Event-Driven模型【1】》 |