打印

在学RTX,自己写了个关于信箱进程通信的源程序,分享给大家。

[复制链接]
162|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
王将|  楼主 | 2018-7-29 12:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
主程序,其他的不是很重要 ~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);
}
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

419

主题

419

帖子

0

粉丝