This is an old revision of the document!
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.
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
Service | Arguments | Description | Properties |
---|---|---|---|
Creating | |||
OS_Queue_Create | (queue, buffer, size) | Create and clear queue. | |
Sending | |||
OS_Queue_Send | (queue, message) | Send message via queue. If queue full then wait for free place | |
OS_Queue_Send_TO | (queue, message, timeout) | Send message via queue. If queue full then wait for free place. Exit if timeout expired. | |
OS_Queue_Send_Now | (queue, message) | Send message via queue. If queue is full then most rearly message will be pushed out. | |
Checking | |||
bool OS_Queue_Check | (queue) | Check for there is any message in queue. | |
bool OS_Queue_IsFull | (queue) | Check for queue of messages is full. | |
bool OS_Queue_IsEmpty | (queue) | Check for queue of messages is empty. | |
Waiting | |||
OS_Queue_Wait | (queue, os_msg_type_var) | Wait message from queue. After accepting message will be deleted from queue. | |
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. |
Service | Arguments | Description | Properties |
---|---|---|---|
Creating | |||
OS_Squeue_Create | (squeue, buffer, size) | Create and clear queue. | |
Sending | |||
OS_Squeue_Send | (squeue, smessage) | Send simple message via queue. If queue full then wait for free place | |
OS_Squeue_Send_TO | (squeue, smessage, timeout) | Send message via queue. If queue full then wait for free place. Exit if timeout expired. | |
OS_Squeue_Send_Now | (squeue, smessage) | Send message via queue. If queue is full then most rearly message will be pushed out. | |
Checking | |||
bool OS_Squeue_Check | (squeue) | Check for there is any simple message in queue. | |
bool OS_Squeue_IsFull | (squeue) | Check for queue of simple messages is full. | |
bool OS_Squeue_IsEmpty | (squeue) | Check for queue of simple messages is empty. | |
Waiting | |||
OS_Squeue_Wait | (squeue, os_smsg_type_var) | Wait message from queue. After accepting message will be deleted from queue. | |
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. |