FreeRTOS f*ckery

This commit is contained in:
Attila Body 2021-10-30 00:29:13 +02:00
parent 4e45521e52
commit 4e9d7b1334
8 changed files with 122 additions and 13 deletions

View file

@ -1,13 +1,13 @@
#ifndef __ili9341_H
#define __ili9341_H
#include <f4ll_cpp/singleton.h>
#include <f4ll_cpp/strangeton.h>
#include <f4ll_cpp/dmahelper.h>
#include <inttypes.h>
namespace f4ll_cpp {
class Ili9341Fsmc : public Singleton<Ili9341Fsmc>, private DmaHelper
class Ili9341Fsmc : public Strangeton<Ili9341Fsmc>, private DmaHelper
{
public:
struct PixelPair {

View file

@ -14,13 +14,8 @@ namespace f4ll_cpp {
template<typename T> class Singleton {
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;
static T &Instance() {
static T instance;
return instance;
}

View 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
View 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
View 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_ */