打印
[应用方案]

UCOS内核2.83 基础知识总结

[复制链接]
531|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ideafor|  楼主 | 2016-4-22 09:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一:什么是邮箱
邮箱是UCOS中的一种通信机制,可以使一个任务或者中断服务子程序向另一个任务发送一个指针型的变量。通常该指针指向一个包含了“消息”的特定数据结构。
邮箱可以建多个,邮箱的最大数量由OS_CFG.H文件中的配置常数OS_MAX_EVENTS设定。一个邮箱只能保存一则消息。
二:邮箱的使用目的
1.通知一个事件的发生(发送一条消息)那么初始化时就要把该邮箱设空(NULL)。
2.如果用邮箱共享某些资源,那么就要初始化该邮箱为一个非NULL的指针,这种情况下,邮箱被当作一个二值信号量来使用。
三:程序示例
Void main(void)

{

       OSInit();

    AckMbox = OSMboxCreate( ( void * ) 0 );

    TxMbox  = OSMboxCreate( ( void * ) 0 );

    OSStart();

}



Void Task1( void * data)

{

       Char * txmsg;



    Txmsg = ‘A’ ;

    For (; ;){

           OSMboxPost(TxMbox, ( void * )&txmsg );

           OSMboxPend(AckMbox,0,&err) ;

           Txmsg ++;

           If ( txmsg == ‘Z’){

               Txmsg = ‘A’ ;

               }

         }

}



Void Task2 ( void * data )

{

    Char * rxmsg;

    INT8U err ;



    For ( ; ;){

       Rxmsg =  ( char *)OSMboxPend(TxMbox, 0,&err)

       PC_DispChar ( 70 ,18 ,* rxmsg ,DISP_FGND_YELLOW+DISP_BGND_RED);

       OSTimeDly (1);

       OSMboxPost ( AckMbox , (void *) 1);

       }

}

NO2:

   Void main (void)

{

       OS_EVENT * MboxSem;

       OSInit();

       MboxSem = OSMboxCreate( ( void * ) 1 );

       OSStart();

}



Void Task1 ( void * pdata )

{

       INY8U err ;

       For ( ; ; ){

       OSMboxPend ( MboxSem , 0 , &err );

              .

              .

              .

       OSMboxPost ( MboxSem , (void *) 1 );

      }

}


沙发
ideafor|  楼主 | 2016-4-22 09:13 | 只看该作者
四.主要函数的介绍:
1.OS_EVENT  *OSMboxCreate (void*msg)
Description: This function waits for a message tobe sent to a mailbox
Arguments : msg is a pointer to a messagethat you wish to deposit in the mailbox. If you set this value tothe NULL pointer (i.e. (void *)0) then the mailbox will beconsidered empty.
Returns   : != (OS_EVENT *)0  is a pointer to the eventcontrol clock (OS_EVENT) associated with the createdmailbox
            ==(OS_EVENT *)0  if no event control blocks wereavailable
2.void  *OSMboxPend (OS_EVENT *pevent, INT16Utimeout, INT8U *err)
Description: This function waits for a message tobe sent to a mailbox
Arguments : pevent is a pointer to the eventcontrol block associated  with the desiredmailbox
Notes: when use OSMboxPend , the mailbox will beempty .
Returns   : != (void *)0  is a pointer to the messagereceived
             == (void *)0  if no message was received or , if'pevent'  is a NULL pointer or, if you didn't passthe proper pointer to the event control block.
3.INT8U  OSMboxPost (OS_EVENT *pevent, void*msg)
Description: This function sends a message to amailbox
Arguments  : pevent is a pointerto the event control block associated with the desiredmailbox.
             msgis a pointer to the message to send.  You MUST NOTsend a NULL pointer.
Returns   : OS_NO_ERR  The call wassuccessful and the message was sent

使用特权

评论回复
板凳
捉虫天师| | 2016-4-22 13:43 | 只看该作者
原来是采用了任务调度机制

使用特权

评论回复
地板
neeringstu| | 2016-4-22 23:03 | 只看该作者
感觉用邮箱还不如直接用全局数组方便呢

使用特权

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

本版积分规则

30

主题

149

帖子

1

粉丝