Available Languages?:

This is an old revision of the document!


OSA : Message queues

Intro

The message queue is most universal tool to data exchange between tasks. Queue allow to send next message before previous was received. There are two types of queues in OSA: for pointers to messages and for simple byte messages.

To use queues in you program you have to define constants in OSAcfg.h:

#define OS_ENABLE_QUEUE
                          // To use queues of pointers to messages
#define OS_ENABLE_SQUEUE
                          // To use queues of simple byte messages

When theese constants defined, compiler inserts functions to work with queue in you code.

Queues are declared through variables of queue type: OST_QUEUE and OST_SQUEUE:

OST_QUEUE  queue;    // Declare queue of pointer to messages
OST_SQUEUE squeue;   // Declare queue of simple byte messages

Variable of OST_QUEUE (or OST_SQUEUE) type contains information of queue size, number of existing messages and pointer to buffer of messages. Buffer of messages is an array in RAM where sent messages will be stored to:

OST_MSG   msg_queue[10];         // Buffer for 10 pointer to messages
OST_SMSG  smsg_queue[15];        // Buffer for 15 simple byte messages

To work with queue we have to create it by service OS_Queue_Create (or OS_Squeue_Create):

    OS_Queue_Create(queue, msg_queue, 10);  // Create queue of 10 pointer to messages.
                                         // Sent messages will be stored in msg_queue array

After creating queue we can send and accept messages through queue.

For PIC16 queue descriptor and message buffer can be allocated in bank0 and bank1 only.

Combination

When it is supposed that sizes of OST_MSG and OST_SMSG are same, we can to combine queue functions. This will reduce ROM usage. To do it we have to define constant in OSAcfg.h:

#define OS_QUEUE_SQUEUE_IDENTICAL

Services

Queue of pointers to message

Service Arguments Description Properties
Creating
OS_Queue_Create (queue, buffer, size) Create and clear queue. Not allowed in interrupt
Sending
OS_Queue_Send (queue, message) Send message via queue. If queue full then wait for free place Allowed only in taskSwitches contexts
OS_Queue_Send_TO (queue, message, timeout) Send message via queue. If queue full then wait for free place. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer
OS_Queue_Send_Now (queue, message) Send message via queue. If queue is full then most rearly message will be pushed out. Have alternate service for work in ISR (suffix "_I")
Checking
bool
OS_Queue_Check
(queue) Check for there is any message in queue. Have alternate service for work in ISR (suffix "_I")
bool
OS_Queue_IsFull
(queue) Check for queue of messages is full. Have alternate service for work in ISR (suffix "_I")
bool
OS_Queue_IsEmpty
(queue) Check for queue of messages is empty. Have alternate service for work in ISR (suffix "_I")
Waiting
OS_Queue_Wait (queue, os_msg_type_var) Wait message from queue. After accepting message will be deleted from queue. Allowed only in taskSwitches contexts
OS_Queue_Wait_TO (queue, os_msg_type_var, timeout) Wait message from queue. After accepting message will be deleted from queue. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer

Queue of simple messages

Service Arguments Description Properties
Creating
OS_Squeue_Create (squeue, buffer, size) Create and clear queue. Not allowed in interrupt
Sending
OS_Squeue_Send (squeue, smessage) Send simple message via queue. If queue full then wait for free place Allowed only in taskSwitches contexts
OS_Squeue_Send_TO (squeue, smessage, timeout) Send message via queue. If queue full then wait for free place. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer
OS_Squeue_Send_Now (squeue, smessage) Send message via queue. If queue is full then most rearly message will be pushed out. Have alternate service for work in ISR (suffix "_I")
Checking
bool
OS_Squeue_Check
(squeue) Check for there is any simple message in queue. Have alternate service for work in ISR (suffix "_I")
bool
OS_Squeue_IsFull
(squeue) Check for queue of simple messages is full. Have alternate service for work in ISR (suffix "_I")
bool
OS_Squeue_IsEmpty
(squeue) Check for queue of simple messages is empty. Have alternate service for work in ISR (suffix "_I")
Waiting
OS_Squeue_Wait (squeue, os_smsg_type_var) Wait message from queue. After accepting message will be deleted from queue. Allowed only in taskSwitches contexts
OS_Squeue_Wait_TO (squeue, os_smsg_type_var, timeout) Wait message from queue. After accepting message will be deleted from queue. Exit if timeout expired. Allowed only in taskSwitches contextsService uses system timer
 
en/osa/ref/services/mesage_queues.1260572745.txt.gz · Last modified: 12.12.2009 02:05 by osa_chief
 
Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki