本文简单介绍了Contiki系统5种定时器用途,进而着重介绍etimer,并图示timerlist。

1. 定时器概述

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]

注:

  • timer与stimer区别在于the resolution of time:timers use system clock ticks while stimers use seconds to allow much longer time periods[1]。
  • Unlike the other timers, the timer and stimer libraries can be safely used from interrupts which makes them especially useful in low level drivers.

2. 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

全局静态变量timerlist,指向系统第一个etimer,图示timerlist如下:

static struct etimer *timerlist;

etimer

3. 定时器产生及处理

通过add_timer函数将etimer加入timerlist,详情见博文《创建两个交互进程》4.1节etimer_set函数。etimer处理由系统进程etimer_process负责,详情见博文《系统进程etimer_process》。

Contiki etimer链表visio源文件:Contiki etimer链表timerlist.vsd

参考资料:

[1] Timers · contiki-os/contiki Wiki · GitHub

[2] 博文《》

本文系Spark & Shine原创,转载需注明出处本文最近一次修改时间 2022-03-20 16:48

results matching ""

    No results matching ""