-
/**包含一个函数声明 : static char process_thread_blink_process(struct pt *process_thread_process_pt, process_event_t ev, process_data_t data)
-
* 定义一个进程结构 : struct process blink_process = { NULL, "Blink", process_thread_blink_process };
-
*/
-
PROCESS(blink_process, "Blink");
-
/**定义一个进程数据组 : struct process blink_process = { NULL, "Blink", process_thread_blink_process };
-
* 这个进程数组是用户添加的进程,在后面的处理中,他会和系统进程一起使用进程链表管理
-
*/
-
AUTOSTART_PROCESSES(&blink_process);
-
/**定义一个进程 : static char process_thread_blink_process(struct pt *process_thread_process_pt, process_event_t ev, process_data_t data)
-
*
-
*/
-
PROCESS_THREAD(blink_process, ev, data)
-
{
-
-
PROCESS_BEGIN();
-
while(1)
-
{
-
static struct etimer et;
-
etimer_set(&et, CLOCK_SECOND);
-
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
-
-
Bsp_RedLightOnImp();
-
-
etimer_set(&et, CLOCK_SECOND);
-
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
-
-
Bsp_RedLightOffImp();
-
-
}
-
PROCESS_END();
-
}
宏讲解
-
PROCESS(blink_process, "Blink");
-
-
#define PROCESS(name, strname) \
-
PROCESS_THREAD(name, ev, data); \
-
struct process name = { NULL, strname, \
-
process_thread_##name }
-
-
#define PROCESS_THREAD(name, ev, data) \
static PT_THREAD(process_thread_##name(struct pt *process_pt, \
process_event_t ev, \
process_data_t data))
-
-
按照上面一步步展开即可得到注释部分的内容,关于##连接符的作用,如
#define A(x) T_##x
则 int A(1) = 10; //等效于int T_1 = 10;
进程展开
-
static char process_thread_blink_process(struct pt *blink_process_process_pt, process_event_t ev, process_data_t data)
-
{
-
{
-
char PT_YIELD_FLAG = 1;
-
switch((blink_process_process_pt)->lc)
-
{
-
case 0:
-
;
-
while (1) {
-
do {
-
PT_YIELD_FLAG = 0;
-
(blink_process_process_pt)->lc = __LINE__;
-
case __LINE__:
-
;
-
if((PT_YIELD_FLAG == 0) || !(etimer_expired(&et))) {
-
return PT_YIELDED
-
} while(0)
-
}
-
Bsp_RedLightOnImp();
-
-
etimer_set(&et, CLOCK_SECOND);
-
do {
-
PT_YIELD_FLAG = 0;
-
(blink_process_process_pt)->lc = __LINE__;
-
case __LINE__:
-
;
-
if((PT_YIELD_FLAG == 0) || !(etimer_expired(&et))) {
-
return PT_YIELDED
-
} while(0)
-
}
-
Bsp_RedLightOffImp();
-
-
}
-
-
};
-
-
PT_YIELD_FLAG = 0;
-
(blink_process_process_pt)->lc = 0;;
-
return 3;
-
}
-
}
进程代码展开如上图所示,在走一遍代码运行流程:
进程第一次运行:进程运行到12行保存运行的函数为12行?进程运行到15行后,条件为假,进程挂起。
假设定时事件到达,进程第二次运行:进程从头运行,运行到第五行系统跳转,这时运行从第上次保存的行开始运行,从第12行?此时就恢复上次运行的现场了。
阅读(428) | 评论(0) | 转发(0) |