Skip to content

Commit a5bb524

Browse files
Steve CartmellCruz Monrreal II
authored andcommitted
docs(api-queue): Update documentation for the Queue API
1 parent b7c0fbd commit a5bb524

File tree

1 file changed

+97
-40
lines changed

1 file changed

+97
-40
lines changed

rtos/Queue.h

Lines changed: 97 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
#ifndef QUEUE_H
2323
#define QUEUE_H
2424

25-
#include <stdint.h>
26-
#include <string.h>
27-
2825
#include "cmsis_os2.h"
26+
#include "mbed_rtos1_types.h"
2927
#include "mbed_rtos_storage.h"
3028
#include "platform/mbed_error.h"
3129
#include "platform/NonCopyable.h"
32-
#include "mbed_rtos1_types.h"
3330

3431
namespace rtos {
3532
/** \addtogroup rtos */
@@ -38,21 +35,31 @@ namespace rtos {
3835
* \defgroup rtos_Queue Queue class
3936
* @{
4037
*/
41-
42-
/** The Queue class allow to control, send, receive, or wait for messages.
43-
A message can be a integer or pointer value to a certain type T that is send
44-
to a thread or interrupt service routine.
45-
@tparam T data type of a single message element.
46-
@tparam queue_sz maximum number of messages in queue.
4738

48-
@note
49-
Memory considerations: The queue control structures will be created on current thread's stack, both for the mbed OS
50-
and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
51-
*/
39+
/** The Queue class represents a collection of objects that are stored first by
40+
* order of priorty, and then in first-in, first-out (FIFO) order.
41+
*
42+
* A queue is used to when data needs to stored and then accessed in the same
43+
* order that it has been stored. The order in which they are retrieved is in
44+
* order of descending priority, if multiple elements have the same priority
45+
* they are retrieved in FIFO order.
46+
*
47+
* The object type stored in the queue can be an integer, pointer, or a generic
48+
* type given by the template parameter T.
49+
*
50+
* @tparam T Specifies the type of elements that are stored in the queue.
51+
* @tparam queue_sz Maximum number of messages that can be stored in the queue.
52+
*
53+
* @note Memory considerations: The queue control structures will be created on
54+
* current thread's stack, both for the mbed OS and underlying RTOS
55+
* objects (static or dynamic RTOS memory pools are not being used).
56+
*
57+
*/
5258
template<typename T, uint32_t queue_sz>
5359
class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
5460
public:
55-
/** Create and initialize a message Queue.
61+
/** Create and initialize a message Queue of objects of the parameterized
62+
* type `T` and maximum capacity specified by `queue_sz`
5663
*
5764
* @note You cannot call this function from ISR context.
5865
*/
@@ -66,6 +73,7 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
6673
_id = osMessageQueueNew(queue_sz, sizeof(T*), &attr);
6774
MBED_ASSERT(_id);
6875
}
76+
6977
/** Queue destructor
7078
*
7179
* @note You cannot call this function from ISR context.
@@ -94,33 +102,82 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
94102
return osMessageQueueGetSpace(_id) == 0;
95103
}
96104

97-
/** Put a message in a Queue.
98-
@param data message pointer.
99-
@param millisec timeout value or 0 in case of no time-out. (default: 0)
100-
@param prio priority value or 0 in case of default. (default: 0)
101-
@return status code that indicates the execution status of the function:
102-
@a osOK the message has been put into the queue.
103-
@a osErrorTimeout the message could not be put into the queue in the given time.
104-
@a osErrorResource not enough space in the queue.
105-
@a osErrorParameter internal error or non-zero timeout specified in an ISR.
106-
107-
@note You may call this function from ISR context if the millisec parameter is set to 0.
108-
*/
105+
/** Inserts the given element to the end of the queue.
106+
*
107+
* This function puts the message pointed to by `data` into the queue. The
108+
* parameter `prio` is used to sort the message according to their priority
109+
* (higher numbers indicate higher priority) on insertion.
110+
*
111+
* The timeout indicated by the parameter `millisec` specifies how long the
112+
* function will block waiting for the message to be inserted into the
113+
* queue.
114+
*
115+
* The parameter `millisec` can have the following values:
116+
* - When the timeout is 0 (the default), the function returns instantly.
117+
* - When the timeout is osWaitForever the function will wait for an
118+
* infinite time.
119+
* - For all other values the function will wait for the given number of
120+
* milliseconds.
121+
*
122+
* @param data Pointer to the element to insert into the queue.
123+
* @param millisec Timeout for the operation to be executed, or 0 in case
124+
* of no-timeout. (default: 0)
125+
* @param prio Priority of the operation or 0 in case of default.
126+
* (default: 0)
127+
*
128+
* @return Status code that indicates the execution status of the function:
129+
* @a osOK The message has been successfully inserted
130+
* into the queue.
131+
* @a osErrorTimeout The message could not be inserted into the
132+
* queue in the given time.
133+
* @a osErrorResource The message could not be inserted because
134+
* the queue is full.
135+
* @a osErrorParameter Internal error or non-zero timeout specified
136+
* in an ISR.
137+
*
138+
* @note You may call this function from ISR context if the millisec
139+
* parameter is set to 0.
140+
*
141+
*/
109142
osStatus put(T* data, uint32_t millisec=0, uint8_t prio=0) {
110143
return osMessageQueuePut(_id, &data, prio, millisec);
111144
}
112145

113-
/** Get a message or Wait for a message from a Queue. Messages are retrieved in a descending priority order or
114-
first in first out when the priorities are the same.
115-
@param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
116-
@return event information that includes the message in event.value and the status code in event.status:
117-
@a osEventMessage message received.
118-
@a osOK no message is available in the queue and no timeout was specified.
119-
@a osEventTimeout no message has arrived during the given timeout period.
120-
@a osErrorParameter a parameter is invalid or outside of a permitted range.
121-
122-
@note You may call this function from ISR context if the millisec parameter is set to 0.
123-
*/
146+
/** Get a message or wait for a message from the queue.
147+
*
148+
* This function retrieves a message from the queue. The message is stored
149+
* in the value field of the returned `osEvent` object.
150+
*
151+
* The timeout specified by the parameter `millisec` specifies how long the
152+
* function will wait to retrieve the message from the queue.
153+
*
154+
* The timeout parameter can have the following values:
155+
* - When the timeout is 0, the function returns instantly.
156+
* - When the timeout is osWaitForever (default), the function will wait
157+
* infinite time until the message is retrieved.
158+
* - When the timeout is any other value the function will wait for th
159+
* specified time before returning a timeout error.
160+
*
161+
* Messages are retrieved in descending priority order. If two messages
162+
* share the same priority level they are retrieved in first-in, first-out
163+
* (FIFO) order.
164+
*
165+
* @param millisec Timeout value or 0 in case of no time-out.
166+
* (default: osWaitForever).
167+
*
168+
* @return Event information that includes the message in event. Message
169+
* value and the status code in event.status:
170+
* @a osEventMessage Message successfully received.
171+
* @a osOK No message is available in the queue and no
172+
* timeout was specified.
173+
* @a osEventTimeout No message was received before a timeout
174+
* event occurred.
175+
* @a osErrorParameter A parameter is invalid or outside of a
176+
* permitted range.
177+
*
178+
* @note You may call this function from ISR context if the millisec
179+
* parameter is set to 0.
180+
*/
124181
osEvent get(uint32_t millisec=osWaitForever) {
125182
osEvent event;
126183
T *data = NULL;
@@ -155,6 +212,6 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
155212
/** @}*/
156213
/** @}*/
157214

158-
}
159-
#endif
215+
} // namespace rtos
160216

217+
#endif // QUEUE_H

0 commit comments

Comments
 (0)