|
楼主 |
发表于 2011-2-10 22:45:18
|
显示全部楼层
回复【1楼】studyplacefor
-----------------------------------------------------------------------
主文件:
// (^_^)
#include<stdlib.h>
#include"o_os.h"
void tskfunc1(int argc,void *argv);
void tskfunc2(int argc,void *argv);
void subfunc(void);
//=================================
volatile int cnt,test; //define volatile variable
//======================
int main(void)
{
int i;
init_coos(400); //init the stack_heap;
creat_tsk(tskfunc1,12,NULL,400); //new a task
creat_tsk(tskfunc2,0,NULL,400);
i=0;
while(1)
{
WAITFOR(cnt==8); //平均占用CPU ,执行任务
while(i++<cnt) test = i; //test: for debug .
cnt++;
}
}
//===========================================
void tskfunc1(int argc,void *argv){
int i;
static int creat=0; // the guard_flag, it's no need in my opinion
if(!creat){
creat_tsk(tskfunc1,9,NULL,400);
creat=1;
}
i=0;
while(1){
WAITFOR(cnt>argc); //how can he avoid the death_loop ?
test=0x55;//
/*使用函数调用在子程序中测试WAITFOR*/
subfunc();
while(i++<cnt) test = i^0xaa;//产生测试码?
}
}
//=====================================
void tskfunc2(int argc,void *argv){
while(1){
WAITFOR(++cnt>15);
cnt=0;
}
}
//===========================
void subfunc(void){
int i;
WAITFOR(cnt<5);
for(i=0;i<cnt;i++) test = 0x10 * i;
cnt++;
} |
|