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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

QueuesWhy queues?In the preceding chapter, intertask communication using mailboxes was described. Mailboxes can handle smallmessages with fixed data size only.Queues enable intertask communication with larger messages or with messages of various sizes.BasicsA queue consists of a data buffer and a control structure that is managed by the real-time operating system. The queuebehaves like a normal buffer; you can put something (called a message) in and retrieve it later. Queues work as FIFO:first in, first out. So a message that is put in first will be retrieved first.There are three major differences between queues and mailboxes:1 Queues accept messages of various size. When putting a message into a queue, the message size is passed as aparameter.2 Retrieving a message from the queue does not copy the message, but returns a pointer to the message and its size. Thisenhances performance because the data is copied only once, when the message is written into the queue.3 The retrieving function has to delete every message after processing it.Both the number and size of queues is limited only by the amount of available memory. Any data structure can bewritten into a queue. The message size is not fixed.Queues API function overviewRoutineOS_Q_Create()OS_Q_Put()OS_Q_GetPtr()OS_Q_GetPtrCond()OS_Q_GetPtrTimed()OS_Q_Purge()OS_Q_Clear()OS_Q_GetMessageCnt()Table 72: Queues APIOS_Q_Create()DescriptionCreates and initializes a message queue.DescriptionCreates and initializes a message queue.Stores a new message of given size in a queue.Retrieves a message from a queue.Retrieves a message from a queue, if one message is available or returns withoutsuspension.Retrieves a message from a queue within a specified time, if one message is available.Deletes the last retrieved message in a queue.Deletes all message in a queue.Returns the number of messages currently in a queue.PP<strong>RTOS</strong>-2 71

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

Saved successfully!

Ooh no, something went wrong!