#include #include #include IMPORT void doWorkA( UH ); IMPORT UH doWorkB( void ); typedef struct { T_MSG msg; UH data; } UserMSG; ID mbxid; ID tskIdA; /* タスクAの識別子 */ ID tskIdB; /* タスクBの識別子 */ void taskA( INT stacd, VP exinf ) { ER ercd; UserMSG rcv_umsg; while(1){ ercd = tk_rcv_mbx( mbxid, (T_MSG **)&rcv_umsg, TMO_POL ); if( ercd == E_TMOUT ) { tk_wup_tsk( tskIdB ); } else { doWorkA( rcv_umgs.data );/* タスクA用の処理 */ } } tk_ext_tsk(); } void taskB( INT stacd, VP exinf ) { UserMSG umsg[5]; INT cnt = 0; while(1){ umsg.data[cnt] = doWorkB(); /* タスクB用の処理 */ tk_snd_mbx( mbxid, (T_MSG *)&umsg[cnt] ); if( cnt != 4 ) { cnt++; } else { tk_slp_tsk( TMO_FEVR ); cnt = 0; } } tk_ext_tsk(); } EXPORT INT usermain( void ) /* 初期タスクから呼ばれる関数 */ { T_CMBX cmbx = { NULL, TA_TFIFO|TA_MFIFO }; T_CTSK ctskA = { NULL, TA_HLNG|TA_RNG0, taskA, 2, 4*1024 }; T_CTSK ctskB = { NULL, TA_HLNG|TA_RNG0, taskB, 1, 4*1024 }; mbxid = tk_cre_mbx( &cmbx ); /* メールボックスを生成 */ tskIdB = tk_cre_tsk( &ctskB ); /* タスクBを生成 */ tk_sta_tsk( tskIdB, 0 ); /* タスクBの実行を開始 */ tskIdA = tk_cre_tsk( &ctskA ); /* タスクAを生成 */ tk_sta_tsk( tskIdA, 0 ); /* タスクAの実行を開始 */ tk_slp_tsk(TMO_FEVR); /* 起床待ち状態に移行 */ return 0; }