Sunteți pe pagina 1din 15

Chapter 10:

Message Mailbox Management

1
Message Mailbox Management

• A message mailbox is a μC/OS-II object that


allows a task or an ISR to send a pointer-sized
variable to another task.

• The content of the mailbox is a pointer to a


message. What the pointer point to is
application specific.

2
Functions
• OSMboxCreate()
– Creating a mailbox
• OSMboxDel()
– Deleting a mailbox
• OSMboxPend()
– Waiting for a message
• OSMboxAccept()
– Getting a message without waiting
• OSMboxPost()
– Sending a message
• OSMboxPostOpt()
– OSMboxPost++
• OSMboxQuery()
– Obtaining the status

3
Tasks, ISRs and a
message mailbox

4
OS_EVENT_TYPE_SEM &
OS_EVENT_TYPE_MBOX

OS_EVENT_TYPE_SEM OS_EVENT_TYPE_MBOX
0x00 0x00
cnt 0x00
NULL Point to msg
0x00 … 0x00 0x00 … 0x00

5
OSMboxCreate()

6
OSMboxDel()

7
8
OSMboxPend()

9
OSMboxPend()

10
OSMboxPost()

11
OSMboxPostOpt()
• pevent
a pointer to the event control block associated with the
desired mailbox
• msg
a pointer to the message to send. You must not send a null
pointer.
• opt
determines the type of POST performed:
– OS_POST_OPT_NONE: post to a single waiting task
(Identical to OSMboxPost())
– OS_POST_OPT_BROADCAST: post to all tasks that are
waiting on the mailbox

12
13
OSMboxAccept()

14
Using a Mailbox as a Binary Semaphore

OS_EVENT *MboxSem;

void Task1(void *pdata) {


INT8U err;
while(1) {
OSMboxPend(MboxSem, 0, &err);
/*…*/
OSMboxPost(MboxSem, (void *)1);
}
}

15

S-ar putea să vă placă și