22
22
#ifndef QUEUE_H
23
23
#define QUEUE_H
24
24
25
- #include < stdint.h>
26
- #include < string.h>
27
-
28
25
#include " cmsis_os2.h"
26
+ #include " mbed_rtos1_types.h"
29
27
#include " mbed_rtos_storage.h"
30
28
#include " platform/mbed_error.h"
31
29
#include " platform/NonCopyable.h"
32
- #include " mbed_rtos1_types.h"
33
30
34
31
namespace rtos {
35
32
/* * \addtogroup rtos */
@@ -38,21 +35,31 @@ namespace rtos {
38
35
* \defgroup rtos_Queue Queue class
39
36
* @{
40
37
*/
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.
47
38
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
+ */
52
58
template <typename T, uint32_t queue_sz>
53
59
class Queue : private mbed ::NonCopyable<Queue<T, queue_sz> > {
54
60
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`
56
63
*
57
64
* @note You cannot call this function from ISR context.
58
65
*/
@@ -66,6 +73,7 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
66
73
_id = osMessageQueueNew (queue_sz, sizeof (T*), &attr);
67
74
MBED_ASSERT (_id);
68
75
}
76
+
69
77
/* * Queue destructor
70
78
*
71
79
* @note You cannot call this function from ISR context.
@@ -94,33 +102,82 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
94
102
return osMessageQueueGetSpace (_id) == 0 ;
95
103
}
96
104
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
+ */
109
142
osStatus put (T* data, uint32_t millisec=0 , uint8_t prio=0 ) {
110
143
return osMessageQueuePut (_id, &data, prio, millisec);
111
144
}
112
145
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
+ */
124
181
osEvent get (uint32_t millisec=osWaitForever) {
125
182
osEvent event;
126
183
T *data = NULL ;
@@ -155,6 +212,6 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
155
212
/* * @}*/
156
213
/* * @}*/
157
214
158
- }
159
- #endif
215
+ } // namespace rtos
160
216
217
+ #endif // QUEUE_H
0 commit comments