新博客:http://sparkandshine.net/
分类: 嵌入式
2011-10-30 20:12:17
摘要:
本文按自己理解的方式,对进程、事件、etimer的API进行整理,以便编程。
网上有一份根据源码生成的文档(类似于ava SE 6 API Documentation),分门别类给出接口(系统和启动代码调用的接口、硬件驱动调用的接口、应用编程接口),本文只给出应用编程接口,并进行整理。另以下的大部分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.
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]