FreeRTOS C++ Wrappers
QueueCPP.h
Go to the documentation of this file.
1 
36 #ifndef QUEUECPP_H
37 #define QUEUECPP_H
38 
39 #include "FreeRTOS.h"
40 #include "queue.h"
41 
42 //#include <type_traits>
43 
58 template<class T> class Queue {
59 // static_assert(::std::is_pod<T>, "Queues only work with PODs"); ///@todo need to get later version of C++ compile working
60 public:
61  Queue(unsigned portBASE_TYPE length, char const* name){
62  handle = xQueueCreate(length, sizeof(T));
63 #if configQUEUE_REGISTRY_SIZE > 0
64  vQueueAddToRegistry(handle, name);
65 #endif
66 
67  };
68 
69  ~Queue() {
70  vQueueDelete(handle);
71  }
72 
73  unsigned portBASE_TYPE waiting() const {
74  return uxQueueMessagesWaiting(handle);
75  }
76 
77  bool push(T const& item, TickType_t time = portMAX_DELAY){
78  return xQueueSendToFront(handle, &item, time);
79  }
80 
81  bool add(T const& item, TickType_t time = portMAX_DELAY){
82  return xQueueSendToBack(handle, &item, time);
83  }
84 
85  bool pop(T& var, TickType_t time = portMAX_DELAY) {
86  return xQueueReceive(handle, &var, time);
87  }
88 
89  bool peek(T& var, TickType_t time = portMAX_DELAY) {
90  return xQueuePeek(handle, &var, time);
91  }
92 
93  bool full() {
94  return 0 < uxQueueSpacesAvailable(handle);
95  }
96 
97  bool empty() {
98  return uxQueueMessagesWaiting(handle) == 0;
99  }
100 
101  bool push_ISR(T const& item){
102  return xQueueSendToFrontFromISR(handle, &item, waswoken);
103  }
104 
105  bool add_ISR(T const& item){
106  return xQueueSendToBackFromISR(handle, &item, waswoken);
107  }
108 
109  bool pop_ISR(T& var) {
110  return xQueueReceiveFromISR(handle, &var, waswoken);
111  }
112 
113  bool peek_ISR(T& var) {
114  return xQueuePeekFromISR(handle, &var, waswoken);
115  }
116 
117  bool full_ISR() {
118  return xQueueIsQueueFullFromISR(handle);
119  }
120 
121  bool empty_ISR() {
122  return xQueueIsQueueEmptyFromISR(handle);
123  }
124 
125  unsigned waiting_ISR() {
126  return uxQueueMessagesWaitingFromISR(handle);
127  }
128 
129  void start_ISR(portBASE_TYPE& flag) { waswoken = &flag; }
130 
131 private:
132  xQueueHandle handle;
133 // portBASE_TYPE* waswoken;
134 #if __cplusplus < 201101L
135  Queue(Queue const&);
136  void operator =(Queue const&);
137 #else
138  Queue(Queue const&) = delete;
139  void operator =(Queue const&) = delete;
140 #endif // __cplusplus
141 
142 };
143 
144 #endif
bool add_ISR(T const &item)
Definition: QueueCPP.h:105
bool pop_ISR(T &var)
Definition: QueueCPP.h:109
bool peek(T &var, TickType_t time=portMAX_DELAY)
Definition: QueueCPP.h:89
bool full_ISR()
Definition: QueueCPP.h:117
Queue(unsigned portBASE_TYPE length, char const *name)
Definition: QueueCPP.h:61
unsigned portBASE_TYPE waiting() const
Definition: QueueCPP.h:73
~Queue()
Definition: QueueCPP.h:69
void start_ISR(portBASE_TYPE &flag)
Definition: QueueCPP.h:129
unsigned waiting_ISR()
Definition: QueueCPP.h:125
bool full()
Definition: QueueCPP.h:93
bool empty()
Definition: QueueCPP.h:97
bool add(T const &item, TickType_t time=portMAX_DELAY)
Definition: QueueCPP.h:81
bool empty_ISR()
Definition: QueueCPP.h:121
bool push_ISR(T const &item)
Definition: QueueCPP.h:101
bool peek_ISR(T &var)
Definition: QueueCPP.h:113
Queue Wrapper.
Definition: QueueCPP.h:58
bool pop(T &var, TickType_t time=portMAX_DELAY)
Definition: QueueCPP.h:85
bool push(T const &item, TickType_t time=portMAX_DELAY)
Definition: QueueCPP.h:77