Chinaunix首页 | 论坛 | 博客
  • 博客访问: 393237
  • 博文数量: 87
  • 博客积分: 1171
  • 博客等级: 少尉
  • 技术积分: 1068
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-19 14:34
文章分类

全部博文(87)

文章存档

2014年(10)

2013年(24)

2012年(53)

我的朋友

分类: 嵌入式

2012-10-12 19:58:54

Contiki学习笔记:应用编程接口API

 

一、进程

1.1 进程声明和定义[1]

PROCESS_THREAD(name, ev, data)-----Define the body of a process.  

PROCESS_NAME(name)-----Declare the name of a process.  

PROCESS(name, strname)-----Declare a process.

1.2 process protothread方法

PROCESS_BEGIN()-----Define the beginning of a process.  

PROCESS_END()-----Define the end of a process.  

PROCESS_EXIT()-----Exit the currently running process.

PROCESS_CURRENT()-----Get a pointer to the currently running process. PROCESS_CONTEXT_BEGIN(p)-----Switch context to another process. PROCESS_CONTEXT_END(p)-----End a context switch.

PROCESS_POLLHANDLER(handler)-----Specify an action when a process is polled. PROCESS_EXITHANDLER(handler)-----Specify an action when a process exits.

1.3 进程内核函数[2]

void process_start (struct process *p, const char *arg)-----Start a process.  

void process_exit (struct process *p)-----Cause a process to exit. 

1.4 挂起进程相关[1][3]

PROCESS_WAIT_EVENT()-----Wait for an event to be posted to the process. PROCESS_WAIT_EVENT_UNTIL(c)-----Wait for an event to be posted to the process, with an extra condition. 

PROCESS_YIELD()-----Yield the currently running process.  

PROCESS_YIELD_UNTIL(c)-----Yield the currently running process until a condition occurs.

PROCESS_WAIT_UNTIL(c)-----Wait for a condition to occur.  

PROCESS_WAIT_WHILE(c)-----PT_WAIT_WHILE(process_pt, c)  

PROCESS_PT_SPAWN(pt, thread)-----Spawn a protothread from the process.  

PROCESS_PAUSE()-----Yield the process for a short while.

二、事件

2.1 新建事件[1]

process_event_t  process_alloc_event (void)-----Allocate a global event number.

2.2 传递事件[1][2]

int process_post (struct process *p, process_event_t ev, void *data)-----Post an asynchronous event.  

void process_post_synch (struct process *p, process_event_t ev, void *data)-----Post a synchronous event to a process.

三、etimer[4][5]

void etimer_set (struct etimer *et, clock_time_t interval)-----Set an event timer.  

void etimer_reset (struct etimer *et)-----Reset an event timer with the same interval as was previously set.

void etimer_restart (struct etimer *et)-----Restart an event timer from the current point in time.

   这里特别对etimer_reset 和 etimer_restart进行说明,容易混淆。

 

     either_reset :定时事件已经到了,我现在需要重新计时,此时,我重置下et->start=et->start+et-.interval, 也就是刚计时结束的那个点为起点,继续计时。这个函数周期性很好,是精确的一次一个et->interval 向前迈进的。

 

   etimer_restart :从现在的时间点重新计时et->interval 时间,虽然时间起点有漂移,但是它也是准确的监测et->interval时间段。产生时间事件。这个不需要很好的周期性,当需要et->interval这么长时间时,调用就行了。

 

 

 

 

  

void etimer_adjust (struct etimer *et, int td)-----Adjust the expiration time for an event timer.

void etimer_stop (struct etimer *et)-----Stop a pending event timer.  

int etimer_expired (struct etimer *et)-----Check if an event timer has expired. 

clock_time_t etimer_expiration_time (struct etimer *et)-----Get the expiration time for the event timer.

clock_time_t etimer_start_time (struct etimer *et)-----Get the start time for the event timer.


参考资料:

[1] 

[2] 

[3] 博文《Contiki学习笔记:编程模式

[4] 

[5] 

 

阅读(2541) | 评论(0) | 转发(0) |
0

上一篇:IPv6 概述

下一篇:contiki 程序逻辑总结

给主人留下些什么吧!~~