Created
February 1, 2017 04:49
-
-
Save idt12312/b7f8379ad2b0b7c72079e3bb6723df12 to your computer and use it in GitHub Desktop.
FreeRTOSのタスクを楽に扱うクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef TASK_TASKBASE_H_ | |
#define TASK_TASKBASE_H_ | |
#include "FreeRTOS.h" | |
#include "task.h" | |
#include "queue.h" | |
#include "semphr.h" | |
class TaskBase { | |
public: | |
// デフォルトコンストラクタを禁止 | |
// 継承先のコンストラクタでTaskBaseの初期化を強制するため | |
TaskBase() = delete; | |
TaskBase(const char *_name, int _priority, uint32_t _stack_size=configMINIMAL_STACK_SIZE) | |
:name(_name), priority(_priority), stack_size(_stack_size) | |
{ | |
} | |
virtual ~TaskBase() | |
{ | |
delete_task(); | |
} | |
void create_task() | |
{ | |
xTaskCreate(task_entry_point, name, stack_size, this, priority, &handle); | |
} | |
void delete_task() | |
{ | |
vTaskDelete(handle); | |
} | |
protected: | |
xTaskHandle handle = 0; | |
const char *name; | |
int priority; | |
uint32_t stack_size; | |
virtual void task() = 0; | |
static void task_entry_point(void* task_instance) | |
{ | |
static_cast<TaskBase*>(task_instance)->task(); | |
} | |
}; | |
#endif /* TASK_TASKBASE_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment