Multiple bugfixes; working manager task

This commit is contained in:
dario
2023-10-15 22:37:04 +02:00
parent cb41fb56e2
commit 67f3e9aa15
6 changed files with 59 additions and 34 deletions

View File

@@ -20,9 +20,14 @@
# define STA_TACOS_INITIAL_STATE 0
#endif
#define TACOS_STATE_TRANSITION_FLAG 0x00000001U
#define TACOS_STATE_CHANGE_FORCED_FLAG 0x00000002U
#define TACOS_STATE_CHANGE_ALL_FLAG 0x00000003U
#include <sta/tacos/thread.hpp>
#include <sta/rtos/timer.hpp>
#include <sta/rtos/event.hpp>
#include <sta/debug/assert.hpp>
#include <functional>
@@ -35,6 +40,8 @@ namespace sta
class Statemachine : public TacosThread
{
public:
static RtosEvent* stateChangeEvent;
static Statemachine* instance()
{
static CGuard g;
@@ -43,6 +50,7 @@ namespace sta
{
// Create a the manager singleton instance.
Statemachine::_instance = new Statemachine();
Statemachine::stateChangeEvent = new RtosEvent();
}
return _instance;
@@ -52,10 +60,17 @@ namespace sta
void func() override;
/**
* @brief Returns the statemachine's current state.
*/
uint16_t getCurrentState() const;
void setStateTransitionFunction(uint16_t (*function)(uint16_t));
/**
* @brief Registers a new state transition function.
*/
void setStateTransitionFunction(std::function<uint16_t(uint16_t)> function);
void forceStateTransition(uint16_t state);
private:
static Statemachine * _instance;
@@ -67,7 +82,9 @@ namespace sta
if( NULL != Statemachine::_instance )
{
delete Statemachine::_instance;
delete Statemachine::stateChangeEvent;
Statemachine::_instance = NULL;
Statemachine::stateChangeEvent = NULL;
}
}
};
@@ -77,10 +94,6 @@ namespace sta
Statemachine(const Statemachine&);
~Statemachine() {}
private:
static void forceStateChange(void * arg);
private:
uint16_t currentState_;
RtosTimer lockoutTimer_;