Chapter 10 Message Mailbox Management 1 Message Mailbox
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 • OSMbox. Create() – Creating a mailbox • OSMbox. Del() – Deleting a mailbox • OSMbox. Pend() – Waiting for a message • OSMbox. Accept() – Getting a message without waiting • OSMbox. Post() – Sending a message • OSMbox. Post. Opt() – OSMbox. Post++ • OSMbox. Query() – 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 0 x 00 cnt 0 x 00 NULL Point to msg 0 x 00 … 0 x 00 5
OSMbox. Create() 6
OSMbox. Del() 7
8
OSMbox. Pend() 9
OSMbox. Pend() 10
OSMbox. Post() 11
OSMbox. Post. Opt() • 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 OSMbox. Post()) – OS_POST_OPT_BROADCAST: post to all tasks that are waiting on the mailbox 12
13
OSMbox. Accept() 14
Using a Mailbox as a Binary Semaphore OS_EVENT *Mbox. Sem; void Task 1(void *pdata) { INT 8 U err; while(1) { OSMbox. Pend(Mbox. Sem, 0, &err); /*…*/ OSMbox. Post(Mbox. Sem, (void *)1); } } 15
- Slides: 15