Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ menu "Sparta Ion Config"
int "The actual battery voltage in mv for full (=100%). For example 42000mv for a 10s battery"
default 42000

config ION_KEEPALIVE
bool "Enable keepalive heartbeat. Will reset the ESP32 when main loop is stuck for more than a minute."
default n

endmenu
13 changes: 10 additions & 3 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ 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 @@ -76,16 +74,21 @@ enum messageHandlingResult {
};

static TimerHandle_t measureBatTimer;
TimerHandle_t healthCheckTimer ;

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

#if CONFIG_ION_KEEPALIVE
volatile bool myTaskAlive = false;
TimerHandle_t healthCheckTimer ;

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


static messageHandlingResult handleMotorMessage(ion_state * state) {
messageType message = {};
Expand Down Expand Up @@ -261,8 +264,10 @@ static void my_task(void *pvParameter) {
measureBatTimer = xTimerCreate("measureBatTimer", (100 / portTICK_PERIOD_MS), pdTRUE, (void *)0, measureBatTimerCallback);
xTimerStart(measureBatTimer, 0);

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

ion_state state = {
.state = IDLE,
Expand All @@ -278,7 +283,9 @@ static void my_task(void *pvParameter) {

while(true) {

#if CONFIG_ION_KEEPALIVE
myTaskAlive = true; // sign of life
#endif

// TODO:
// More use of timeouts
Expand Down
3 changes: 3 additions & 0 deletions sdkconfig.supermini
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ CONFIG_ION_ADC_EMPTY_MV=18000

# Consider 25.2V (4.2V/cell for 6s) full
CONFIG_ION_ADC_FULL_MV=25200

# keepalive
CONFIG_ION_KEEPALIVE=y
Loading