diff --git a/App/application.cpp b/App/application.cpp index c5f712d..920f67a 100644 --- a/App/application.cpp +++ b/App/application.cpp @@ -17,11 +17,24 @@ using namespace f4ll_cpp; +TaskHandle_t g_handle; +StaticTask_t g_tcb; +StackType_t g_stack[200]; + +void TaskFn(void * param) +{ + for(;;) { + vTaskDelay(100); + } +} + void MainLoop() { - Application m; - - m.Loop(); +// Application m; +// +// m.Start(); + g_handle = xTaskCreateStatic(TaskFn, "lofasz", sizeof(g_stack)/sizeof(g_stack[0]), + nullptr, 5, g_stack, &g_tcb); } #define CMD_X_READ 0b10010000 @@ -51,10 +64,16 @@ uint16_t ReadTouch(SPI_TypeDef *spi, bool x) Application::Application() : GlobalsInitializer(&m_console) +, Task(3) , m_console(USART1, DMA2, LL_DMA_STREAM_2, LL_DMA_STREAM_7, this, nullptr) { } +void Application::TaskFn(void *taskObj) +{ + static_cast(reinterpret_cast*>(taskObj))->Loop(); +} + void Application::Loop() { Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, false)); diff --git a/App/application.h b/App/application.h index 38a5222..ca780a1 100644 --- a/App/application.h +++ b/App/application.h @@ -20,6 +20,7 @@ void MainLoop(); #if defined(__cplusplus) #include +#include #include "globals.h" struct GlobalsInitializer { @@ -28,14 +29,21 @@ struct GlobalsInitializer { } }; -class Application : public GlobalsInitializer, public f4ll_cpp::SerialConsole<257>::ISerialConsoleCallback { +class Application : public GlobalsInitializer + , public f4ll_cpp::SerialConsole<257>::ISerialConsoleCallback + , public fsl::Task +{ public: Application(); void Loop(); + friend class fsl::Task; private: + static void TaskFn(void *taskObj); + virtual void LineReceived(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer); virtual void TransmissionComplete(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer); + virtual char const * getName() { return "Application"; } f4ll_cpp::SerialConsole<257> m_console; volatile bool m_lineReceived = false; diff --git a/Src/main.c b/Src/main.c index 61cd818..99deb1b 100644 --- a/Src/main.c +++ b/Src/main.c @@ -29,6 +29,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "application.h" /* USER CODE END Includes */ @@ -100,6 +101,7 @@ int main(void) MX_SPI2_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ + MainLoop(); /* Init scheduler */ osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */ diff --git a/components/f4ll_cpp/ili9341.h b/components/f4ll_cpp/ili9341.h index 02ce413..5ed58f2 100644 --- a/components/f4ll_cpp/ili9341.h +++ b/components/f4ll_cpp/ili9341.h @@ -1,13 +1,13 @@ #ifndef __ili9341_H #define __ili9341_H -#include +#include #include #include namespace f4ll_cpp { -class Ili9341Fsmc : public Singleton, private DmaHelper +class Ili9341Fsmc : public Strangeton, private DmaHelper { public: struct PixelPair { diff --git a/components/f4ll_cpp/singleton.h b/components/f4ll_cpp/singleton.h index 75a52f8..6c089b4 100644 --- a/components/f4ll_cpp/singleton.h +++ b/components/f4ll_cpp/singleton.h @@ -14,13 +14,8 @@ namespace f4ll_cpp { template class Singleton { public: - static T &Instance() { return *m_instance; } - template - static T &Init(Args &&... args) - { - static T instance{ std::forward(args)... }; - if(!m_instance) - m_instance = &instance; + static T &Instance() { + static T instance; return instance; } diff --git a/components/f4ll_cpp/strangeton.h b/components/f4ll_cpp/strangeton.h new file mode 100644 index 0000000..89cfb71 --- /dev/null +++ b/components/f4ll_cpp/strangeton.h @@ -0,0 +1,39 @@ +/* + * singleton.h + * + * Created on: Sep 11, 2019 + * Author: compi + */ + +#ifndef SINGLETON_H_ +#define SINGLETON_H_ + +#include + +namespace f4ll_cpp { + +template class Strangeton { +public: + static T &Instance() { + return *m_instance; + } + template static T &Init(Args &&... args) { + static T instance{ std::forward(args)... }; + if(!m_instance) + m_instance = &instance; + return instance; + } + +protected: + Strangeton() = default; + Strangeton(const Strangeton &) = delete; + Strangeton &operator=(const Strangeton &) = delete; + virtual ~Strangeton() = default; + static T *m_instance; +}; + +template T* Strangeton::m_instance = nullptr; + +} // f4ll_cpp + +#endif /* SINGLETON_H_ */ diff --git a/components/fsl/task.cpp b/components/fsl/task.cpp new file mode 100644 index 0000000..cf5ee8b --- /dev/null +++ b/components/fsl/task.cpp @@ -0,0 +1,10 @@ +/* + * task.cpp + * + * Created on: Oct 29, 2021 + * Author: compi + */ + +#include + + diff --git a/components/fsl/task.h b/components/fsl/task.h new file mode 100644 index 0000000..9b1a597 --- /dev/null +++ b/components/fsl/task.h @@ -0,0 +1,36 @@ +/* + * task.h + * + * Created on: Oct 29, 2021 + * Author: compi + */ + +#ifndef FSL_TASK_H_ +#define FSL_TASK_H_ + +#include +#include // FreeRTOS +#include // FreeRTOS + +namespace fsl { + +template class Task { +public: + Task(UBaseType_t priority) : m_priority(priority) {} + void Start(SemaphoreHandle_t doneSem = nullptr, bool waitForInit = false) { + m_handle = xTaskCreateStatic(T::TaskFn, getName(), sizeof(m_stack)/sizeof(m_stack[0]), + this, m_priority, m_stack, &m_tcb); + } + virtual ~Task() {}; + virtual char const * getName() = 0; + +private: + TaskHandle_t m_handle; + UBaseType_t m_priority; + StaticTask_t m_tcb; + StackType_t m_stack[stackSize]; +}; + +} /* namespace fsl */ + +#endif /* FSL_TASK_H_ */