Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ static const int MEASURE_BAT_BIT = BIT7;

static EventGroupHandle_t controlEventGroup;

volatile bool myTaskAlive = false;

enum messageHandlingResult {
// We got a handoff back, so we get to send the next message
CONTROL_TO_US,
Expand All @@ -74,9 +76,17 @@ enum messageHandlingResult {
};

static TimerHandle_t measureBatTimer;
TimerHandle_t healthCheckTimer ;

static void measureBatTimerCallback(TimerHandle_t xTimer) { xEventGroupSetBits(controlEventGroup, MEASURE_BAT_BIT); }

static void checkMyTaskHealth(TimerHandle_t xTimer) {
if (!myTaskAlive) {
esp_restart();
}
myTaskAlive = false; // Reset voor volgende check
}

static messageHandlingResult handleMotorMessage(ion_state * state) {
messageType message = {};
readResult result;
Expand Down Expand Up @@ -249,8 +259,10 @@ static void my_task(void *pvParameter) {
initMotor();

measureBatTimer = xTimerCreate("measureBatTimer", (100 / portTICK_PERIOD_MS), pdTRUE, (void *)0, measureBatTimerCallback);

xTimerStart(measureBatTimer, 0);

healthCheckTimer = xTimerCreate("healthCheckTimer", 60000 / portTICK_PERIOD_MS, pdTRUE, NULL, checkMyTaskHealth);
xTimerStart(healthCheckTimer, 0);

ion_state state = {
.state = IDLE,
Expand All @@ -266,6 +278,8 @@ static void my_task(void *pvParameter) {

while(true) {

myTaskAlive = true; // sign of life

// TODO:
// More use of timeouts
// See if we really need 8k stack (copying message structure a lot I guess)
Expand Down