Contiki例(三)使用etimer定时器激活被阻塞的任务

所使用的系统文件如下:上一博文只使用Contiki操作系统的核心,则只保留sys文件夹下8个文件就行了,实际上argc.h和argc.c没有使用,可用0字节的文件代替。或修改process.c删除对argc.h的引用,最精简的保留6个文件就行了。今天阅读源代码增加etimer的功能后,把sys文件如下所示。

-[F]whz_contiki {
 |-[F]sys {
 | |-arg.c
 | |-arg.h
 | |-cc.h
 | |-clock.h
 | |-etimer.c
 | |-etimer.h
 | |-lc-switch.h
 | |-lc.h
 | |-process.c
 | |-process.h
 | |-pt.h
 | |-timer.c
 | |-timer.h }

系统sys文件夹下的文件增加到了13个,clock.h是硬件平台的接口,必须在对应的平台上实现对应的clock.c文件,可参照 platform 文件夹下的文件修改。

hello_world.c如下:

#include "contiki.h"
struct etimer hello_etimer;
PROCESS(hello_world_process, "Hello world process");
PROCESS_THREAD(hello_world_process, ev, data)
{
   static int i;
  PROCESS_BEGIN();
  for(i=0;i<3;i++){
      PROCESS_YIELD();
      etimer_restart(&hello_etimer);
      printf("Hello, world\n");
  }
  PROCESS_END();
}

main.c如下:


#include "contiki.h"
PROCESS_NAME(hello_world_process);
extern struct etimer hello_etimer;
int main(int argc, char **argv)
{
    process_init();
    process_start(&hello_world_process, NULL);
    process_start(&etimer_process, NULL);
    etimer_set(&hello_etimer,3000);
    while(process_list) {
        do {
        }
        while(process_run()>0);
        etimer_request_poll();
        if(!etimer_pending()){
            process_exit(&etimer_process);
        }
    }
    return 0;
}
OK了,实现了三秒打印一次“Hello World”!打印3次后程序退出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值