My Project
 All Classes Functions Variables Pages
Task.h
1 /*
2  * Task.h
3  *
4  * Created on: Mar 4, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_TASK_H_
9 #define COMPONENTS_CPP_UTILS_TASK_H_
10 #include <freertos/FreeRTOS.h>
11 #include <freertos/task.h>
12 #include <string>
34 class Task {
35 public:
36  Task(std::string taskName = "Task", uint16_t stackSize = 10000, uint8_t priority = 5);
37  virtual ~Task();
38  void setStackSize(uint16_t stackSize);
39  void setPriority(uint8_t priority);
40  void setName(std::string name);
41  void setCore(BaseType_t coreId);
42  void start(void* taskData = nullptr);
43  void stop();
53  virtual void run(void* data) = 0; // Make run pure virtual
54  static void delay(int ms);
55 
56 private:
57  xTaskHandle m_handle;
58  void* m_taskData;
59  static void runTask(void* data);
60  std::string m_taskName;
61  uint16_t m_stackSize;
62  uint8_t m_priority;
63  BaseType_t m_coreId;
64 
65 };
66 
67 #endif /* COMPONENTS_CPP_UTILS_TASK_H_ */
static void delay(int ms)
Suspend the task for the specified milliseconds.
Definition: Task.cpp:46
void setStackSize(uint16_t stackSize)
Set the stack size of the task.
Definition: Task.cpp:97
void setName(std::string name)
Set the name of the task.
Definition: Task.cpp:117
void setPriority(uint8_t priority)
Set the priority of the task.
Definition: Task.cpp:107
void setCore(BaseType_t coreId)
Set the core number the task has to be executed on. If the core number is not set, tskNO_AFFINITY will be used.
Definition: Task.cpp:128
void stop()
Stop the task.
Definition: Task.cpp:84
virtual void run(void *data)=0
Body of the task to execute.
Task(std::string taskName="Task", uint16_t stackSize=10000, uint8_t priority=5)
Create an instance of the task class.
Definition: Task.cpp:27
void start(void *taskData=nullptr)
Start an instance of the task.
Definition: Task.cpp:70
Encapsulate a runnable task.
Definition: Task.h:34