mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-23 11:10:52 +00:00
coroutine: kinda works now
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
#include "concurrency/OSThread.h"
|
||||
#include "freertosinc.h"
|
||||
|
||||
#ifdef HAS_FREE_RTOS
|
||||
@@ -15,6 +16,7 @@ template <class T> class TypedQueue
|
||||
{
|
||||
static_assert(std::is_pod<T>::value, "T must be pod");
|
||||
QueueHandle_t h;
|
||||
concurrency::OSThread *reader = NULL;
|
||||
|
||||
public:
|
||||
TypedQueue(int maxElements)
|
||||
@@ -29,13 +31,35 @@ template <class T> class TypedQueue
|
||||
|
||||
bool isEmpty() { return uxQueueMessagesWaiting(h) == 0; }
|
||||
|
||||
bool enqueue(T x, TickType_t maxWait = portMAX_DELAY) { return xQueueSendToBack(h, &x, maxWait) == pdTRUE; }
|
||||
bool enqueue(T x, TickType_t maxWait = portMAX_DELAY)
|
||||
{
|
||||
if (reader) {
|
||||
reader->setInterval(0);
|
||||
concurrency::mainDelay.interrupt();
|
||||
}
|
||||
return xQueueSendToBack(h, &x, maxWait) == pdTRUE;
|
||||
}
|
||||
|
||||
bool enqueueFromISR(T x, BaseType_t *higherPriWoken) { return xQueueSendToBackFromISR(h, &x, higherPriWoken) == pdTRUE; }
|
||||
bool enqueueFromISR(T x, BaseType_t *higherPriWoken)
|
||||
{
|
||||
if (reader) {
|
||||
reader->setInterval(0);
|
||||
concurrency::mainDelay.interruptFromISR(higherPriWoken);
|
||||
}
|
||||
return xQueueSendToBackFromISR(h, &x, higherPriWoken) == pdTRUE;
|
||||
}
|
||||
|
||||
bool dequeue(T *p, TickType_t maxWait = portMAX_DELAY) { return xQueueReceive(h, p, maxWait) == pdTRUE; }
|
||||
|
||||
bool dequeueFromISR(T *p, BaseType_t *higherPriWoken) { return xQueueReceiveFromISR(h, p, higherPriWoken); }
|
||||
|
||||
/**
|
||||
* Set a thread that is reading from this queue
|
||||
* If a message is pushed to this queue that thread will be scheduled to run ASAP.
|
||||
*
|
||||
* Note: thread will not be automatically enabled, just have its interval set to 0
|
||||
*/
|
||||
void setReader(concurrency::OSThread *t) { reader = t; }
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user