一个最简单的思路,做一个任务,每次调度它时只打印一行“Hello World”,调度10次后此任务退出。
系统环境和所需的文件同上一篇博文
今天调试成功了,任务函数如下:
PROCESS_THREAD(hello_world_process, ev, data)
//static char process_thread_hello_world_process(struct pt *process_pt, process_event_t ev, process_data_t data)
{
static int i;
PROCESS_BEGIN();
//#define PROCESS_BEGIN() PT_BEGIN(process_pt)
//#define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; if (PT_YIELD_FLAG) {;} LC_RESUME((pt)->lc)
//#define LC_RESUME(s) switch(s) { case 0:
// { char PT_YIELD_FLAG = 1; if (PT_YIELD_FLAG) {;} switch((process_pt)->lc) { case 0:;
for(i=0;i<10;i++){
printf("Hello, world\n");
PROCESS_YIELD();
}
PROCESS_END();
//#define PROCESS_END() PT_END(process_pt)
//#define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \
// PT_INIT(pt); return PT_ENDED; }
// }; PT_YIELD_FLAG = 0; (process_pt)->lc = 0;; return 3; };
}
/*---------------------------------------------------------------------------*/
main()主函数的调度如下:
int main(int argc, char **argv)
{
int i=0;
struct process * q;
process_init();
// process_start(&etimer_process, NULL);
// ctimer_init();
//autostart_start(autostart_processes);
process_start(autostart_processes[0] ,NULL);
PRINTF("\r\nprocess_list=%lx",(long)process_list);
if(process_list) PRINTF("start: starting process '%s'\n", process_list->name);
while(process_list) {
for(q = process_list; q != NULL; q = q->next){
do {
}
while(process_run()>0);
process_post_synch(q, PROCESS_EVENT_NONE, NULL);
i++;
}
}
PRINTF("\r\nprocess count = %d",i);
return 0;
}
/*---------------------------------------------------------------------------*/
编译及运行情况如下图所示,调度10次后程序退出了。