meshtastic-firmware/src/concurrency/NotifiedWorkerThread.h

57 wiersze
1.4 KiB
C
Czysty Zwykły widok Historia

#pragma once
#include "OSThread.h"
namespace concurrency
{
2020-10-09 01:10:44 +00:00
/**
* @brief A worker thread that waits on a freertos notification
*/
class NotifiedWorkerThread : public OSThread
{
2020-10-10 00:28:00 +00:00
/**
* The notification that was most recently used to wake the thread. Read from runOnce()
*/
uint32_t notification = 0;
2020-10-09 01:10:44 +00:00
public:
NotifiedWorkerThread(const char *name) : OSThread(name) {}
2020-10-09 01:10:44 +00:00
/**
* Notify this thread so it can run
*/
2020-10-10 01:57:57 +00:00
bool notify(uint32_t v, bool overwrite);
2020-10-09 01:10:44 +00:00
/**
* Notify from an ISR
*
* This must be inline or IRAM_ATTR on ESP32
*/
2020-10-10 01:57:57 +00:00
bool notifyFromISR(BaseType_t *highPriWoken, uint32_t v, bool overwrite);
2020-10-09 01:10:44 +00:00
/**
* Schedule a notification to fire in delay msecs
2020-10-09 01:10:44 +00:00
*/
2020-10-10 01:57:57 +00:00
bool notifyLater(uint32_t delay, uint32_t v, bool overwrite);
protected:
virtual void onNotify(uint32_t notification) = 0;
/// just calls checkNotification()
2022-01-24 17:24:40 +00:00
virtual int32_t runOnce() override;
2020-10-10 01:57:57 +00:00
2023-01-21 13:34:29 +00:00
/// Sometimes we might want to check notifications independently of when our thread was getting woken up (i.e. if we are about
/// to change radio transmit/receive modes we want to handle any pending interrupts first). You can call this method and if
/// any notifications are currently pending they will be handled immediately.
void checkNotification();
2020-10-10 01:57:57 +00:00
private:
/**
* Notify this thread so it can run
*/
bool notifyCommon(uint32_t v, bool overwrite);
2020-10-09 01:10:44 +00:00
};
} // namespace concurrency