免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1800 | 回复: 0
打印 上一主题 下一主题

Contiki学习笔记:主要数据结构之etimer [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-23 03:25 |只看该作者 |倒序浏览

摘要:

    本文简单介绍了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:参考《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】

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP