2020-05-01 19:11:04 +00:00
|
|
|
#include "WorkerThread.h"
|
2020-06-12 23:37:03 +00:00
|
|
|
#include "debug.h"
|
2020-05-01 19:11:04 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2020-06-06 00:30:09 +00:00
|
|
|
#ifdef configUSE_PREEMPTION
|
|
|
|
|
2020-05-01 19:11:04 +00:00
|
|
|
void Thread::start(const char *name, size_t stackSize, uint32_t priority)
|
|
|
|
{
|
|
|
|
auto r = xTaskCreate(callRun, name, stackSize, this, priority, &taskHandle);
|
|
|
|
assert(r == pdPASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::callRun(void *_this)
|
|
|
|
{
|
|
|
|
((Thread *)_this)->doRun();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorkerThread::doRun()
|
|
|
|
{
|
2020-06-28 18:12:12 +00:00
|
|
|
startWatchdog();
|
|
|
|
|
2020-05-01 19:11:04 +00:00
|
|
|
while (!wantExit) {
|
2020-06-28 18:12:12 +00:00
|
|
|
stopWatchdog();
|
2020-05-01 19:11:04 +00:00
|
|
|
block();
|
2020-06-28 18:12:12 +00:00
|
|
|
startWatchdog();
|
|
|
|
|
|
|
|
// no need - startWatchdog is guaranteed to give us one full watchdog interval
|
|
|
|
// serviceWatchdog(); // Let our loop worker have one full watchdog interval (at least) to run
|
2020-06-12 23:37:03 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_STACK
|
|
|
|
static uint32_t lastPrint = 0;
|
|
|
|
if (millis() - lastPrint > 10 * 1000L) {
|
|
|
|
lastPrint = millis();
|
|
|
|
meshtastic::printThreadInfo("net");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-01 19:11:04 +00:00
|
|
|
loop();
|
|
|
|
}
|
2020-06-28 18:12:12 +00:00
|
|
|
|
|
|
|
stopWatchdog();
|
2020-05-01 19:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify this thread so it can run
|
|
|
|
*/
|
|
|
|
void NotifiedWorkerThread::notify(uint32_t v, eNotifyAction action)
|
|
|
|
{
|
|
|
|
xTaskNotify(taskHandle, v, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifiedWorkerThread::block()
|
|
|
|
{
|
2020-05-02 15:29:51 +00:00
|
|
|
xTaskNotifyWait(0, // don't clear notification on entry
|
|
|
|
clearOnRead, ¬ification, portMAX_DELAY); // Wait forever
|
2020-05-01 19:11:04 +00:00
|
|
|
}
|
2020-06-06 00:30:09 +00:00
|
|
|
|
|
|
|
#endif
|