2021-06-27 17:56:28 +00:00
|
|
|
#include "NotifiedWorkerThread.h"
|
2023-01-21 13:34:29 +00:00
|
|
|
#include "configuration.h"
|
2021-03-28 04:16:37 +00:00
|
|
|
#include "main.h"
|
2020-10-10 00:28:00 +00:00
|
|
|
|
|
|
|
namespace concurrency
|
|
|
|
{
|
|
|
|
|
2020-10-10 01:57:57 +00:00
|
|
|
static bool debugNotification;
|
|
|
|
|
2020-10-10 00:28:00 +00:00
|
|
|
/**
|
|
|
|
* Notify this thread so it can run
|
|
|
|
*/
|
2020-10-10 01:57:57 +00:00
|
|
|
bool NotifiedWorkerThread::notify(uint32_t v, bool overwrite)
|
|
|
|
{
|
|
|
|
bool r = notifyCommon(v, overwrite);
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
mainDelay.interrupt();
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify this thread so it can run
|
|
|
|
*/
|
|
|
|
IRAM_ATTR bool NotifiedWorkerThread::notifyCommon(uint32_t v, bool overwrite)
|
|
|
|
{
|
|
|
|
if (overwrite || notification == 0) {
|
|
|
|
enabled = true;
|
|
|
|
setInterval(0); // Run ASAP
|
2021-03-28 04:16:37 +00:00
|
|
|
runASAP = true;
|
2020-10-10 01:57:57 +00:00
|
|
|
|
|
|
|
notification = v;
|
|
|
|
if (debugNotification)
|
2022-12-30 02:41:37 +00:00
|
|
|
LOG_DEBUG("setting notification %d\n", v);
|
2020-10-10 01:57:57 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (debugNotification)
|
2022-12-30 02:41:37 +00:00
|
|
|
LOG_DEBUG("dropping notification %d\n", v);
|
2020-10-10 01:57:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-10-10 00:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify from an ISR
|
|
|
|
*
|
|
|
|
* This must be inline or IRAM_ATTR on ESP32
|
|
|
|
*/
|
2020-10-10 01:57:57 +00:00
|
|
|
IRAM_ATTR bool NotifiedWorkerThread::notifyFromISR(BaseType_t *highPriWoken, uint32_t v, bool overwrite)
|
2020-10-10 00:28:00 +00:00
|
|
|
{
|
2020-10-10 01:57:57 +00:00
|
|
|
bool r = notifyCommon(v, overwrite);
|
|
|
|
if (r)
|
|
|
|
mainDelay.interruptFromISR(highPriWoken);
|
|
|
|
|
|
|
|
return r;
|
2020-10-10 00:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedule a notification to fire in delay msecs
|
|
|
|
*/
|
2020-10-10 01:57:57 +00:00
|
|
|
bool NotifiedWorkerThread::notifyLater(uint32_t delay, uint32_t v, bool overwrite)
|
|
|
|
{
|
|
|
|
bool didIt = notify(v, overwrite);
|
|
|
|
|
|
|
|
if (didIt) { // If we didn't already have something queued, override the delay to be larger
|
|
|
|
setIntervalFromNow(delay); // a new version of setInterval relative to the current time
|
|
|
|
if (debugNotification)
|
2022-12-30 02:41:37 +00:00
|
|
|
LOG_DEBUG("delaying notification %u\n", delay);
|
2020-10-10 01:57:57 +00:00
|
|
|
}
|
2020-10-10 00:28:00 +00:00
|
|
|
|
2020-10-10 01:57:57 +00:00
|
|
|
return didIt;
|
2020-10-10 00:28:00 +00:00
|
|
|
}
|
|
|
|
|
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 NotifiedWorkerThread::checkNotification()
|
2020-10-10 01:57:57 +00:00
|
|
|
{
|
|
|
|
auto n = notification;
|
|
|
|
notification = 0; // clear notification
|
|
|
|
if (n) {
|
|
|
|
onNotify(n);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int32_t NotifiedWorkerThread::runOnce()
|
|
|
|
{
|
2023-01-21 13:34:29 +00:00
|
|
|
enabled = false; // Only run once per notification
|
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
|
|
|
checkNotification();
|
2020-10-10 00:28:00 +00:00
|
|
|
|
2020-10-10 01:57:57 +00:00
|
|
|
return RUN_SAME;
|
2020-10-10 00:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace concurrency
|