共2条
1/1 1 跳转至页
2210,UC,OS 在2210上移植UC/OS中,有关邮箱和消息队列使用中的问题!
问
UC/OS-II 我的程序中邮箱发送消息正确,但等待接收的却接收不到,接收的任务优先级高。应该可以接收到呀!请问是什么原因呢?谢谢了!
任务之间发送消息,接收者总接收不到。但同一个任务里发送时可以接收到 答 1: 程序#include "config.h"
#define ENGINE_OIL_PERS_OK 0x01
#define ENGINE_OIL_TEMP_OK 0x02
#define ENGINE_START 0x04
#define TASK_STK_SIZE 64
OS_STK TaskStk[TASK_STK_SIZE];
OS_STK TaskStartStk[TASK_STK_SIZE];
OS_STK TaskBeenStk[TASK_STK_SIZE];
OS_STK TaskOutStk[TASK_STK_SIZE];
OS_EVENT *Uart0Mbox;
OS_FLAG_GRP *EngineStatus;
void Uart0Send(uint8 *dat,uint8 num);
uint8 Uart0Recive(uint8 num);
void TaskStart(void *pdata);
void TaskOut(void *pdata);
void TaskBeen(void *pdata);
int main(void)
{
OSInit();
Uart0Mbox=OSMboxCreate(NULL);
if(Uart0Mbox==NULL)
{
while(1);
}
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE-1],0);
OSStart();
return 0;
}
void TaskStart(void *pdata)
{
uint8 err,err1,err2,err3;
uint8 *dat;
EngineStatus = OSFlagCreate(0x00,&err3);
TargetInit();
OSTaskCreate(TaskOut,(void *)0,&TaskOutStk[TASK_STK_SIZE-1],12);
OSTaskCreate(TaskBeen,(void *)0,&TaskBeenStk[TASK_STK_SIZE-1],11);
abb:
OSFlagPost(EngineStatus,ENGINE_OIL_PERS_OK,OS_FLAG_SET,&err);
if(err!=OS_NO_ERR)
{
goto abb;
}
for(;;)
{
dat=(uint8 *)OSMboxPend(Uart0Mbox,10,&err1);
Uart0Send(dat,5);
OSFlagPost(EngineStatus,ENGINE_OIL_PERS_OK,OS_FLAG_SET,&err2);
}
}
void TaskOut(void *pdata)
{
uint8 err,err1,err2,err3;
uint8 Flag;
uint8 *dat;
pdata=pdata;
for(;;)
{
Flag=OSFlagPend(EngineStatus,ENGINE_OIL_PERS_OK,OS_FLAG_WAIT_SET_ALL,20,&err);
if(err==OS_NO_ERR)
{
dat=(void *)Uart0Recive(5);
if(*(dat+4)==0xFF)
{
OSFlagPost(EngineStatus,ENGINE_OIL_TEMP_OK,OS_FLAG_SET,&err1);
}
}
err2=OSMboxPost(Uart0Mbox,(void *)dat);
if(err2==OS_NO_ERR)
{
OSFlagPost(EngineStatus,ENGINE_OIL_PERS_OK,OS_FLAG_CLR,&err3);
}
}
}
void TaskBeen(void *pdata)
{
uint8 err;
pdata=pdata;
for(;;)
{
OSFlagPend(EngineStatus,ENGINE_OIL_TEMP_OK,OS_FLAG_WAIT_SET_ALL+OS_FLAG_CONSUME,0,&err);
OS_ENTER_CRITICAL();
PWMTCR=0x09; //启动PWM
OS_EXIT_CRITICAL();
OSTimeDly(OS_TICKS_PER_SEC*5);
OS_ENTER_CRITICAL();
PWMTCR=0x09;
OS_EXIT_CRITICAL();
}
}
任务之间发送消息,接收者总接收不到。但同一个任务里发送时可以接收到 答 1: 程序#include "config.h"
#define ENGINE_OIL_PERS_OK 0x01
#define ENGINE_OIL_TEMP_OK 0x02
#define ENGINE_START 0x04
#define TASK_STK_SIZE 64
OS_STK TaskStk[TASK_STK_SIZE];
OS_STK TaskStartStk[TASK_STK_SIZE];
OS_STK TaskBeenStk[TASK_STK_SIZE];
OS_STK TaskOutStk[TASK_STK_SIZE];
OS_EVENT *Uart0Mbox;
OS_FLAG_GRP *EngineStatus;
void Uart0Send(uint8 *dat,uint8 num);
uint8 Uart0Recive(uint8 num);
void TaskStart(void *pdata);
void TaskOut(void *pdata);
void TaskBeen(void *pdata);
int main(void)
{
OSInit();
Uart0Mbox=OSMboxCreate(NULL);
if(Uart0Mbox==NULL)
{
while(1);
}
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE-1],0);
OSStart();
return 0;
}
void TaskStart(void *pdata)
{
uint8 err,err1,err2,err3;
uint8 *dat;
EngineStatus = OSFlagCreate(0x00,&err3);
TargetInit();
OSTaskCreate(TaskOut,(void *)0,&TaskOutStk[TASK_STK_SIZE-1],12);
OSTaskCreate(TaskBeen,(void *)0,&TaskBeenStk[TASK_STK_SIZE-1],11);
abb:
OSFlagPost(EngineStatus,ENGINE_OIL_PERS_OK,OS_FLAG_SET,&err);
if(err!=OS_NO_ERR)
{
goto abb;
}
for(;;)
{
dat=(uint8 *)OSMboxPend(Uart0Mbox,10,&err1);
Uart0Send(dat,5);
OSFlagPost(EngineStatus,ENGINE_OIL_PERS_OK,OS_FLAG_SET,&err2);
}
}
void TaskOut(void *pdata)
{
uint8 err,err1,err2,err3;
uint8 Flag;
uint8 *dat;
pdata=pdata;
for(;;)
{
Flag=OSFlagPend(EngineStatus,ENGINE_OIL_PERS_OK,OS_FLAG_WAIT_SET_ALL,20,&err);
if(err==OS_NO_ERR)
{
dat=(void *)Uart0Recive(5);
if(*(dat+4)==0xFF)
{
OSFlagPost(EngineStatus,ENGINE_OIL_TEMP_OK,OS_FLAG_SET,&err1);
}
}
err2=OSMboxPost(Uart0Mbox,(void *)dat);
if(err2==OS_NO_ERR)
{
OSFlagPost(EngineStatus,ENGINE_OIL_PERS_OK,OS_FLAG_CLR,&err3);
}
}
}
void TaskBeen(void *pdata)
{
uint8 err;
pdata=pdata;
for(;;)
{
OSFlagPend(EngineStatus,ENGINE_OIL_TEMP_OK,OS_FLAG_WAIT_SET_ALL+OS_FLAG_CONSUME,0,&err);
OS_ENTER_CRITICAL();
PWMTCR=0x09; //启动PWM
OS_EXIT_CRITICAL();
OSTimeDly(OS_TICKS_PER_SEC*5);
OS_ENTER_CRITICAL();
PWMTCR=0x09;
OS_EXIT_CRITICAL();
}
}
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |