一、rtimer概述

The Contiki rtimer library provides scheduling and execution of real-time tasks (with predictable execution times)

数据结构:

struct rtimer {
rtimer_clock_t time;
rtimer_callback_t func;
void *ptr;
};
typedef void (* rtimer_callback_t)(struct rtimer *t, void *ptr);

1、rtimer_init

void
rtimer_init(void)
{
rtimer_arch_init();
}

rtimer_arch_init是跟平台相关的,rtimer_arch_init() is called by the rtimer library to initialize the rtimer architecture code.

2、rtimer_set

int
rtimer_set(struct rtimer *rtimer, rtimer_clock_t time,
rtimer_clock_t duration,
rtimer_callback_t func, void *ptr)
{
int first = ; PRINTF("rtimer_set time %d\n", time); if(next_rtimer == NULL) {//空,first置1
first = ;
} rtimer->func = func;//设置回调函数
rtimer->ptr = ptr;//回调函数第一个参数 rtimer->time = time;//设置
next_rtimer = rtimer;//设置next_rtimer if(first == ) {//如果是1
rtimer_arch_schedule(time);
}
}

rtimer用来设置rtimer,即在特定的时间(time)执行特定的回调函数(func)。

其中rtimer_arch_schedule函数是跟平台相关的,被底层用来确定调用rtimer_run_next的时间,rtimer_run_next会在特定的时间执行回调函数。

3、rtimer_run_next

void
rtimer_run_next(void)
{
struct rtimer *t;
if(next_rtimer == NULL) {
return;
}
t = next_rtimer;
next_rtimer = NULL;//重新设置为NULL
t->func(t, t->ptr);//执行回调函数
if(next_rtimer != NULL) {//在执行回调函数期间有rtimer set,在调用一次rtimer_arch_schedule
rtimer_arch_schedule(next_rtimer->time);
}
return;
}

rtimer_run_next会调用特定的next_rtimer的回调函数。

rtimer_run_next是在底层被调用的。

直观的流程:

rtimer_set(设置rtimer) --->  rtimer_arch_schedule(通知底层在特定时间)    ------>   rtimer_run_next(在特定时间执行回调函数)   ------->   rtimer_set

注:RTIMER_NOW() RTIMER_SECOND rtimer_arch_init() rtimer_arch_now() rtimer_arch_schedule()等都是跟平台有关的。

Contiki Rtimer 模块的更多相关文章

  1. Contiki Etimer 模块

    一.Etimer概述 Etimer提供产生时间事件(timed event)的机制,当设定好的timer到期时,将会给设定etimer的process发送一个PROCESS_EVENT_TIMER 事 ...

  2. Contiki clock模块

    一.functions for handling system time clock_time_t clock_time(void);//return the current system time ...

  3. Contiki Ctimer模块

    Ctimer 提供和Etimer类似的功能,只是Ctimer是在一段时间后调用回调函数,没有和特定进程相关联. 而Etimer是在一段时间后发送PROCESS_EVENT_TIMER事件给特定的进程. ...

  4. [置顶] STM32移植contiki进阶之三(中):timer 中文版

    鉴于自己英语水平不高,在这里,将上一篇关于contiki 的timer的文章翻译为中文,让自己在学习的时候,更方便点.文中有许多不是很通顺的地方,将就吧. Timers Contiki系统提供了一套时 ...

  5. Contiki-Timer 概述

    Contiki有一个clock模块和一系列timer模块:timer,stimer,ctimer,etimer,和rtimer. 一.clock模块 clock模块提供一些处理系统时间的函数,还有一些 ...

  6. Contiki Timer & Stimer 模块

    一.Timer API struct timer { clock_time_t start; clock_time_t interval; }; CCIF void timer_set(struct ...

  7. Contiki 2.7 Makefile 文件(四)

    3.第三部分 这里我们假设TARGET为native (1) OBJECTDIR = obj_$(TARGET) LOWERCASE = -abcdefghijklmnopqrstuvwxyz UPP ...

  8. Contiki源码结构

    Contiki源码结构 apps目录下,用于存放Application,也就是我们的应用程序放在这个目录下.如webserver,webrowser等,如下图所示. core目录是contiki操作系 ...

  9. cc2530 makefile简略分析 <contiki学习之三>

    前面将contiki的makefile框架都理了下,这篇就以cc2530为收篇吧,也即makefile分析就该到此为止了. contiki/examples/cc2530dk 打开Makefile如下 ...

随机推荐

  1. 微信小程序 - gulp插件压缩(代码、图片等)

    最后更新时间: 2018.7.18 :更新了所有package.json插件版本以及修复极个别问题. 2018.8.12 : 增加提示,所有标签必须闭合(不然打包会报错) 2018.10.13:需要用 ...

  2. Bootstrap 模态框、轮播 结合使用

    Bootstrap 模态框和轮播分开使用的教程网上非常多.可是两者结合使用的样例和资料非常少. 两者结合使用时,開始我遇到了不少bug,如今分享给大家. 我的这个样例是把图片轮播嵌入到模态框里. 最后 ...

  3. 【Python】读取cvs文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 6: invalid start byte

    现在有文件data.csv 文件编码格式为:ANSI data.csv 1|1|1|北京市 2|1|2|天津市 3|1|3|上海市 4|1|4|重庆市 5|1|5|石家庄市 6|2|5|唐山市 7|3 ...

  4. 怎样在编译的时候,控制删除apk不用的资源?

    1.改动alps/meidatek/config/xxx/ProjectConfig.mk下的MTK_PRODUCT_LOCALS,去掉不用的资源,比方屏幕密度或语言等.  2. nodpi和mipm ...

  5. Session对象失效的客户端解决方法

    ASP(Active Server Pages)技术的Session对象用于存储用户在对话期间的私有信息.当前用户的Session对象中定义的变量和对象能在页面之间共享,但是不能为应用中其他用户所访问 ...

  6. 集团管控的历史读本——Leo鉴书76

    当下中国管理咨询界比較火的课题之中的一个就是"集团管控".公司大了之后怎样正好的用人.怎样对下属分公司不失控制.怎样在二代接手之后系统仍然稳固.种种问题都在困扰着企业们.假设我们把 ...

  7. 用C语言解决迷宫问题

    #include <stdio.h> #include <stdlib.h> #define ROW 10 #define COL 10 /*迷宫中位置信息*/ typedef ...

  8. Android_程序未处理异常的捕获与处理

    1.简单介绍 对于程序抛出的未被捕获的异常,可能会导致程序异常退出,界面不友好且应记录关键错误信息上传至server. 这里主要使用UncaughtExceptionHandler 2.代码实现 pu ...

  9. 【Java】使用@Value @Reource或@Autowire依赖 (值) 注入时出现NPE的排查方法

    首先想说明的是,@Value @Resource和@Autowire虽然都是用于依赖注入的Annotation,但是二者是有区别的. 1 Resource不依赖于Spring,后者相反,因此为了减少以 ...

  10. Centos 7.0系统服务管理

    从Centos7开始,不再用sysvinit管理系统服务了,而是改用了systemd,因此对系统服务管理方法已经变更,以下简述 1.查看当前所有系统服务的状态 systemctl 2.查看指定系统服务 ...