firmware/src/concurrency/Thread.h

48 lines
1.0 KiB
C
Raw Normal View History

#pragma once
#include "freertosinc.h"
namespace concurrency {
2020-07-05 22:54:30 +00:00
/**
* @brief Base threading
*/
class Thread
{
protected:
TaskHandle_t taskHandle = NULL;
/**
* set this to true to ask thread to cleanly exit asap
*/
volatile bool wantExit = false;
public:
void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY);
virtual ~Thread() { vTaskDelete(taskHandle); }
uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
2020-07-06 19:53:10 +00:00
/**
* All thread run methods must periodically call serviceWatchdog, or the system will declare them hung and panic.
*
* this only applies after startWatchdog() has been called. If you need to sleep for a long time call stopWatchdog()
*/
2020-07-10 02:57:55 +00:00
void serviceWatchdog();
void startWatchdog();
void stopWatchdog();
2020-07-06 19:53:10 +00:00
private:
static void callRun(void *_this);
};
2020-07-06 19:53:10 +00:00
} // namespace concurrency