主程序,其他的不是很重要 ~res是串口中断接受到消息的一个变量
#include "includes.h"
u8 Res;
int *msg;
unsigned int mpool[16*sizeof(unsigned int)/4+3];
OS_TID HandleLedtask;
OS_TID Handlesendmailtask;
os_mbx_declare (LEDBox,16); /* Declare an RTX mailbox */
__task void Ledtask (void);
__task void sendmailtask (void);
int main (void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
uart_init(115200);
LED_Init();
BEEP_Init(); //串口初始化波特率为115200
_init_box(mpool,sizeof(mpool),sizeof(unsigned int));
os_sys_init(sendmailtask);
while(1);
}
__task void sendmailtask ()
{ //int *msg;
Handlesendmailtask=os_tsk_self ();
os_mbx_init(LEDBox, sizeof(LEDBox));
HandleLedtask=os_tsk_create(Ledtask,3);
while(1)
{
printf("sendmailtask
");
msg =_alloc_box(mpool);
*msg = Res;
printf("Res=%d
",Res);
os_mbx_send(LEDBox, msg, 0xffff);
if(os_mbx_send(LEDBox, msg, 0xffff)==OS_R_OK)
printf("send success
");
os_dly_wait(200);
}
}
__task void Ledtask ()
{
u32 receive,*rptr;
while(1)
{
printf(" LedtTask
");
os_mbx_wait(LEDBox,(void **)&rptr,0xffff);
receive = *rptr;
if(os_mbx_wait(LEDBox,(void **)&rptr,0xffff)==OS_R_MBX)
printf("Receive success receive=%d
",receive);
if(receive==0x01)
{
printf("接受到了0x01,红灯亮起来
");
LED0=0;}
if(receive==0x02)
{ LED0=1;
printf("接受到了0x02,红灯熄灭
");}
if(receive==0x03)
{
printf("接受到了0x03,绿灯亮起来
");
LED1=0;}
if(receive==0x04)
{
printf("接受到了0x04,绿灯熄灭
");
LED1=1;}
_free_box (mpool, rptr); /* Release the memory block */
os_dly_wait(200);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>