OS_EVENT *Sem_Event; //创建信号量 (最后面是串口打印数据值,与理想值不符,求指教!!)
int main(void)
{
uart_init(115200);
OSInit();
Sem_Event=OSSemCreate(1);
OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO);
OSStart();
}
void high_task(void *pdata)//任务一,高优先级任务
{
u8 err;
while(1)
{
OSTimeDlyHMSM(0,0,0,500);
printf("high task Pend Sem\r\n");
OSSemPend(Sem_Event,0,&err); //信号量请求
printf("high task Running!\r\n");
OSSemPost(Sem_Event); //信号量释放
OSTimeDlyHMSM(0,0,0,500); //延时500ms
}
}
void middle_task(void *pdata)//任务二,中优先级任务
{
while(1)
{
printf("middle task Running!\r\n");
OSTimeDlyHMSM(0,0,1,0); //延时1S
}
}
void low_task(void *pdata)//任务三,低优先级任务
{
static u32 times;
u8 err;
while(1)
{
OSSemPend(Sem_Event,0,&err);
printf("low task Running!\r\n");
for(times=0;times<10000000;times++)
{
OS_Sched(); //任务调度
}
OSSemPost(Sem_Event);
OSTimeDlyHMSM(0,0,1,0);
}
}
middle task Running!
middle task Running!
middle task Running!
middle task Running!
middle task Running!
high task Running!
middle task Running!
high task Pend Sem
high task Running!
low task Running!
middle task Running!
high task Pend Sem
|