11.07.2015 Views

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MailboxesWhy mailboxes?In the preceding chapters, task synchronization by the use of semaphores was described. Unfortunately, semaphorescannot transfer data from one task to another. If we need to transfer data between tasks via a buffer for example, wecould use a resource semaphore every time we accessed the buffer. But doing so would make the program less efficient.Another major disadvantage would be that we could not access the buffer from an interrupt handler, because theinterrupt handler is not allowed to wait for the resource semaphore.One way out would be the usage of global variables. In this case we would have to disable interrupts every time and inevery place that we accessed these variables. This is possible, but it is a path full of pitfalls. It is also not easy for a taskto wait for a character to be placed in a buffer without polling the global variable that contains the number of charactersin the buffer. Again, there is a way out - the task could be notified by an event signaled to the task every time a characteris placed in the buffer. That is why there is an easier way to do this with a real-time OS:The use of mailboxes.BasicsA mailbox is a buffer that is managed by the real-time operating system. The buffer behaves like a normal buffer; youcan put something (called a message) in and retrieve it later. Mailboxes usually work as FIFO: first in, first out. So amessage that is put in first will usually be retrieved first. "Message" might sound abstract, but very simply just means"item of data". It will become clearer in the typical applications explained in the following section.The number of mailboxes is limited only by the amount of available memory.Message size: 1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!