Open FFBoard
Open source force feedback firmware
cqueue.cpp
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * Copyright (c) 2017, Michael Becker (michael.f.becker@gmail.com)
4 *
5 * This file is part of the FreeRTOS Add-ons project.
6 *
7 * Source Code:
8 * https://github.com/michaelbecker/freertos-addons
9 *
10 * Project Page:
11 * http://michaelbecker.github.io/freertos-addons/
12 *
13 * On-line Documentation:
14 * http://michaelbecker.github.io/freertos-addons/docs/html/index.html
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files
18 * (the "Software"), to deal in the Software without restriction, including
19 * without limitation the rights to use, copy, modify, merge, publish,
20 * distribute, sublicense, and/or sell copies of the Software, and to
21 * permit persons to whom the Software is furnished to do so,subject to the
22 * following conditions:
23 *
24 * + The above copyright notice and this permission notice shall be included
25 * in all copies or substantial portions of the Software.
26 * + Credit is appreciated, but not required, if you find this project
27 * useful enough to include in your application, product, device, etc.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
33 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
34 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 *
37 ***************************************************************************/
38
39#include "FreeRTOS.h"
40#include "queue.hpp"
41
42
43using namespace cpp_freertos;
44
45
46Queue::Queue(UBaseType_t maxItems, UBaseType_t itemSize)
47{
48 handle = xQueueCreate(maxItems, itemSize);
49
50 if (handle == NULL) {
51#ifndef CPP_FREERTOS_NO_EXCEPTIONS
53#else
54 configASSERT(!"Queue Constructor Failed");
55#endif
56 }
57}
58
59
61{
62 vQueueDelete(handle);
63}
64
65
66bool Queue::Enqueue(void *item)
67{
68 BaseType_t success;
69
70 success = xQueueSendToBack(handle, item, portMAX_DELAY);
71
72 return success == pdTRUE ? true : false;
73}
74
75
76bool Queue::Enqueue(void *item, TickType_t Timeout)
77{
78 BaseType_t success;
79
80 success = xQueueSendToBack(handle, item, Timeout);
81
82 return success == pdTRUE ? true : false;
83}
84
85
86bool Queue::Dequeue(void *item, TickType_t Timeout)
87{
88 BaseType_t success;
89
90 success = xQueueReceive(handle, item, Timeout);
91
92 return success == pdTRUE ? true : false;
93}
94
95
96bool Queue::Peek(void *item, TickType_t Timeout)
97{
98 BaseType_t success;
99
100 success = xQueuePeek(handle, item, Timeout);
101
102 return success == pdTRUE ? true : false;
103}
104
105
106bool Queue::EnqueueFromISR(void *item, BaseType_t *pxHigherPriorityTaskWoken)
107{
108 BaseType_t success;
109
110 success = xQueueSendToBackFromISR(handle, item, pxHigherPriorityTaskWoken);
111
112 return success == pdTRUE ? true : false;
113}
114
115
116bool Queue::DequeueFromISR(void *item, BaseType_t *pxHigherPriorityTaskWoken)
117{
118 BaseType_t success;
119
120 success = xQueueReceiveFromISR(handle, item, pxHigherPriorityTaskWoken);
121
122 return success == pdTRUE ? true : false;
123}
124
125
126bool Queue::PeekFromISR(void *item)
127{
128 BaseType_t success;
129
130 success = xQueuePeekFromISR(handle, item);
131
132 return success == pdTRUE ? true : false;
133}
134
135
137{
138 UBaseType_t cnt = uxQueueMessagesWaiting(handle);
139
140 return cnt == 0 ? true : false;
141}
142
143
145{
146 UBaseType_t cnt = uxQueueSpacesAvailable(handle);
147
148 return cnt == 0 ? true : false;
149}
150
151
153{
154 xQueueReset(handle);
155}
156
157
158UBaseType_t Queue::NumItems()
159{
160 return uxQueueMessagesWaiting(handle);
161}
162
163
165{
166 return uxQueueSpacesAvailable(handle);
167}
168
169
170Deque::Deque(UBaseType_t maxItems, UBaseType_t itemSize)
171 : Queue(maxItems, itemSize)
172{
173}
174
175
176bool Deque::EnqueueToFront(void *item, TickType_t Timeout)
177{
178 BaseType_t success;
179
180 success = xQueueSendToFront(handle, item, Timeout);
181
182 return success == pdTRUE ? true : false;
183}
184
185
186bool Deque::EnqueueToFrontFromISR(void *item, BaseType_t *pxHigherPriorityTaskWoken)
187{
188 BaseType_t success;
189
190 success = xQueueSendToFrontFromISR(handle, item, pxHigherPriorityTaskWoken);
191
192 return success == pdTRUE ? true : false;
193}
194
195
196BinaryQueue::BinaryQueue(UBaseType_t itemSize)
197 : Queue(1, itemSize)
198{
199}
200
201
202bool BinaryQueue::Enqueue(void *item)
203{
204 (void)xQueueOverwrite(handle, item);
205 return true;
206}
207
208
209bool BinaryQueue::EnqueueFromISR(void *item, BaseType_t *pxHigherPriorityTaskWoken)
210{
211 (void)xQueueOverwriteFromISR(handle, item, pxHigherPriorityTaskWoken);
212 return true;
213}
virtual bool Enqueue(void *item)
Definition: cqueue.cpp:202
BinaryQueue(UBaseType_t itemSize)
Definition: cqueue.cpp:196
virtual bool EnqueueFromISR(void *item, BaseType_t *pxHigherPriorityTaskWoken)
Definition: cqueue.cpp:209
Deque(UBaseType_t maxItems, UBaseType_t itemSize)
Definition: cqueue.cpp:170
bool EnqueueToFrontFromISR(void *item, BaseType_t *pxHigherPriorityTaskWoken)
Definition: cqueue.cpp:186
bool EnqueueToFront(void *item, TickType_t Timeout=portMAX_DELAY)
Definition: cqueue.cpp:176
virtual ~Queue()
Definition: cqueue.cpp:60
bool PeekFromISR(void *item)
Definition: cqueue.cpp:126
bool Peek(void *item, TickType_t Timeout=portMAX_DELAY)
Definition: cqueue.cpp:96
bool Dequeue(void *item, TickType_t Timeout=portMAX_DELAY)
Definition: cqueue.cpp:86
QueueHandle_t handle
Definition: queue.hpp:247
UBaseType_t NumSpacesLeft()
Definition: cqueue.cpp:164
virtual bool Enqueue(void *item)
Definition: cqueue.cpp:66
virtual bool EnqueueFromISR(void *item, BaseType_t *pxHigherPriorityTaskWoken)
Definition: cqueue.cpp:106
bool DequeueFromISR(void *item, BaseType_t *pxHigherPriorityTaskWoken)
Definition: cqueue.cpp:116
UBaseType_t NumItems()
Definition: cqueue.cpp:158