Skip to content
Snippets Groups Projects
Commit efba5857 authored by Niccolò Betto's avatar Niccolò Betto
Browse files

[ConRIGv2] Adjust priority of various modules

* Radio
* Buttons
* Buzzer (set to low priority)
parent 32b25c0b
Branches
No related tags found
1 merge request!126RIGv2 and ConRIGv2 general development
......@@ -34,37 +34,68 @@ namespace ConRIGv2
class BoardScheduler : public Boardcore::Injectable
{
public:
BoardScheduler()
: radio{miosix::PRIORITY_MAX - 1}, buttons{miosix::PRIORITY_MAX - 2}
/**
* @brief Enclosing struct to avoid polluting the BoardScheduler namespace.
*/
struct Priority
{
}
/**
* @brief Priority levels for the board schedulers.
*/
enum PriorityLevel
{
LOW = miosix::PRIORITY_MAX - 4,
MEDIUM = miosix::PRIORITY_MAX - 3,
HIGH = miosix::PRIORITY_MAX - 2,
CRITICAL = miosix::PRIORITY_MAX - 1,
};
};
Boardcore::TaskScheduler& radio() { return high; }
Boardcore::TaskScheduler& buttons() { return critical; }
Boardcore::TaskScheduler& buzzer() { return medium; }
/**
* @brief Starts all the schedulers
*/
[[nodiscard]] bool start()
{
if (!radio.start())
if (!critical.start())
{
LOG_ERR(logger, "Failed to start radio scheduler");
LOG_ERR(logger, "Critical priority scheduler failed to start");
return false;
}
if (!buttons.start())
if (!high.start())
{
LOG_ERR(logger, "Failed to start buttons scheduler");
LOG_ERR(logger, "High priority scheduler failed to start");
return false;
}
return true;
if (!medium.start())
{
LOG_ERR(logger, "Medium priority scheduler failed to start");
return false;
}
Boardcore::TaskScheduler& getRadioScheduler() { return radio; }
started = true;
return true;
}
Boardcore::TaskScheduler& getButtonsScheduler() { return buttons; }
/**
* @brief Returns if all the schedulers are up and running
*/
bool isStarted() { return started; }
private:
Boardcore::TaskScheduler critical{Priority::CRITICAL};
Boardcore::TaskScheduler high{Priority::HIGH};
Boardcore::TaskScheduler medium{Priority::MEDIUM};
std::atomic<bool> started{false};
Boardcore::PrintLogger logger =
Boardcore::Logging::getLogger("boardscheduler");
Boardcore::TaskScheduler radio;
Boardcore::TaskScheduler buttons;
};
} // namespace ConRIGv2
......@@ -63,8 +63,7 @@ void printStateDiff(const mavlink_conrig_state_tc_t& oldState,
bool Buttons::start()
{
TaskScheduler& scheduler =
getModule<BoardScheduler>()->getButtonsScheduler();
TaskScheduler& scheduler = getModule<BoardScheduler>()->buttons();
return scheduler.addTask([this]() { periodicStatusCheck(); },
Config::Buttons::BUTTON_SAMPLE_PERIOD) != 0;
......
......@@ -36,6 +36,7 @@ using namespace miosix;
using namespace Boardcore;
using namespace ConRIGv2;
using namespace Common;
using namespace Boardcore::Units::Frequency;
SX1278Lora* gRadio{nullptr};
......@@ -241,9 +242,8 @@ bool Radio::start()
return false;
}
TaskScheduler& scheduler = getModule<BoardScheduler>()->getRadioScheduler();
if (scheduler.addTask([this]() { sendPeriodicPing(); },
auto& radioSched = getModule<BoardScheduler>()->radio();
if (radioSched.addTask([this]() { sendPeriodicPing(); },
Config::Radio::PING_GSE_PERIOD,
TaskScheduler::Policy::RECOVER) == 0)
{
......@@ -251,7 +251,8 @@ bool Radio::start()
return false;
}
scheduler.addTask([this]() { buzzerTask(); }, 50,
auto& buzzzerSched = getModule<BoardScheduler>()->buzzer();
buzzzerSched.addTask([this]() { buzzerTask(); }, 20_hz,
TaskScheduler::Policy::RECOVER);
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment