move packet handling into its own thread

This commit is contained in:
geeksville
2020-05-01 12:11:04 -07:00
parent 763276a2c8
commit 50213d8323
10 changed files with 178 additions and 27 deletions

44
src/WorkerThread.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include "WorkerThread.h"
#include <assert.h>
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()
{
while (!wantExit) {
block();
loop();
}
}
/**
* Notify this thread so it can run
*/
void NotifiedWorkerThread::notify(uint32_t v, eNotifyAction action)
{
xTaskNotify(taskHandle, v, action);
}
/**
* Notify from an ISR
*/
void NotifiedWorkerThread::notifyFromISR(BaseType_t *highPriWoken, uint32_t v, eNotifyAction action)
{
xTaskNotifyFromISR(taskHandle, v, action, highPriWoken);
}
void NotifiedWorkerThread::block()
{
xTaskNotifyWait(0, // don't clear notification on entry
0, // do not reset notification value on read
&notification, portMAX_DELAY); // Wait forever
}