42 lines
876 B
C++
42 lines
876 B
C++
/// © MiroZ 2024
|
|
|
|
#ifndef __TASK_FACTORY_H__
|
|
#define __TASK_FACTORY_H__
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/task.h>
|
|
#include <freertos/semphr.h>
|
|
#include <stdint.h>
|
|
#include <esp_err.h>
|
|
#include <functional>
|
|
|
|
typedef std::function<void()> TASK_FUNCTION;
|
|
|
|
class TaskFactory
|
|
{
|
|
protected:
|
|
SemaphoreHandle_t m_xMutex = NULL;
|
|
TASK_FUNCTION m_task_function = nullptr;
|
|
|
|
protected:
|
|
static void taskStarter(void * ptr) {
|
|
(static_cast<TaskFactory*>(ptr)->run());
|
|
}
|
|
void run(){
|
|
m_task_function();
|
|
}
|
|
|
|
public:
|
|
TaskHandle_t createTask(TASK_FUNCTION task_function, const char *name, uint32_t stack_size, UBaseType_t priority, BaseType_t core);
|
|
|
|
static uint32_t getStackHighWaterMark(TaskHandle_t task){
|
|
return (uint32_t)uxTaskGetStackHighWaterMark(task);
|
|
}
|
|
|
|
TaskFactory();
|
|
~TaskFactory();
|
|
};
|
|
|
|
extern TaskFactory TASK_FACTORY;
|
|
|
|
#endif /* __TASK_FACTORY_H__ */ |