contiki的5种定时器理解

来源:互联网 发布:js格式化xml字符串 编辑:程序博客网 时间:2024/05/01 13:46

一,概述

Contiki的定时器包含一个硬件时钟模型,五个定时器模型,五种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.

二,硬件时钟模型

    硬件时钟模型是clock.c与clock.h文件:

1,core/sys/clock.h

    该文件定义了需要实现的接口

2,clock.c

    该文件对应于不同的硬件,需要自己实现,功能在clock.h里都定义了

三,定时器模块

1,timer

    该模块以clock的tick作为时间精度,设定定时器,等待时间到达以后触发,需要轮询调用;

2,stimer

    该模块以second作为时间精度,设定定时器,等待时间到达以后触发,需要轮询调用;

3,ctimer

    该模块调用etimer,触发以后调用回调函数;

4,etimer

    该模块调用timer,当定时器超时触发以后以事件的方式通知绑定定时器的线程;

5,rtimer

    该模块直接调用硬件平台,设定一个硬件实时定时器,触发以后调用一个定时器回调;

四,总结

contiki的定时器种类太多,在初期会让人有一种分不清的感觉。都是以timer(硬件定时器)为基础拓展成软件的定时器方式,有的以事件方式、有的以回调方式,有的通过粗精度来保证软件的低消耗,可以通过功能的划分来选择不同的定时器。
0 0
原创粉丝点击