TypedQueue: make functions return bools instead of BaseType_t

Minor cleanup to hide away some FreeRTOS bits.

Note: I believe src/CustomRF95.cpp:62 had a bug where it had the
condition inverted.
1.2-legacy
Girts Folkmanis 2020-03-15 17:52:01 -07:00
rodzic 90ecdf229e
commit 7a4a1af332
5 zmienionych plików z 23 dodań i 24 usunięć

Wyświetl plik

@ -126,8 +126,7 @@ void CustomRF95::handleInterrupt()
// parsing was successful, queue for our recipient
mp->has_payload = true;
int res = rxDest.enqueueFromISR(mp, &higherPriWoken); // NOWAIT - fixme, if queue is full, delete older messages
assert(res == pdTRUE);
assert(rxDest.enqueueFromISR(mp, &higherPriWoken)); // NOWAIT - fixme, if queue is full, delete older messages
}
clearRxBuf(); // This message accepted and cleared
@ -185,4 +184,4 @@ void CustomRF95::startSend(MeshPacket *txp)
int res = RH_RF95::send(radiobuf, numbytes);
assert(res);
}
}

Wyświetl plik

@ -66,16 +66,14 @@ public:
/// Return a buffer for use by others
void release(T *p)
{
int res = dead.enqueue(p, 0);
assert(res == pdTRUE);
assert(dead.enqueue(p, 0));
assert(p >= buf && (p - buf) < maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
}
/// Return a buffer from an ISR, if higherPriWoken is set to true you have some work to do ;-)
void releaseFromISR(T *p, BaseType_t *higherPriWoken)
{
int res = dead.enqueueFromISR(p, higherPriWoken);
assert(res == pdTRUE);
assert(dead.enqueueFromISR(p, higherPriWoken));
assert(p >= buf && (p - buf) < maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
}
};

Wyświetl plik

@ -173,7 +173,7 @@ void MeshService::handleFromRadio(MeshPacket *mp)
if (d)
releaseToPool(d);
}
assert(toPhoneQueue.enqueue(mp, 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
assert(toPhoneQueue.enqueue(mp, 0)); // FIXME, instead of failing for full queue, delete the oldest mssages
if (mp->payload.want_response)
sendNetworkPing(mp->from);

Wyświetl plik

@ -18,7 +18,7 @@ public:
{
T *p;
return this->dequeue(&p, maxWait) == pdTRUE ? p : NULL;
return this->dequeue(&p, maxWait) ? p : nullptr;
}
// returns a ptr or null if the queue was empty
@ -26,6 +26,6 @@ public:
{
T *p;
return this->dequeueFromISR(&p, higherPriWoken) == pdTRUE ? p : NULL;
return this->dequeueFromISR(&p, higherPriWoken) ? p : nullptr;
}
};

Wyświetl plik

@ -1,18 +1,22 @@
#pragma once
#include <Arduino.h>
#include <assert.h>
#include <cassert>
#include <type_traits>
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>
/**
* A wrapper for freertos queues. Note: each element object must be quite small, so T should be only
* pointer types or ints
* A wrapper for freertos queues. Note: each element object should be small
* and POD (Plain Old Data type) as elements are memcpied by value.
*/
template <class T>
class TypedQueue
{
static_assert(std::is_pod<T>::value, "T must be pod");
QueueHandle_t h;
public:
public:
TypedQueue(int maxElements)
{
h = xQueueCreate(maxElements, sizeof(T));
@ -34,24 +38,22 @@ public:
return uxQueueMessagesWaiting(h) == 0;
}
// pdTRUE for success else failure
BaseType_t enqueue(T x, TickType_t maxWait = portMAX_DELAY)
bool enqueue(T x, TickType_t maxWait = portMAX_DELAY)
{
return xQueueSendToBack(h, &x, maxWait);
return xQueueSendToBack(h, &x, maxWait) == pdTRUE;
}
BaseType_t enqueueFromISR(T x, BaseType_t *higherPriWoken)
bool enqueueFromISR(T x, BaseType_t *higherPriWoken)
{
return xQueueSendToBackFromISR(h, &x, higherPriWoken);
return xQueueSendToBackFromISR(h, &x, higherPriWoken) == pdTRUE;
}
// pdTRUE for success else failure
BaseType_t dequeue(T *p, TickType_t maxWait = portMAX_DELAY)
bool dequeue(T *p, TickType_t maxWait = portMAX_DELAY)
{
return xQueueReceive(h, p, maxWait);
return xQueueReceive(h, p, maxWait) == pdTRUE;
}
BaseType_t dequeueFromISR(T *p, BaseType_t *higherPriWoken)
bool dequeueFromISR(T *p, BaseType_t *higherPriWoken)
{
return xQueueReceiveFromISR(h, p, higherPriWoken);
}