|
源程序
#include <includes.h>
#define TaskaStkLengh 256
#define TaskbStkLengh 256
#define TaskcStkLengh 256
OS_STK TaskaStk[TaskaStkLengh];
OS_STK TaskbStk[TaskbStkLengh];
OS_STK TaskcStk[TaskcStkLengh];
OS_EVENT * DispSem;
void Taska (void * pdata);
void Taskb (void * pdata);
void Taskc (void * pdata);
static void App_DispScr_SignOn (void);
int main (void)
{
BSP_IntDisAll(); /* Disable all ints until we are ready to accept them. */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel". */
BSP_Init(); /* Initialize BSP functions. */
App_DispScr_SignOn ();
printf("OS Init OK!\r\n");
OSTaskCreate (Taska,(void*)0,&TaskaStk[TaskaStkLengh-1],7) ;
OSTaskCreate (Taskb,(void*)0,&TaskbStk[TaskbStkLengh-1],8) ;
OSTaskCreate (Taskc,(void*)0,&TaskcStk[TaskcStkLengh-1],9) ;
OSTimeSet(0);
OS_CPU_SysTickInit(); /* Initialize the SysTick. */
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II). */
return 0;
}
void Taska (void * pdata)
{
INT8U err;
INT8U i=0;
DispSem=OSSemCreate(1); //建立信号量
while(1)
{
OSSemPend(DispSem,0,&err);
i++;
if(i==100)i=0;
printf("\r\nTaska \r\n");
//OSTimeDly(500);
err=OSSemPost(DispSem);
}
}
void Taskb (void * pdata)
{
INT8U err;
INT8U i=0;
while(1)
{
OSSemPend(DispSem,0,&err);
i++;
if(i==100)i=0;
printf("\r\n Taskb \r\n");
err=OSSemPost(DispSem);
//OSTimeDly(600);
}
}
void Taskc (void * pdata)
{
INT8U err;
INT8U i=0;
while(1)
{
OSSemPend(DispSem,0,&err);
i++;
if(i==100)i=0;
printf("\r\n Taskc \r\n");
err=OSSemPost(DispSem);
//OSTimeDly(700);
}
}
程序的本意是让这个三任务交替执行.如果不注释掉延时可以达到交替执行的目的.但是注释掉打//地方的延时后程序只运行Taska .其它的任务都不会被执行.
难道 err=OSSemPost(DispSem); 后面或前面必需加 OSTimeDly(500);延时. |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|