以下是我修改的程序,在mytask中添加了一个延时,我认为应该先显示mytask calling fun(),然后过8s之后再显示youtask calling fun(),可是
实际上是,显示mytask calling fun()之后紧接着显示八个youtask calling fun()然后是mytask callingfun()
请问这是为什么呢?
#include "INCLUDES.h"
#define TASK_STK_SIZE 512
char *s1="MyTask"; char *s2="YouTask"; INT8U err; INT8U y=0; OS_EVENT *Fun_Semp;
OS_STK StartTaskStk[TASK_STK_SIZE]; OS_STK MyTaskStk[TASK_STK_SIZE]; OS_STK YouTaskStk[TASK_STK_SIZE];
void Fun(INT8U x,INT8U y); void StartTask(void *data); void MyTask(void *data); void YouTask(void *data);
/* ********************************************************************************************************* * MAIN主函数 ********************************************************************************************************* */ void main (void) { Fun_Semp=OSSemCreate(1); //定义信号量 OSInit(); PC_DOSSaveReturn(); PC_VectSet(uCOS, OSCtxSw);
OSTaskCreate(StartTask,(void *)0, &StartTaskStk[TASK_STK_SIZE - 1], 0); //创建起始函数 OSStart(); /* 启动多任务管理 */ }
void StartTask(void *pdata) { #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif
INT16S key; /*用于退出的建*/ pdata = pdata; /* Prevent compiler warning */ OS_ENTER_CRITICAL(); PC_VectSet(0x08, OSTickISR); PC_SetTickRate(OS_TICKS_PER_SEC); OS_EXIT_CRITICAL(); OSStatInit(); /* 初始化统计任务 */ OSTaskCreate(MyTask,(void *)0, &MyTaskStk[TASK_STK_SIZE - 1], 1); //创建任务函数 OSTaskCreate(YouTask,(void *)0, &YouTaskStk[TASK_STK_SIZE - 1], 2); //创建任务函数 for (;;) { if (PC_GetKey(&key) == TRUE) { /* See if key has been pressed */ if (key == 0x1B) { /* Yes, see if it's the ESCAPE key */ PC_DOSReturn(); /* Return to DOS */ } } OSTimeDlyHMSM(0,0,3,0); /* 等待3S*/ } }
void MyTask(void *pdata) { #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif pdata = pdata; /* Prevent compiler warning */ for (;;) { OSSemPend(Fun_Semp,0,&err); //请求信号量 PC_DispStr(0,y++,s1,DISP_BGND_BLACK+DISP_FGND_WHITE); Fun(7,y); //############################################################################# OSTimeDlyHMSM(0,0,8,0); /* 等待8S*/ //############################################################################# OSSemPost(Fun_Semp); //发送信号量 OSTimeDlyHMSM(0,0,1,0); /* 等待1S*/ } }
void YouTask(void *pdata) { #if OS_CRITICAL_METHOD == 3 //Allocate storage for CPU status register OS_CPU_SR cpu_sr; #endif
pdata=pdata; for (;;) { OSSemPend(Fun_Semp,0,&err); //请求信号量 PC_DispStr(0,y++,s2,DISP_BGND_BLACK+DISP_FGND_WHITE); Fun(7,y);
OSSemPost(Fun_Semp);
OSTimeDlyHMSM(0,0,1,0); //等待10个时钟节拍 } }
void Fun(INT8U x,INT8U y) { PC_DispStr(x,y-1," Calling FUN()",DISP_BGND_BLACK+DISP_FGND_WHITE); }
|