#include<conio.h>
#include<unistd.h> // execi function is included
tid_t t_task1,t_task2,t_task3;
int task1(){ // task1 function
int roop;
for(roop=0;roop<500;roop++){
cputs("task1");
}
return 0;
}
int task2(){ // task2 fanction
int roop;
for(roop=0;roop<500;roop++){
cputs("task2");
}
return 0;
}
int task3(){// task3 fanction
int roop;
for(roop=0;roop<500;roop++){
cputs("task3");
}
return 0;
}
int main(int argc, char **argv) {
t_task1=execi(&task1,0,NULL,10,DEFAULT_STACK_SIZE); // make task1
t_task2=execi(&task2,0,NULL,50,DEFAULT_STACK_SIZE); // make task2
t_task3=execi(&task3,0,NULL,100,DEFAULT_STACK_SIZE); // make task3
return 0;
}
|
プログラムを起動した時点で、execi()で生成したタスク以外に、main 関数の実行にあたって、優先度 10 の main タスクが生成されています。この例では、main はタスク生成を生成するだけでその実行を終えるため、上記の様な場合にアイドルタスクへと処理が移ります。
#include<conio.h>
#include<dsensor.h>
#include<unistd.h> // wait_event function is included
wakeup_t sensor_press_wakeup(wakeup_t data); // wakeup_function
tid_t t_task1,t_task2;
int task1(){ // task1 function
cputs("task1");
wait_event(&sensor_press_wakeup,0);
cputs("tson");
return 0;
}
int task2(){ // task2 fanction
sleep(2);
cputs("task2");
return 0;
}
int main(int argc, char **argv) {
t_task1=execi(&task1,0,NULL,50,DEFAULT_STACK_SIZE); // make task1
t_task2=execi(&task2,0,NULL,10,DEFAULT_STACK_SIZE); // make task2
return 0;
}
wakeup_t sensor_press_wakeup(wakeup_t data) { // wakeup_function
return SENSOR_1<0xf000;
}
|

ヒント:タッチセンタと光センサの入力を wait_event するタスクをそれぞれ生成する。