2020-07-05 21:11:40 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-09 06:16:51 +00:00
|
|
|
#include "OSThread.h"
|
2020-07-05 21:11:40 +00:00
|
|
|
|
2020-10-09 06:16:51 +00:00
|
|
|
namespace concurrency
|
|
|
|
{
|
2020-10-09 01:10:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief A worker thread that waits on a freertos notification
|
|
|
|
*/
|
2020-10-09 06:16:51 +00:00
|
|
|
class NotifiedWorkerThread : public OSThread
|
2020-07-05 21:11:40 +00:00
|
|
|
{
|
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:
|
2020-10-09 06:16:51 +00:00
|
|
|
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-07-05 21:11:40 +00:00
|
|
|
|
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 06:16:51 +00:00
|
|
|
|
2020-10-09 01:10:44 +00:00
|
|
|
/**
|
2020-10-09 06:16:51 +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);
|
2020-07-05 21:11:40 +00:00
|
|
|
|
2020-10-09 06:16:51 +00:00
|
|
|
protected:
|
|
|
|
virtual void onNotify(uint32_t notification) = 0;
|
|
|
|
|
Fix rare assertion failure which could occur due to pending interrupts
* fix assertion failure
```
22:57:36 64409 [PositionPlugin] FIXME-update-db Sniffing packet
22:57:36 64409 [PositionPlugin] Delivering rx packet (id=0x5851f437 Fr0xa1 To0xff, WantAck0, HopLim3 Ch0x0 Portnum=3 rxtime=1628895456 priority=10)
22:57:36 64409 [PositionPlugin] Forwarding to phone (id=0x5851f437 Fr0xa1 To0xff, WantAck0, HopLim3 Ch0x0 Portnum=3 rxtime=1628895456 priority=10)
22:57:36 64409 [PositionPlugin] Update DB node 0x85f4da1, rx_time=1628895456
22:57:36 64409 [PositionPlugin] Plugin routing considered
22:57:36 64409 [PositionPlugin] Add packet record (id=0x5851f437 Fr0xa1 To0xff, WantAck0, HopLim3 Ch0x0 Portnum=3 rxtime=1628895456 priority=10)
22:57:36 64409 [PositionPlugin] Expanding short PSK #1
22:57:36 64409 [PositionPlugin] Installing AES128 key!
22:57:36 64409 [PositionPlugin] enqueuing for send (id=0x5851f437 Fr0xa1 To0xff, WantAck0, HopLim3 Ch0xb1 encrypted rxtime=1628895456 priority=10)
22:57:36 64409 [PositionPlugin] (bw=125, sf=12, cr=4/8) packet symLen=32 ms, payloadSize=22, time 2596 ms
22:57:36 64409 [PositionPlugin] txGood=6,rxGood=10,rxBad=0
22:57:36 64409 [PositionPlugin] AirTime - Packet transmitted : 2596ms
22:57:36 64409 [RadioIf] assert failed src/mesh/RadioLibInterface.cpp: 240, void RadioLibInterface::handleReceiveInterrupt(), test=isReceiving
```
2021-08-17 23:31:01 +00:00
|
|
|
/// 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.
|
Fix rare assertion failure which could occur due to pending interrupts
* fix assertion failure
```
22:57:36 64409 [PositionPlugin] FIXME-update-db Sniffing packet
22:57:36 64409 [PositionPlugin] Delivering rx packet (id=0x5851f437 Fr0xa1 To0xff, WantAck0, HopLim3 Ch0x0 Portnum=3 rxtime=1628895456 priority=10)
22:57:36 64409 [PositionPlugin] Forwarding to phone (id=0x5851f437 Fr0xa1 To0xff, WantAck0, HopLim3 Ch0x0 Portnum=3 rxtime=1628895456 priority=10)
22:57:36 64409 [PositionPlugin] Update DB node 0x85f4da1, rx_time=1628895456
22:57:36 64409 [PositionPlugin] Plugin routing considered
22:57:36 64409 [PositionPlugin] Add packet record (id=0x5851f437 Fr0xa1 To0xff, WantAck0, HopLim3 Ch0x0 Portnum=3 rxtime=1628895456 priority=10)
22:57:36 64409 [PositionPlugin] Expanding short PSK #1
22:57:36 64409 [PositionPlugin] Installing AES128 key!
22:57:36 64409 [PositionPlugin] enqueuing for send (id=0x5851f437 Fr0xa1 To0xff, WantAck0, HopLim3 Ch0xb1 encrypted rxtime=1628895456 priority=10)
22:57:36 64409 [PositionPlugin] (bw=125, sf=12, cr=4/8) packet symLen=32 ms, payloadSize=22, time 2596 ms
22:57:36 64409 [PositionPlugin] txGood=6,rxGood=10,rxBad=0
22:57:36 64409 [PositionPlugin] AirTime - Packet transmitted : 2596ms
22:57:36 64409 [RadioIf] assert failed src/mesh/RadioLibInterface.cpp: 240, void RadioLibInterface::handleReceiveInterrupt(), test=isReceiving
```
2021-08-17 23:31:01 +00:00
|
|
|
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
|
|
|
};
|
2020-07-05 21:11:40 +00:00
|
|
|
|
|
|
|
} // namespace concurrency
|