-
Notifications
You must be signed in to change notification settings - Fork 1
/
Task.h
67 lines (63 loc) · 1.51 KB
/
Task.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Task.h
*
* Created on: Mar 4, 2017
* Author: kolban
*/
#ifndef COMPONENTS_CPP_UTILS_TASK_H_
#define COMPONENTS_CPP_UTILS_TASK_H_
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <string>
/**
* @brief Encapsulate a runnable task.
*
* This class is designed to be subclassed with the method:
*
* @code{.cpp}
* void run(void *data) { ... }
* @endcode
*
* For example:
*
* @code{.cpp}
* class CurlTestTask : public Task {
* void run(void *data) {
* // Do something
* }
* };
* @endcode
*
* implemented.
*/
class Task {
public:
Task(std::string taskName = "Task", uint16_t stackSize = 10000, uint8_t priority = 5);
virtual ~Task();
void setStackSize(uint16_t stackSize);
void setPriority(uint8_t priority);
void setName(std::string name);
void setCore(BaseType_t coreId);
void start(void* taskData = nullptr);
void stop();
/**
* @brief Body of the task to execute.
*
* This function must be implemented in the subclass that represents the actual task to run.
* When a task is started by calling start(), this is the code that is executed in the
* newly created task.
*
* @param [in] data The data passed in to the newly started task.
*/
virtual void run(void* data) = 0; // Make run pure virtual
static void delay(int ms);
private:
xTaskHandle m_handle;
void* m_taskData;
static void runTask(void* data);
std::string m_taskName;
uint16_t m_stackSize;
uint8_t m_priority;
BaseType_t m_coreId;
};
#endif /* COMPONENTS_CPP_UTILS_TASK_H_ */