Contiki clock模块
一、functions for handling system time
- clock_time_t clock_time(void);//return the current system time in clock ticks
- unsigned long clock_seconds(void);//return the system time in seconds
- void clock_set_seconds(unsigned long ec);//set the value of the platform seconds
这些函数都是platform dependent的,我们是在stm8中实现的。
- #if USE_RTC_CLK
- #if USE_LSE // 32768Hz
- #define CLOCK_CONF_SECOND 1024
- #else // 38000Hz
- #define CLOCK_CONF_SECOND 1000
- #endif
- #else
- #define CLOCK_CONF_SECOND 1024
- #endif
- typedef unsigned long clock_time_t;
- /**
- * A second, measured in system clock time.
- *
- * \hideinitializer
- */
- #ifdef CLOCK_CONF_SECOND
- #define CLOCK_SECOND CLOCK_CONF_SECOND
- #else
- #define CLOCK_SECOND (clock_time_t)32
- #endif
其中我们的clock_time_t是unsigned long型的,在stm8中unsigned long是32bit,最大数值是4294967295。
The number of clock ticks per second is specified with the constant CLOCK_SECOND.
CLOCK_SECOND 按1024来算,clock_time函数wrap around的时间是:
4294967295/1024/(60*60*24*365) = 0.133年
clock_seconds函数wrap aound的时间是:
4294967295/(60*60*24*365) = 136.2年
The system time starts from zero when the Contiki system starts.
二、functions for blocking the CPU
- /**
- * Wait for a given number of ticks.
- * \param t How many ticks.
- *
- */
- void clock_wait(clock_time_t t);
- /**
- * Delay a given number of microseconds.
- * \param dt How many microseconds to delay.
- *
- * \note Interrupts could increase the delay by a variable amount.
- */
- void clock_delay_usec(uint16_t dt);
These functions are normally only used in low-level drivers where it sometimes is necessary to wait a short time without giving up the control over the CPU.
The function clock_init() is called by the system during the boot-up procedure to initialize the clock module.
main函数:
- int
- main(void)
- {
- reset_sr = RST->SR;
- RST->SR = 0xFF;
- clock_init();
- leds_init();
- leds_on(LEDS_GREEN);
- HALT_LED_ON();
- rs232_init(RS232_PORT_0, USART_BAUD_9600, USART_PARITY_NONE);
- node_id_restore();
- node_init();
- process_init();
- process_start(&etimer_process, NULL);
- ctimer_init();
- 略……
- return ;
- }
三、Porting the Clock Module
The clock module is platform dependent and is implemented in the file clock.c. Since the clock module handles the system time, the clock module implementation usually also handles the notifications to the etimer library when it is time to check for expired event timers.
具体相关代码如下:
- if(etimer_pending() && etimer_next_expiration_time() <= current_clock) {
- etimer_request_poll();
- }
Contiki clock模块的更多相关文章
- Contiki Etimer 模块
一.Etimer概述 Etimer提供产生时间事件(timed event)的机制,当设定好的timer到期时,将会给设定etimer的process发送一个PROCESS_EVENT_TIMER 事 ...
- Contiki Rtimer 模块
一.rtimer概述 The Contiki rtimer library provides scheduling and execution of real-time tasks (with pre ...
- Contiki Ctimer模块
Ctimer 提供和Etimer类似的功能,只是Ctimer是在一段时间后调用回调函数,没有和特定进程相关联. 而Etimer是在一段时间后发送PROCESS_EVENT_TIMER事件给特定的进程. ...
- [置顶] STM32移植contiki进阶之三(中):timer 中文版
鉴于自己英语水平不高,在这里,将上一篇关于contiki 的timer的文章翻译为中文,让自己在学习的时候,更方便点.文中有许多不是很通顺的地方,将就吧. Timers Contiki系统提供了一套时 ...
- Contiki-Timer 概述
Contiki有一个clock模块和一系列timer模块:timer,stimer,ctimer,etimer,和rtimer. 一.clock模块 clock模块提供一些处理系统时间的函数,还有一些 ...
- Linux时间子系统之(二):软件架构
专题文档汇总目录 Notes:从框架上讲解了时间子系统,从底向上包括CPU Local TImer.Global Counter.Clock Souce/Clock Events模块管理.Tick D ...
- Linux时间子系统(二) 软件架构
一.前言 本文的主要内容是描述内核时间子系统的软件框架.首先介绍了从旧的时间子系统迁移到新的时间子系统的源由,介绍新的时间子系统的优势.第三章汇整了时间子系统的相关文件以及内核配置.最后描述各种内核配 ...
- 体系编程、SOC编程那些事儿
转:https://blog.csdn.net/yueqian_scut/article/details/49968897 笔者将从芯片IC的系统设计的角度去诠释如何掌握体系编程和SOC编程.笔者有超 ...
- SYS/BIOS实例分析
SYS/BIOS简介 SYS/BIOS是一个可扩展的实时内核(或者说是操作系统),其提供了许多模块化的APIs(应用程序接口),支持抢占式多线程,硬件抽象,实时分析和配置工具,其设计目的是为了最大限度 ...
随机推荐
- SGU 231 Prime Sum 求<=n内有多少对素数(a,b)使得a+b也为素数 规律题
题目链接:contest=0&problem=231">点击打开链接 题意: 求<=n内有多少对素数(a,b)使得a+b也为素数 思路: 我们发现全部素数间隔都是> ...
- Android4.0(Phone)拨号启动过程分析(一)
因为工作的须要.须要改动原生的Phone程序,如今就好好看下来电与拨号是怎样处理的:无论是拨号还是来电,调用的都是Phone程序,因为非常多类都涉及到framework层,比較复杂:先从简单的拨号分析 ...
- tp框架where条件查询数据库
tp框架where条件查询数据库 Where 条件表达式格式为: $map['字段名'] = array('表达式', '操作条件'); 其中 $map 是一个普通的数组变量,可以根据自己需求而命名. ...
- Spring使用Cache、整合Ehcache(转)
Spring使用Cache 从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我 ...
- hdu2141Can you find it?
给你四个集合.要你从这四个集合中 各取出一个数出来,推断,取出的前三个数的和 是否等于第四个数. 数据比較大.我的做法是将 前两个集合全部数全部和的情况取出来, 然后二分查找第四个集合和第三集合 ...
- 35:字符串单词倒排 ReverseWords
题目描述:对字符串中的所有单词进行倒排. 说明: 1.每个单词是以26个大写或小写英文字母构成: 2.非构成单词的字符均视为单词间隔符: 3.要求倒排后的单词间隔符以一个空格表示:如果原字符串中相邻单 ...
- Android UI开源框架
1.Side-Menu.Android 分类側滑菜单,Yalantis 出品. 项目地址:https://github.com/Yalantis/Side-Menu.Android 2.Context ...
- 在tomcat中用jndi配置数据源启动java web程序
1.在web.xml中添加: <resource-ref> <res-ref-name>jdbc/MTSDB</res-ref-name> <re ...
- 机器学习实战之K-Means算法
一,引言 先说个K-means算法很高大上的用处,来开始新的算法学习.我们都知道每一届的美国总统大选,那叫一个竞争激烈.可以说,谁拿到了各个州尽可能多的选票,谁选举获胜的几率就会非常大.有人会说,这跟 ...
- php正则表达式匹配img中任意属性的方法
经常和图片打交道,不得不用到一些提取图片中scr.alt.title.等的属性,这里总结给大家一些常用的,感觉还不错,比较通用! PHP正则表达式匹配img中任意属性PHP 复制代码代码如下: < ...