mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-08-06 01:37:33 +00:00
Added reworked manager / statemachine tasks, thread implementation and new directory layout
This commit is contained in:
86
Tacos/include/sta/tacos/manager.hpp
Normal file
86
Tacos/include/sta/tacos/manager.hpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* manager.hpp
|
||||
*
|
||||
* Created on: Sep 19, 2023
|
||||
* Author: Dario
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_STA_TACOS_MANAGER_HPP_
|
||||
#define INCLUDE_STA_TACOS_MANAGER_HPP_
|
||||
|
||||
|
||||
#include <sta/config.hpp>
|
||||
|
||||
#ifndef STA_TACOS_MANAGER_PRIORITY
|
||||
# error "Manger task priority not specified in config.hpp"
|
||||
#else
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <sta/tacos/thread.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
namespace tacos
|
||||
{
|
||||
class Manager : public TacosThread
|
||||
{
|
||||
public:
|
||||
static Manager* instance()
|
||||
{
|
||||
static CGuard g;
|
||||
|
||||
if (!_instance)
|
||||
{
|
||||
// Create a the manager singleton instance.
|
||||
Manager::_instance = new Manager();
|
||||
|
||||
// Start the manager task as a tacos task.
|
||||
Manager::_instance->start();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void registerThread(TacosThread thread, std::list<uint16_t> states);
|
||||
|
||||
void init() override;
|
||||
|
||||
void func() override;
|
||||
|
||||
private:
|
||||
class CGuard
|
||||
{
|
||||
public:
|
||||
~CGuard()
|
||||
{
|
||||
if( NULL != Manager::_instance )
|
||||
{
|
||||
delete Manager::_instance;
|
||||
Manager::_instance = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static Manager* _instance;
|
||||
|
||||
Manager();
|
||||
|
||||
Manager(const Manager&);
|
||||
|
||||
~Manager() {}
|
||||
|
||||
void updateThreads();
|
||||
|
||||
void startThreads(uint16_t state);
|
||||
|
||||
void stopThreads(uint16_t state);
|
||||
|
||||
std::set<TacosThread> threads_[STA_TACOS_NUM_STATES];
|
||||
};
|
||||
} // namespace tacos
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_TACOS_MANAGER_PRIORITY
|
||||
|
||||
#endif /* INCLUDE_STA_TACOS_MANAGER_HPP_ */
|
31
Tacos/include/sta/tacos/startup.hpp
Normal file
31
Tacos/include/sta/tacos/startup.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* startup.hpp
|
||||
*
|
||||
* Created on: 22 Sep 2023
|
||||
* Author: Dario
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_STA_TACOS_STARTUP_HPP_
|
||||
#define INCLUDE_STA_TACOS_STARTUP_HPP_
|
||||
|
||||
namespace sta
|
||||
{
|
||||
namespace tacos
|
||||
{
|
||||
/**
|
||||
* @brief Function that is called before the statemachine task is started.
|
||||
* Override it to adjust the statemachine to your specifications.
|
||||
*/
|
||||
void onStatemachineInit();
|
||||
|
||||
/**
|
||||
* @brief Function that is called before the manager task is started.
|
||||
* Override it to adjust the manager to your specifications.
|
||||
*/
|
||||
void onManagerInit();
|
||||
} // namespace tacos
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
||||
#endif /* INCLUDE_STA_TACOS_STARTUP_HPP_ */
|
73
Tacos/include/sta/tacos/statemachine.hpp
Normal file
73
Tacos/include/sta/tacos/statemachine.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* statemachine.hpp
|
||||
*
|
||||
* Created on: Sep 14, 2023
|
||||
* Author: Dario
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_TACOS_STATEMACHINE_HPP_
|
||||
#define INCLUDE_TACOS_STATEMACHINE_HPP_
|
||||
|
||||
#include <sta/config.hpp>
|
||||
|
||||
#include <sta/tacos/thread.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
namespace tacos
|
||||
{
|
||||
class Statemachine : public TacosThread
|
||||
{
|
||||
public:
|
||||
static Statemachine* instance()
|
||||
{
|
||||
static CGuard g;
|
||||
|
||||
if (!_instance)
|
||||
{
|
||||
// Create a the manager singleton instance.
|
||||
Statemachine::_instance = new Statemachine();
|
||||
|
||||
// Start the manager task as a tacos task.
|
||||
Statemachine::_instance->start();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void init() override;
|
||||
|
||||
void func() override;
|
||||
|
||||
uint16_t getCurrentState();
|
||||
|
||||
private:
|
||||
class CGuard
|
||||
{
|
||||
public:
|
||||
~CGuard()
|
||||
{
|
||||
if( NULL != Statemachine::_instance )
|
||||
{
|
||||
delete Statemachine::_instance;
|
||||
Statemachine::_instance = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Statemachine();
|
||||
|
||||
Statemachine(const Statemachine&);
|
||||
|
||||
~Statemachine() {}
|
||||
|
||||
static Statemachine * _instance;
|
||||
|
||||
uint16_t currentState_;
|
||||
};
|
||||
} // namespace tacos
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
||||
#endif /* INCLUDE_TACOS_STATEMACHINE_HPP_ */
|
78
Tacos/include/sta/tacos/thread.hpp
Normal file
78
Tacos/include/sta/tacos/thread.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* task.hpp
|
||||
*
|
||||
* Created on: Sep 14, 2023
|
||||
* Author: Dario
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_TACOS_TASK_HPP_
|
||||
#define INCLUDE_TACOS_TASK_HPP_
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
#include <sta/rtos/thread.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
namespace tacos
|
||||
{
|
||||
class TacosThread : public RtosThread
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TacosThread(const char* name, osPriority_t prio);
|
||||
|
||||
virtual ~TacosThread();
|
||||
|
||||
/**
|
||||
* @brief Start the execution of this thread.
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* @brief Checks if this thread is currently running.
|
||||
*/
|
||||
bool isRunning();
|
||||
|
||||
/**
|
||||
* @brief Get the currently running instance.
|
||||
*/
|
||||
osThreadId_t getInstance();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const char* getName() const;
|
||||
|
||||
bool operator==(const TacosThread& other) const;
|
||||
bool operator<(const TacosThread& other) const;
|
||||
|
||||
/**
|
||||
* @brief A function that wraps this task's functionality in a loop. This loop will run until
|
||||
* termination is requested.
|
||||
*/
|
||||
void loop();
|
||||
|
||||
virtual void init();
|
||||
|
||||
/**
|
||||
* @brief The body of the thread's loop. Has to be implemented by the user.
|
||||
*/
|
||||
virtual void func();
|
||||
private:
|
||||
/**
|
||||
* @brief Static function to pass to RTOS to run as a thread. Calls the loop function implemented here.
|
||||
*/
|
||||
static void entry_point(void* arg);
|
||||
|
||||
osThreadId_t instance_;
|
||||
osThreadAttr_t attribs_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* INCLUDE_TACOS_TASK_HPP_ */
|
Reference in New Issue
Block a user