Message queues
Communications between application tasks on a node are implemented via message queues. The application can create a dedicated message queue for a particular communication channel. A set of functions are provided to implement message queues, as indicated in Section 6.9.1.1below (these functions are detailed in Section10.1). The stack requires certain standard queues, as indicated in Section 6.9.1.2 below.
Note: To allow the device to enter sleep mode, the message queues must not contain any messages. All message queues must first be emptied.
General queue management
A queue can be created using the function ZQ_vZQueueCreate(). This function allows the queue size (number of messages that it can hold) and the size of a message to be specified. A queue is given a unique handle, which is a pointer to a tszQueue
structure containing up-to-date information about the queue (see Section101.2.1).
A message can be placed in a (created) queue using the function ZQ_bZQueueSend() and a message can be retrieved from a queue using the function ZQ_bZQueueReceive(). This is illustrated in the following figure.
Sending/Receiving a Message via a Message Queue
When the above two functions are called, the tszQueue
structure for the queue is automatically updated to reflect the new state of the queue. Retrieving a message results in the message being deleted from the queue. The application must regularly poll a message queue through which it expects to receive messages. It can do this by periodically calling the ZQ_bQueueIsEmpty() function, which checks whether the queue is empty. If the queue is not empty, it should call ZQ_bZQueueReceive() until there are no more messages in the queue. The number of messages currently waiting to be collected from the queue can be obtained using the function ZQ_u32QueueGetQueueMessageWaiting().
Parent topic:Message queues
Standard stack queues
Three standard queues must be created by the application for use by the stack:
Queue with handle zps_msgMlmeDcfmInd to receive IEEE 802.15.4 MAC command packets from other nodes
Queue with handle zps_msgMcpsDcfmInd to receive IEEE 802.15.4 MAC data packets from other nodes
Queue with handle zps_TimeEvents to receive internal software timer events (such as a timer expiry event)
Example code for the creation of these queues is provided below:
ZQ_vZQueueCreate(&zps_msgMlmeDcfmInd, MLME_QUEUE_SIZE, sizeof(MAC_tsMlmeVsDcfmInd),(uint8*)asMacMlmeVsDcfmInd);
ZQ_vZQueueCreate(&zps_msgMcpsDcfmInd, MCPS_QUEUE_SIZE, sizeof(MAC_tsMcpsVsDcfmInd),(uint8*)asMacMcpsDcfmInd);
ZQ_vQueueCreate(&zps_TimeEvents,TIMER_QUEUE_SIZE,sizeof(zps_tsTimeEvent), (uint8*)asTimeEvent);
You simply need to include the above code in your application. You do not need to process these queues in your code.
More information on the receive queues is provided in Received message queues.
Parent topic:Message queues
Parent topic:Using support software features