diff --git a/source/shoh/src/main.cpp b/source/shoh/src/main.cpp index c0ef414..81ea5a8 100644 --- a/source/shoh/src/main.cpp +++ b/source/shoh/src/main.cpp @@ -3,15 +3,18 @@ #include "FreeRTOS.h" #include "task.h" #include +#include "common/ThreadCommon.h" #include "Master.h" + int main(void) { SystemCoreClockUpdate(); Board_Init(); - // Create a task before starting the scheduler. - Master master("Master", configMINIMAL_STACK_SIZE * 10, nullptr, tskIDLE_PRIORITY + 1UL); - + ThreadCommon::ThreadManager manager; + manager.createTask(master_thread, "master", + configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL, + nullptr); // Start the real time kernel with preemption. //FreeRTOS::Kernel::startScheduler(); vTaskStartScheduler (); diff --git a/source/shoh/src/threads/common/ThreadCommon.h b/source/shoh/src/threads/common/ThreadCommon.h index 29d3718..d8fe51f 100644 --- a/source/shoh/src/threads/common/ThreadCommon.h +++ b/source/shoh/src/threads/common/ThreadCommon.h @@ -4,9 +4,16 @@ * Created on: 13 Apr 2023 * Author: tylen */ + +#ifndef __THREAD_COMMON_H_ +#define __THREAD_COMMON_H_ + #include "board.h" #include "FreeRTOS.h" +#include #include "queue.h" +#include "task.h" +#include namespace ThreadCommon { @@ -41,12 +48,25 @@ namespace ThreadCommon uint8_t _data; }; + class ThreadManager + { + public: + ThreadManager(); + ~ThreadManager() = default; + bool createTask(void (*task_func)(void*), + std::string name, + size_t stack_size, + size_t priority, + void* parameters); + private: + }; + /* global variables */ /* 'receiver'_'what'_'sender'_q */ extern QueueHandle_t master_event_all_q; extern QueueHandle_t relay_event_master_q; extern QueueHandle_t manager_event_master_q; extern QueueHandle_t ui_event_manager_q; - - } + +#endif /*__THREAD_COMMON_H_*/ diff --git a/source/shoh/src/threads/common/ThreadManager.cpp b/source/shoh/src/threads/common/ThreadManager.cpp new file mode 100644 index 0000000..2ac2803 --- /dev/null +++ b/source/shoh/src/threads/common/ThreadManager.cpp @@ -0,0 +1,21 @@ +#include "ThreadCommon.h" + + +ThreadCommon::ThreadManager::ThreadManager(){} + +bool ThreadCommon::ThreadManager::createTask(void (*task_func)(void*), + std::string name, + size_t stack_size, + size_t priority, + void* parameters) +{ + const char * t_name = name.c_str(); + BaseType_t taskCreated = xTaskCreate(task_func, + t_name, + stack_size, + parameters, + priority, + NULL); + assert(taskCreated == pdPASS); + return (taskCreated == pdPASS); +} diff --git a/source/shoh/src/threads/master/Master.cpp b/source/shoh/src/threads/master/Master.cpp index 408a2ce..1ef3bc0 100644 --- a/source/shoh/src/threads/master/Master.cpp +++ b/source/shoh/src/threads/master/Master.cpp @@ -7,15 +7,8 @@ #include "Master.h" -Master::Master(std::string name, size_t stack_size, void* pvParams, size_t task_priority) -: name(name), stack_size(stack_size), pvParams(pvParams), task_priority(task_priority) -{ - xTaskCreate (Master::taskWrapper, "Master_thread", this->stack_size, this->pvParams, this->task_priority, this->master_task_handle); -} - -Master::~Master(){} - void Master::taskFunction() { + int led = 0; bool LedState = true; for (;;) { Board_LED_Set(led, LedState); @@ -27,3 +20,9 @@ void Master::taskFunction() { vTaskDelay(1000); } } + + +void master_thread(void* pvParams) { + Master m; + m.taskFunction(); +} \ No newline at end of file diff --git a/source/shoh/src/threads/master/Master.h b/source/shoh/src/threads/master/Master.h index f3805ca..bcc173d 100644 --- a/source/shoh/src/threads/master/Master.h +++ b/source/shoh/src/threads/master/Master.h @@ -16,26 +16,17 @@ class Master { public: - Master(std::string name, size_t stack_size, void* pvParams, size_t task_priority); - virtual ~Master(); + Master(){}; + virtual ~Master() = default; void taskFunction(); - static void taskWrapper(void *pvParams) { - Master* pSelf = reinterpret_cast(pvParams); - pSelf->taskFunction(); - } - //Master(Master&&) noexcept = default; //Master& operator=(Master&&) noexcept = default; private: - int led; - std::string name; - size_t stack_size; - void* pvParams; - size_t task_priority; - TaskHandle_t* master_task_handle; - //std::shared_ptr message; + ThreadCommon::Event* message; }; +void master_thread(void* pvParams); + #endif /* THREADS_MASTER_MASTER_H_ */