Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1634381
  • 博文数量: 124
  • 博客积分: 4078
  • 博客等级: 中校
  • 技术积分: 3943
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-21 11:28
个人简介

新博客:http://sparkandshine.net/

文章分类

全部博文(124)

分类: 嵌入式

2011-10-21 14:57:34

摘要:

    本文简单介绍了Contiki系统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区别在于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结构体源码如下:

  1. struct etimer
  2. {
  3.   struct timer timer;
  4.   struct etimer *next;
  5.   struct process *p;
  6. };

  7. /*****timer定义*****/
  8. struct timer
  9. {
  10.   clock_time_t start;
  11.   clock_time_t interval;
  12. };

  13. typedef unsigned int clock_time_t;

    timer仅包含起始时刻和间隔时间,所以timer只记录到期时间。通过比较到到期时间和新的当前时钟,从而判断该定时器是不是到期。

2.2 timerlist

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

  1. static struct etimer *timerlist;

etimer相关的API:参考《》


三、定时器产生及处理

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


参考资料:

[1] Timers - ContikiWiki :

[2] 博文《》

[3] Contiki etimer链表visio源文件 Contiki etimer链表timerlist.rar   

阅读(9709) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

shinykongcn2013-08-30 17:53:37

文章内的链接都跑到你的首页去了。。