Fixed crashing timers by increasing the default task's stack

This commit is contained in:
dario
2023-10-10 11:31:27 +02:00
parent 1a9a96503e
commit cb41fb56e2
6 changed files with 42 additions and 15 deletions

View File

@@ -10,11 +10,6 @@
#include <sta/config.hpp>
#include <sta/tacos/thread.hpp>
#include <sta/rtos/timer.hpp>
#include <sta/debug/assert.hpp>
#ifndef STA_TACOS_NUM_STATES
# error "Number of states wasn't defined in config.hpp"
@@ -26,6 +21,13 @@
#endif
#include <sta/tacos/thread.hpp>
#include <sta/rtos/timer.hpp>
#include <sta/debug/assert.hpp>
#include <functional>
namespace sta
{
namespace tacos
@@ -52,6 +54,8 @@ namespace sta
uint16_t getCurrentState() const;
void setStateTransitionFunction(uint16_t (*function)(uint16_t));
private:
static Statemachine * _instance;
@@ -81,6 +85,7 @@ namespace sta
uint16_t currentState_;
RtosTimer lockoutTimer_;
RtosTimer failsafeTimer_;
std::function<uint16_t(uint16_t)> transitionFunc_;
};
} // namespace tacos
} // namespace sta

View File

@@ -15,7 +15,8 @@ namespace sta
namespace tacos
{
Statemachine::Statemachine()
: currentState_{STA_TACOS_INITIAL_STATE},
: TacosThread{"Statemachine", STA_TACOS_STATEMACHINE_PRIORITY},
currentState_{STA_TACOS_INITIAL_STATE},
lockoutTimer_{[](void *){}, nullptr},
failsafeTimer_{[](void *){}, nullptr}
{
@@ -24,18 +25,30 @@ namespace sta
void Statemachine::init()
{
STA_DEBUG_PRINTLN("INITIALIZING STATEMACHINE");
lockoutTimer_.setCallback([](void *) { STA_DEBUG_PRINTLN("[LOCKOUT TIMEOUT]"); }, nullptr);
lockoutTimer_.setCallback([](void *) { }, nullptr);
lockoutTimer_.start(5000);
failsafeTimer_.setCallback([](void * arg) { STA_DEBUG_PRINTLN("[FAILSAFE TIMEOUT]"); }, nullptr);
STA_DEBUG_PRINTLN("INITIALIZING STATEMACHINE");
failsafeTimer_.setCallback([](void * arg) { }, nullptr);
failsafeTimer_.start(10000);
}
void Statemachine::func()
{
/*
uint16_t next = transitionFunc_(currentState_);
STA_ASSERT(next < STA_TACOS_NUM_STATES);
if (next != currentState_)
{
currentState_ = next;
// TODO: Emit state transition event.
}*/
STA_DEBUG_PRINTLN(lockoutTimer_.isRunning() ? "[RUNNING]" : "[STOPPED]");
osDelay(1000);
}
uint16_t Statemachine::getCurrentState() const
@@ -43,6 +56,13 @@ namespace sta
return currentState_;
}
void Statemachine::setStateTransitionFunction(uint16_t (*function)(uint16_t))
{
STA_ASSERT(function != nullptr);
transitionFunc_ = function;
}
Statemachine* Statemachine::_instance = nullptr;
} // namespace tacos