FreeRTOS C++ Wrappers
TaskCPP.h
Go to the documentation of this file.
1 
38 #ifndef TaskCPP_H
39 #define TaskCPP_H
40 
41 #include "FreeRTOS.h"
42 #include "task.h"
43 
54  TaskPrio_Mid = (configMAX_PRIORITIES-1)/2,
55  TaskPrio_High = configMAX_PRIORITIES-2,
56  TaskPRio_Highest = configMAX_PRIORITIES-1
57 };
58 
68 class Task {
69 public:
81  Task(char const*name, void (*taskfun)(void *), TaskPriority priority,
82  unsigned portSHORT stackDepth, void * parm = 0) {
83  xTaskCreate(taskfun, name, stackDepth, parm, priority, &handle);
84  }
90  virtual ~Task() {
91 #if INCLUDE_vTaskDelete
92  if(handle){
93  vTaskDelete(handle);
94  }
95 #endif
96  return;
97  }
98 
99  TaskHandle_t handle;
100 private:
101 #if __cplusplus < 201101L
102  Task(Task const&);
103  void operator =(Task const&);
104 #else
105  Task(Task const&) = delete;
106  void operator =(Task const&) = delete;
107 #endif // __cplusplus
108 
109 };
110 
118 class TaskClass : public Task {
119 public:
131  TaskClass(char const*name,TaskPriority priority,
132  unsigned portSHORT stackDepth) :
133  Task(name, &taskfun, priority, stackDepth, this)
134  {
135  }
140  virtual void task() = 0;
141 
142 private:
150  static void taskfun(void* parm) {
151  static_cast<TaskClass *>(parm) -> task();
152  // If we get here, task has returned, delete ourselves or block indefinitely.
153 #if INCLUDE_vTaskDelete
154  handle = 0;
155  vTaskDelete(0); // Delete ourselves
156 #else
157  while(1)
158  vTaskDelay(portMAX_DELAY);
159 #endif
160  }
161 };
162 
163 #endif
Urgent tasks, short deadlines, not much processing.
Definition: TaskCPP.h:55
TaskClass(char const *name, TaskPriority priority, unsigned portSHORT stackDepth)
Constructor.
Definition: TaskCPP.h:131
Non-Real Time operatons.
Definition: TaskCPP.h:51
TaskHandle_t handle
Handle for the task we are managing.
Definition: TaskCPP.h:99
Non-Critical operations.
Definition: TaskCPP.h:52
Normal User Interface Level.
Definition: TaskCPP.h:53
virtual void task()=0
task function. The member function task needs to
Make a class based task. Derive from TaskClass and the 'task()' member function will get called as th...
Definition: TaskCPP.h:118
Lowest Level Wrapper. Create the specified task with a provided task function.
Definition: TaskCPP.h:68
Critical Tasks, Do NOW, must be quick (Used by FreeRTOS)
Definition: TaskCPP.h:56
Task(char const *name, void(*taskfun)(void *), TaskPriority priority, unsigned portSHORT stackDepth, void *parm=0)
Constructor.
Definition: TaskCPP.h:81
TaskPriority
Definition: TaskCPP.h:50
Semi-Critical, have deadlines, not a lot of processing.
Definition: TaskCPP.h:54
virtual ~Task()
Destructor.
Definition: TaskCPP.h:90