ME507 Utility Library  0.2.1
Mechatronics Course Support Software for ARM/Arduino/FreeRTOS
taskqueue.h
Go to the documentation of this file.
1 /** @file taskqueue.h
2  * This file contains a very simple wrapper class for the FreeRTOS queue.
3  * It makes using the queue just a little bit easier in C++ than it is in C.
4  * This version has been tested on STM32's and ESP32's only because the
5  * insertion and extraction operators @c << and @c >> need specific
6  * functions to determine if they're running in ISR's or not.
7  *
8  * @date 2012-Oct-21 JRR Original file
9  * @date 2014-Aug-26 JRR Changed file names and queue class name to Queue
10  * @date 2020-Oct-10 JRR Made compatible with Arduino/FreeRTOS environment
11  * @date 2020-Nov-18 JRR Added @c << and @c >> operators for ESP32 and STM32
12  * @date 2021-Sep-19 JRR Added overloads of @c get(), @c ISR_get(), @c peek(),
13  * and @c ISR_peek() which return copies
14  *
15  * License:
16  * This file is copyright 2012-2020 by JR Ridgely and released under the
17  * Lesser GNU Public License, version 2. It intended for educational use
18  * only, but its use is not limited thereto. */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIB-
23  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29  * THE POSSIBILITY OF SUCH DAMAGE. */
30 
31 // This define prevents this .h file from being included more than once
32 #ifndef _TASKQUEUE_H_
33 #define _TASKQUEUE_H_
34 
35 #include <Arduino.h>
36 #include "FreeRTOS.h" // Main header for FreeRTOS
37 #include "baseshare.h"
38 
39 
40 /** @brief Implements a queue to transmit data from one RTOS task to another.
41  * @details Since multithreaded tasks must not use unprotected shared data
42  * items for communication, queues are a primary means of intertask
43  * communication. Other means include shared data items (see
44  * @c taskshare.h) and carrier pigeons. The use of a C++ class
45  * template allows the compiler to check that you're putting the
46  * correct type of data into each queue and getting the correct type
47  * of data out, thus helping to prevent programming mistakes that can
48  * corrupt your data.
49  *
50  * As a template class, @c Queue<dataType> can be used to make
51  * queues which hold data of many types. "Plain Old Data" types such
52  * as @c bool or @c uint16_t are supported, of course. But you can
53  * also use queues which hold compound data types. For example, if
54  * you have @c class @c my_data which holds several measurements
55  * together in an object, you can make a queue for @c my_data objects
56  * with @c Queue<my_data>. Each item in the queue will then hold
57  * several measurements.
58  *
59  * The size of FreeRTOS queues is limited to 255 items in 8-bit
60  * microcontrollers whose @c portBASE_TYPE is an 8-bit number. This
61  * is a FreeRTOS feature.
62  *
63  * Normal writing and reading are done with methods @c put() and
64  * @c get(). Normal writing means that the sending task must wait
65  * until there is empty space in the queue, and then it puts a data
66  * item into the "back" of the queue, where "back" means that the
67  * item in the back of the queue will be read after all items that
68  * were previously put into the queue have been read. Normal reading
69  * means that when an item is read from the front of the queue, it
70  * will then be removed, making space for more items at the back.
71  * This process is often used to synchronize tasks, as the reading
72  * task's @c get() method blocks, meaning that the reading task gets
73  * stuck waiting for an item to arrive in the queue; it won't do
74  * anything useful until new data has been read. Note that this is
75  * acceptable behavior in an RTOS because the RTOS scheduler will
76  * ensure that other tasks get to run even while the reading task
77  * is blocking itself waiting for data.
78  *
79  * In some cases, one may need to use less normal reading and writing
80  * methods. Methods whose name begins with @c ISR_ are to be used
81  * only within a hardware interrupt service routine. If there is a
82  * need to put data at the front of the queue instead of the back,
83  * use @c butt_in() instead of @c put(). If one needs to read data
84  * from the queue without removing that data, the @c look_at() method
85  * allows this to be done. If something particularly unusual needs to
86  * be done with the queue, one can use the method @c get_handle() to
87  * retrieve the handle used by the C language functions in FreeRTOS
88  * to access the Queue object's underlying data structure directly.
89  *
90  * @section queue_usage Usage
91  * The following bits of code show how to set up and use a queue to
92  * transfer data of type @c int16_t from one hypothetical task
93  * called @c task_A to another called @c task_B.
94  *
95  * Near the top of the file which contains @c setup() we create a
96  * queue. The constructor of the @c Queue<int16_t> class is given the
97  * number of items in the queue (10 in this example) and an optional
98  * name for the queue:
99  * @code
100  * #include "taskqueue.h"
101  * ...
102  * /// This queue holds hockey puck accelerations
103  * Queue<int16_t> hockey_queue (10, "Puckey");
104  * @endcode
105  * In a location which is before we use the queue in any other file
106  * than the one in which the queue was created, we re-declare the
107  * queue with the keyword @c extern to make it accessible to any task
108  * within that file:
109  * @code
110  * extern Queue<int16_t> hockey_queue;
111  * @endcode
112  * In the sending task, data is put into the queue:
113  * @code
114  * int16_t an_item = -3; ///< Local acceleration data
115  * ...
116  * an_item = stick_sensor.get_data (2); // Read data from sensor
117  * hockey_queue.put (a_data_item); // Put data into queue
118  * @endcode
119  * In the receiving task, data is read from the queue. In typical
120  * usage, the call to @c get() will block the receiving task until
121  * data has been put into the queue by the sending task:
122  * @code
123  * int16_t data_we_got; ///< Holds received data
124  * ...
125  * hockey_queue.get (data_we_got); // Get data from the queue
126  * @endcode
127  */
128 template <class dataType> class Queue : public BaseShare
129 {
130 // This protected data can only be accessed from this class or its
131 // descendents
132 protected:
133  QueueHandle_t handle; ///< Hhandle for the FreeTOS queue
134  TickType_t ticks_to_wait; ///< RTOS ticks to wait for empty
135  uint16_t buf_size; ///< Size of queue buffer in bytes
136  uint16_t max_full; ///< Maximum number of bytes in queue
137 
138 // Public methods can be called from anywhere in the program where there is
139 // a pointer or reference to an object of this class
140 public:
141  // The constructor creates a FreeRTOS queue
142  Queue (BaseType_t queue_size, const char* p_name = NULL,
143  TickType_t = portMAX_DELAY);
144 
145  // Put an item into the queue behind other items.
146  bool put (const dataType item);
147 
148  // This method puts an item of data into the back of the queue from
149  // within an interrupt service routine. It must not be used within
150  // non-ISR code.
151  bool ISR_put (const dataType item);
152 
153  /** @brief Put an item into the front of the queue to be retrieved
154  * first.
155  * @details This method puts an item into the front of the queue so
156  * that it will be received first as long as nothing else is
157  * put in front of it. This is not the normal way to put
158  * things into a queue; using @c put() to put items into the
159  * back of the queue is. If you always use this method,
160  * you're making a stack rather than a queue, you weirdo.
161  * This method must @b not be used within an interrupt
162  * service routine.
163  * @param item The item which is going to be (rudely) put into the front
164  * of the queue
165  * @return @c True if the item was successfully queued, false if not
166  */
167  bool butt_in (const dataType item)
168  {
169  return ((bool)(xQueueSendToFront (handle, &item, ticks_to_wait)));
170  }
171 
172  // This method puts an item into the front of the queue from within
173  // an ISR. It must not be used within normal, non-ISR code.
174  bool ISR_butt_in (const dataType item);
175 
176  /** @brief Return true if the queue is empty.
177  * @details This method checks if the queue is empty. It returns
178  * @c true if there are no items in the queue and @c false if
179  * there are items.
180  * @return @c true if the queue is empty, @c false if it's not empty
181  */
182  bool is_empty (void)
183  {
184  return (uxQueueMessagesWaiting (handle) == 0);
185  }
186 
187  /** @brief Return true if the queue is empty, from within an ISR.
188  * @details This method checks if the queue is empty from within an
189  * interrupt service routine. It must @b not be used in normal
190  * non-ISR code.
191  * @return @c true if the queue is empty, @c false if it's not empty
192  */
193  bool ISR_is_empty (void)
194  {
195  return (uxQueueMessagesWaitingFromISR (handle) == 0);
196  }
197 
198  /** @brief Retrieve and remove the item at the head of the queue.
199  * @details This method gets the item at the head of the queue and removes
200  * that item from the queue. If there's nothing in the queue,
201  * this method waits, blocking the calling task, for the number
202  * of RTOS ticks specified in the @c wait_time parameter to the
203  * queue constructor (the default is forever) or until something
204  * shows up.
205  * @param recv_item A reference to the item to be filled with data from
206  * the queue
207  */
208  void get (dataType& recv_item)
209  {
210  // If xQueueReceive doesn't return pdTrue, nothing was found in the
211  // queue, so no changes are made to the item
212  xQueueReceive (handle, &recv_item, ticks_to_wait);
213  }
214 
215  /** @brief Retrieve, remove, and return the item at the head of the queue.
216  * @details This method gets the item at the head of the queue and removes
217  * it from the queue. A copy of the item's contents is returned.
218  * If there's nothing in the queue, this method waits, blocking
219  * the calling task, for the number of RTOS ticks specified in
220  * the @c wait_time parameter to the queue constructor (the
221  * default is forever) or until something shows up.
222  * @returns A copy of the contents of the queue item
223  */
224  dataType get (void)
225  {
226  dataType return_this;
227  xQueueReceive (handle, &return_this, ticks_to_wait);
228  return return_this;
229  }
230 
231  /** @brief Remove the item at the head of the queue from within an ISR.
232  * @details This method gets and returns the item at the head of the queue
233  * from within an interrupt service routine. This method must
234  * @b not be called from within normal non-ISR code.
235  * @param recv_item A reference to the item to be filled with data from
236  * the queue
237  */
238  void ISR_get (dataType& recv_item)
239  {
240  portBASE_TYPE task_awakened; // Checks if context switch needed
241 
242  // If xQueueReceive doesn't return pdTrue, nothing was found in the
243  // queue, so we won't change the data referenced in the parameter
244  xQueueReceiveFromISR (handle, &recv_item, &task_awakened);
245  }
246 
247  /** @brief Retrieve, remove, and return the item at the head of the queue
248  * when called by ISR code.
249  * @details This method gets the item at the head of the queue and removes
250  * it from the queue. A copy of the item's contents is returned.
251  * This method must @b not be called from within normal non-ISR
252  * code.
253  * @returns A copy of the contents of the queue item
254  */
255  dataType ISR_get (void)
256  {
257  portBASE_TYPE task_awakened; // Checks if context switch needed
258 
259  dataType return_this;
260  xQueueReceiveFromISR (handle, &return_this, &task_awakened);
261  return return_this;
262  }
263 
264  /** @brief Get the item at the queue head without removing it.
265  * @details This method gets the item at the head of the queue without
266  * removing that item from the queue. If there's nothing in the
267  * queue this method waits, blocking the calling task, for for
268  * the number of RTOS ticks specified in the @c wait_time
269  * parameter to the queue constructor (the default is forever) or
270  * until something shows up. This method must @b not be called
271  * from within an interrupt service routine.
272  * @param recv_item A reference to a variable to be filled with data
273  * from the queue item
274  */
275  void peek (dataType& recv_item)
276  {
277  // If xQueueReceive doesn't return pdTrue, nothing was found in the
278  // queue, so don't change the item
279  xQueuePeek (handle, &recv_item, ticks_to_wait);
280  }
281 
282  /** @brief Return a copy of the item at the queue head without removing
283  * it.
284  * @details This method returns the item at the head of the queue without
285  * removing that item from the queue. If there's nothing in the
286  * queue this method waits, blocking the calling task, for for
287  * the number of RTOS ticks specified in the @c wait_time
288  * parameter to the queue constructor (the default is forever) or
289  * until something shows up. This method must @b not be called
290  * from within an interrupt service routine.
291  * @returns A copy of the data in the item at the head of the queue
292  */
293  dataType peek (void)
294  {
295  dataType recv_item;
296  xQueuePeek (handle, &recv_item, ticks_to_wait);
297  return recv_item;
298  }
299 
300  /** @brief Get the item at the front of the queue without deleting it,
301  * from within an ISR.
302  * @details This method returns the item at the head of the queue without
303  * removing that item from the queue. If there's nothing in the
304  * queue, this method doesn't change the value of the data given
305  * as its parameter. This method must @b only be called within an
306  * interrupt service routine.
307  * @param recv_item A reference to the item to be filled with data from
308  * the queue
309  */
310  void ISR_peek (dataType& recv_item)
311  {
312  portBASE_TYPE task_awakened; // Checks if a task will wake up
313 
314  // If xQueueReceive doesn't return pdTrue, nothing was found in the
315  // queue, so the value of recv_item is not changed
316  xQueuePeekFromISR (handle, &recv_item, &task_awakened);
317  }
318 
319  /** @brief Return a copy of the item at the front of the queue without
320  * deleting it, from within an ISR.
321  * @details This method returns the item at the head of the queue without
322  * removing that item from the queue. If there's nothing in the
323  * queue, this method returns a default value of the type of data
324  * in the queue. This method must @b only be called within an
325  * interrupt service routine.
326  * @returns A copy of the data in the queue
327  */
328  dataType ISR_peek (void)
329  {
330  portBASE_TYPE task_awakened; // Checks if a task will wake up
331  dataType recv_item;
332  xQueuePeekFromISR (handle, &recv_item, &task_awakened);
333  return recv_item;
334  }
335 
336  /** @brief Return true if the queue has contents which can be read.
337  * @details This method allows one to check if the queue has any
338  * contents. It must @b not be called from within an
339  * interrupt service routine.
340  * @return @c true if there's something in the queue, @c false if not
341  */
342  bool any (void)
343  {
344  return (uxQueueMessagesWaiting (handle) != 0);
345  }
346 
347  /** @brief Operator which inserts data into the queue.
348  * @details This convenient operator puts data into the queue, protecting
349  * the data from corruption by thread switching. It checks if the
350  * processor is currently in an interupt service routine (ISR);
351  * if so, it calls ISR specific functions to prevent corruption,
352  * so this function may be used within an ISR or outside one. It
353  * runs a little more slowly than the @c put() method.
354  * @param new_data The data which is to be put into the queue
355  */
356  void operator << (dataType new_data)
357  {
358  if (CHECK_IF_IN_ISR ())
359  {
360  ISR_put (new_data);
361  }
362  else
363  {
364  put (new_data);
365  }
366  }
367 
368  /** @brief Read data from the queue.
369  * @details This method is used to read data from the queue . The
370  * retrieved data is copied into the variable which is given as
371  * this method's parameter, replacing the previous contents. This
372  * method checks if the processor is currently in an interupt
373  * service routine (ISR) and if so, it calls ISR specific
374  * functions to prevent corruption, so this function may be used
375  * within an ISR or outside one. It runs a little more slowly
376  * than the @c get() method.
377  * @param put_here A reference to the variable in which to put received
378  * data
379  */
380  void operator >> (dataType& put_here)
381  {
382  if (CHECK_IF_IN_ISR ())
383  {
384  portBASE_TYPE task_awakened; // Checks if context switch needed
385 
386  // Copy the data from the queue into the receiving variable
387  xQueueReceiveFromISR (handle, &put_here, &task_awakened);
388  }
389  else
390  {
391  xQueueReceive (handle, &put_here, ticks_to_wait);
392  }
393  }
394 
395  /** @brief Return true if the queue has items in it, from within an
396  * ISR.
397  * @details This method allows one to check if the queue has any
398  * contents from within an interrupt service routine. It must
399  * @b not be called from within normal, non-ISR code.
400  * @return @c true if there's something in the queue, @c false if not
401  */
402  bool ISR_any (void)
403  {
404  return (uxQueueMessagesWaitingFromISR (handle) != 0);
405  }
406 
407  /** @brief Return the number of items in the queue.
408  * @details This method returns the number of items waiting in the
409  * queue. It must @b not be called from within an interrupt
410  * service routine; the method @c ISR_num_items_in() can be
411  * called from within an ISR.
412  * @return The number of items in the queue
413  */
414  unsigned portBASE_TYPE available (void)
415  {
416  return (uxQueueMessagesWaiting (handle));
417  }
418 
419  /** @brief Return the number of items in the queue, to an ISR.
420  * @details This method returns the number of items waiting in the
421  * queue; it must be called only from within an interrupt
422  * service routine.
423  * @return The number of items in the queue
424  */
425  unsigned portBASE_TYPE ISR_available (void)
426  {
427  return (uxQueueMessagesWaitingFromISR (handle));
428  }
429 
430  /** @brief Print the queue's status to a serial device.
431  * @details This method makes a printout of the queue's status on
432  * the given serial device, then calls this same method
433  * for the next item of thread-safe data in the linked list
434  * of items.
435  * @param print_dev Reference to the serial device on which to print
436  */
437  void print_in_list (Print& print_dev);
438 
439  /** @brief Indicates whether this queue is usable.
440  * @details This method returns a value which is @c true if this queue
441  * has been successfully set up and can be used.
442  * @returns @c true if this queue is usable, @c false if not
443  */
444  bool usable (void)
445  {
446  return (bool)handle;
447  }
448 
449  /** @brief Return a handle to the FreeRTOS structure which runs this
450  * queue.
451  * @details If somebody wants to do something which FreeRTOS queues
452  * can do but this class doesn't support, a handle for the
453  * queue wrapped by this class can be used to access the
454  * queue directly. This isn't commonly done.
455  * @return The handle of the FreeRTOS queue which is wrapped within
456  * this C++ class
457  */
458  QueueHandle_t get_handle (void)
459  {
460  return handle;
461  }
462 }; // class Queue
463 
464 
465 /** @brief Construct a queue object, allocating memory for the buffer.
466  * @details This constructor creates the FreeRTOS queue which is wrapped by
467  * the @c Queue class.
468  * @param queue_size The number of items which can be stored in the queue
469  * @param p_name A name to be shown in the list of task shares (default
470  * empty String)
471  * @param wait_time How long, in RTOS ticks, to wait for a queue to become
472  * empty before a character can be sent. (Default: @c portMAX_DELAY,
473  * which causes the sending task to block until sending occurs.)
474  */
475 template <class dataType>
476 Queue<dataType>::Queue (BaseType_t queue_size, const char* p_name,
477  TickType_t wait_time)
478  : BaseShare (p_name)
479 {
480  // Create a FreeRTOS queue object with space for the data items
481  handle = xQueueCreate (queue_size, sizeof (dataType));
482 
483  // Store the wait time; it will be used when writing to the queue
484  ticks_to_wait = wait_time;
485 
486  // Save the buffer size
487  buf_size = queue_size;
488 
489  // We haven't stored any items in the queue yet
490  max_full = 0;
491 }
492 
493 
494 /** @brief Put an item into the queue behind other items.
495  * @details This method puts an item of data into the back of the queue, which
496  * is the normal way to put something into a queue. If you want to be
497  * rude and put an item into the front of the queue so it will be
498  * retrieved first, use @c butt_in() instead. <b>This method must not
499  * be used within an Interrupt Service Routine.</b>
500  * @param item The item which is going to be put into the queue
501  * @return True if the item was successfully queued, false if not
502  */
503 template <class dataType>
504 inline bool Queue<dataType>::put (const dataType item)
505 {
506  bool return_value = (bool)(xQueueSendToBack (handle, &item,
507  ticks_to_wait));
508 
509  // Keep track of the maximum fillage of the queue
510  uint16_t fillage = uxQueueMessagesWaiting (handle);
511  if (fillage > max_full)
512  {
513  max_full = fillage;
514  }
515 
516  return (return_value);
517 }
518 
519 
520 /** @brief Put an item into the queue from within an ISR.
521  * @details This method puts an item of data into the back of the queue from
522  * within an interrupt service routine. It must \b not be used within
523  * non-ISR code.
524  * @param item The item which is going to be put into the queue
525  * @return True if the item was successfully queued, false if not
526  */
527 template <class dataType>
528 inline bool Queue<dataType>::ISR_put (const dataType item)
529 {
530  // This value is set true if a context switch should occur due to this data
531  signed portBASE_TYPE shouldSwitch = pdFALSE;
532 
533  bool return_value; // Value returned from this method
534 
535  // Call the FreeRTOS function and save its return value
536  return_value = (bool)(xQueueSendToBackFromISR (handle, &item,
537  &shouldSwitch));
538 
539  // Keep track of the maximum fillage of the queue. BUG: max_full isn't
540  // thread safe (but getting max_full corrupted shouldn't cause a calamity)
541  uint16_t fillage = uxQueueMessagesWaitingFromISR (handle);
542  if (fillage > max_full)
543  {
544  max_full = fillage;
545  }
546 
547  // Return the return value saved from the call to xQueueSendToBackFromISR()
548  return (return_value);
549 }
550 
551 
552 /** @brief Put an item into the front of the queue from within an ISR.
553  * @details This method puts an item into the front of the queue from within
554  * an ISR. It must \b not be used within normal, non-ISR code.
555  * @param item The item which is going to be (rudely) put into the front of
556  * the queue
557  * @return True if the item was successfully queued, false if not
558  */
559 template <class dataType>
560 inline bool Queue<dataType>::ISR_butt_in (const dataType item)
561 {
562  // This value is set true if a context switch should occur due to this data
563  signed portBASE_TYPE shouldSwitch = pdFALSE;
564 
565  bool return_value; // Value returned from this method
566 
567  // Call the FreeRTOS function and save its return value
568  return_value = (bool)(xQueueSendToFrontFromISR (handle, &item,
569  &shouldSwitch));
570 
571  // Return the return value saved from the call to xQueueSendToBackFromISR()
572  return (return_value);
573 }
574 
575 
576 /** @brief Print the queue's status to a serial device.
577  * @details This method makes a printout of the queue's status on the given
578  * serial device, then calls this same method for the next item of
579  * thread-safe data in the linked list of items.
580  * @param print_dev Reference to the serial device on which to print
581  */
582 template <class dataType>
583 void Queue<dataType>::print_in_list (Print& print_dev)
584 {
585  // Print this task's name and pad it to 16 characters
586  print_dev.printf ("%-16squeue\t", name);
587 
588  // Print the free and total number of spaces in the queue or an error
589  // message if this queue can't be used (probably due to a memory error)
590  if (usable ())
591  {
592  print_dev << max_full << '/' << buf_size << endl;
593  }
594  else
595  {
596  print_dev << "UNUSABLE" << endl;
597  }
598 
599  // Call the next item
600  if (p_next != NULL)
601  {
602  p_next->print_in_list (print_dev);
603  }
604 }
605 
606 #endif // _TASKQUEUE_H_
Queue::ticks_to_wait
TickType_t ticks_to_wait
RTOS ticks to wait for empty.
Definition: taskqueue.h:134
Queue::ISR_any
bool ISR_any(void)
Return true if the queue has items in it, from within an ISR.
Definition: taskqueue.h:402
Queue::ISR_is_empty
bool ISR_is_empty(void)
Return true if the queue is empty, from within an ISR.
Definition: taskqueue.h:193
Queue::max_full
uint16_t max_full
Maximum number of bytes in queue.
Definition: taskqueue.h:136
Queue::ISR_put
bool ISR_put(const dataType item)
Put an item into the queue from within an ISR.
Definition: taskqueue.h:528
Queue::peek
void peek(dataType &recv_item)
Get the item at the queue head without removing it.
Definition: taskqueue.h:275
Queue::ISR_available
unsigned portBASE_TYPE ISR_available(void)
Return the number of items in the queue, to an ISR.
Definition: taskqueue.h:425
Queue::is_empty
bool is_empty(void)
Return true if the queue is empty.
Definition: taskqueue.h:182
Queue::get
dataType get(void)
Retrieve, remove, and return the item at the head of the queue.
Definition: taskqueue.h:224
Queue::any
bool any(void)
Return true if the queue has contents which can be read.
Definition: taskqueue.h:342
Queue::usable
bool usable(void)
Indicates whether this queue is usable.
Definition: taskqueue.h:444
Queue::ISR_peek
dataType ISR_peek(void)
Return a copy of the item at the front of the queue without deleting it, from within an ISR.
Definition: taskqueue.h:328
Queue::get_handle
QueueHandle_t get_handle(void)
Return a handle to the FreeRTOS structure which runs this queue.
Definition: taskqueue.h:458
Queue::available
unsigned portBASE_TYPE available(void)
Return the number of items in the queue.
Definition: taskqueue.h:414
Queue::operator<<
void operator<<(dataType new_data)
Operator which inserts data into the queue.
Definition: taskqueue.h:356
Queue::get
void get(dataType &recv_item)
Retrieve and remove the item at the head of the queue.
Definition: taskqueue.h:208
Queue::print_in_list
void print_in_list(Print &print_dev)
Print the queue's status to a serial device.
Definition: taskqueue.h:583
Queue::peek
dataType peek(void)
Return a copy of the item at the queue head without removing it.
Definition: taskqueue.h:293
Queue::butt_in
bool butt_in(const dataType item)
Put an item into the front of the queue to be retrieved first.
Definition: taskqueue.h:167
Queue::ISR_get
dataType ISR_get(void)
Retrieve, remove, and return the item at the head of the queue when called by ISR code.
Definition: taskqueue.h:255
Queue::handle
QueueHandle_t handle
Hhandle for the FreeTOS queue.
Definition: taskqueue.h:133
baseshare.h
Headers for a base class for type-safe, thread-safe task data exchange classes.
Queue::Queue
Queue(BaseType_t queue_size, const char *p_name=NULL, TickType_t=portMAX_DELAY)
Construct a queue object, allocating memory for the buffer.
Definition: taskqueue.h:476
Queue
Implements a queue to transmit data from one RTOS task to another.
Definition: taskqueue.h:128
Queue::buf_size
uint16_t buf_size
Size of queue buffer in bytes.
Definition: taskqueue.h:135
Queue::operator>>
void operator>>(dataType &put_here)
Read data from the queue.
Definition: taskqueue.h:380
Queue::ISR_butt_in
bool ISR_butt_in(const dataType item)
Put an item into the front of the queue from within an ISR.
Definition: taskqueue.h:560
Queue::ISR_get
void ISR_get(dataType &recv_item)
Remove the item at the head of the queue from within an ISR.
Definition: taskqueue.h:238
Queue::put
bool put(const dataType item)
Put an item into the queue behind other items.
Definition: taskqueue.h:504
Queue::ISR_peek
void ISR_peek(dataType &recv_item)
Get the item at the front of the queue without deleting it, from within an ISR.
Definition: taskqueue.h:310
BaseShare
Base class for classes that share data in a thread-safe manner between tasks.
Definition: baseshare.h:54