FreeRTOS f*ckery
This commit is contained in:
parent
4e45521e52
commit
4e9d7b1334
8 changed files with 122 additions and 13 deletions
|
@ -17,11 +17,24 @@
|
||||||
|
|
||||||
using namespace f4ll_cpp;
|
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()
|
void MainLoop()
|
||||||
{
|
{
|
||||||
Application m;
|
// Application m;
|
||||||
|
//
|
||||||
m.Loop();
|
// 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
|
#define CMD_X_READ 0b10010000
|
||||||
|
@ -51,10 +64,16 @@ uint16_t ReadTouch(SPI_TypeDef *spi, bool x)
|
||||||
|
|
||||||
Application::Application()
|
Application::Application()
|
||||||
: GlobalsInitializer(&m_console)
|
: GlobalsInitializer(&m_console)
|
||||||
|
, Task(3)
|
||||||
, m_console(USART1, DMA2, LL_DMA_STREAM_2, LL_DMA_STREAM_7, this, nullptr)
|
, m_console(USART1, DMA2, LL_DMA_STREAM_2, LL_DMA_STREAM_7, this, nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::TaskFn(void *taskObj)
|
||||||
|
{
|
||||||
|
static_cast<Application*>(reinterpret_cast<fsl::Task<Application, 1024>*>(taskObj))->Loop();
|
||||||
|
}
|
||||||
|
|
||||||
void Application::Loop()
|
void Application::Loop()
|
||||||
{
|
{
|
||||||
Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, false));
|
Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, false));
|
||||||
|
|
|
@ -20,6 +20,7 @@ void MainLoop();
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#include <f4ll_cpp/serialconsole.h>
|
#include <f4ll_cpp/serialconsole.h>
|
||||||
|
#include <fsl/task.h>
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
struct GlobalsInitializer {
|
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<Application, 1024>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
Application();
|
Application();
|
||||||
void Loop();
|
void Loop();
|
||||||
|
|
||||||
|
friend class fsl::Task<Application, 1024>;
|
||||||
private:
|
private:
|
||||||
|
static void TaskFn(void *taskObj);
|
||||||
|
|
||||||
virtual void LineReceived(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer);
|
virtual void LineReceived(void *userParam, f4ll_cpp::SerialConsole<257>::Buffer *buffer);
|
||||||
virtual void TransmissionComplete(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;
|
f4ll_cpp::SerialConsole<257> m_console;
|
||||||
volatile bool m_lineReceived = false;
|
volatile bool m_lineReceived = false;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "application.h"
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
@ -100,6 +101,7 @@ int main(void)
|
||||||
MX_SPI2_Init();
|
MX_SPI2_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
MainLoop();
|
||||||
|
|
||||||
/* Init scheduler */
|
/* Init scheduler */
|
||||||
osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */
|
osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#ifndef __ili9341_H
|
#ifndef __ili9341_H
|
||||||
#define __ili9341_H
|
#define __ili9341_H
|
||||||
|
|
||||||
#include <f4ll_cpp/singleton.h>
|
#include <f4ll_cpp/strangeton.h>
|
||||||
#include <f4ll_cpp/dmahelper.h>
|
#include <f4ll_cpp/dmahelper.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
namespace f4ll_cpp {
|
namespace f4ll_cpp {
|
||||||
|
|
||||||
class Ili9341Fsmc : public Singleton<Ili9341Fsmc>, private DmaHelper
|
class Ili9341Fsmc : public Strangeton<Ili9341Fsmc>, private DmaHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct PixelPair {
|
struct PixelPair {
|
||||||
|
|
|
@ -14,13 +14,8 @@ namespace f4ll_cpp {
|
||||||
|
|
||||||
template<typename T> class Singleton {
|
template<typename T> class Singleton {
|
||||||
public:
|
public:
|
||||||
static T &Instance() { return *m_instance; }
|
static T &Instance() {
|
||||||
template<typename ... Args>
|
static T instance;
|
||||||
static T &Init(Args &&... args)
|
|
||||||
{
|
|
||||||
static T instance{ std::forward<Args>(args)... };
|
|
||||||
if(!m_instance)
|
|
||||||
m_instance = &instance;
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
components/f4ll_cpp/strangeton.h
Normal file
39
components/f4ll_cpp/strangeton.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* singleton.h
|
||||||
|
*
|
||||||
|
* Created on: Sep 11, 2019
|
||||||
|
* Author: compi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SINGLETON_H_
|
||||||
|
#define SINGLETON_H_
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace f4ll_cpp {
|
||||||
|
|
||||||
|
template<typename T> class Strangeton {
|
||||||
|
public:
|
||||||
|
static T &Instance() {
|
||||||
|
return *m_instance;
|
||||||
|
}
|
||||||
|
template<typename ... Args> static T &Init(Args &&... args) {
|
||||||
|
static T instance{ std::forward<Args>(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<typename T> T* Strangeton<T>::m_instance = nullptr;
|
||||||
|
|
||||||
|
} // f4ll_cpp
|
||||||
|
|
||||||
|
#endif /* SINGLETON_H_ */
|
10
components/fsl/task.cpp
Normal file
10
components/fsl/task.cpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* task.cpp
|
||||||
|
*
|
||||||
|
* Created on: Oct 29, 2021
|
||||||
|
* Author: compi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <fsl/task.h>
|
||||||
|
|
||||||
|
|
36
components/fsl/task.h
Normal file
36
components/fsl/task.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* task.h
|
||||||
|
*
|
||||||
|
* Created on: Oct 29, 2021
|
||||||
|
* Author: compi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FSL_TASK_H_
|
||||||
|
#define FSL_TASK_H_
|
||||||
|
|
||||||
|
#include <FreeRTOS.h>
|
||||||
|
#include <task.h> // FreeRTOS
|
||||||
|
#include <semphr.h> // FreeRTOS
|
||||||
|
|
||||||
|
namespace fsl {
|
||||||
|
|
||||||
|
template<typename T, uint32_t stackSize> 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_ */
|
Loading…
Add table
Add a link
Reference in a new issue