sys/bios---邮箱

来源:互联网 发布:魅族手机移动数据开关 编辑:程序博客网 时间:2024/06/15 13:43
1 邮箱的创建
    邮箱的创建有静态和动态方式,下面以动态创建方式为例
1
typedef struct _MSG_POS{
2
    Uint16 Id;
3
    Uint32 Value[6];
4
}MSG_POS;
5
6
Mailbox_Handle gh_MboxPos;
7
Error_Block eb;
8
// Create Mailbox
9
Mailbox_Params mboxParams;
10
Mailbox_Params_init(&mboxParams);
11
gh_MboxPos = Mailbox_create(sizeof(MSG_POS),5,&mboxParams,&eb);
在Mailbox_create中,第一个参数表示邮箱传递消息的字节数,第二个参数表示邮箱消息的最大数量。

2 邮箱的发送和挂起
void task1(void){    ...    // send mail    Mailbox_post(gh_MboxPos,&msg,time_out);    ...}void task2(void){    ...    // wait mail    Mailbox_pend(gh_MboxPos,&msg,time_out);    ...}
第一个参数为邮箱句柄,第二个参数为传递的消息地址,第三个表示超时时间。

3 具体应用说明
这里可以将邮箱理解为一个first in first out的队列,Mailbox_post表示向队列写数据,Mailbox_pend表示向队列读数据,如果队列数据存满了,那么就无法向队列再写新的数据。
如果队列已满,执行Mailbox_post则返回0,在time_out为BIOS_WAIT_FOREVER情况下,则任务被挂起,直到队列可以写数据。
如果队列为空,执行Mailbox_pend则返回0,在time_out为BIOS_WAIT_FOREVER情况下,则任务被挂起,直到队列有数据。

{
3
    ...
4
    // send mail
5
    Mailbox_post(gh_MboxPos,&msg,time_out);
6
    ...
7
}
8
9
void task2(void)
10
{
11
    ...
12
    // wait mail
13
    Mailbox_pend(gh_MboxPos,&msg,time_out);
14
    ...
15
}
原创粉丝点击