Commit 2e84e69a authored by Rahix's avatar Rahix
Browse files

Merge branch 'wdt' into 'master'

Watchdog timer implementation
-----------------------------

Enable watchdog timer on boot. Add FreeRTOS task to clear the timer. 
Watchdog expires after 2.7 seconds, and is cleared every 2 seconds.

See merge request card10/firmware!172
parents 1f87386b bcb51a3c
......@@ -104,6 +104,9 @@ int main(void)
abort();
}
/* Watchdog petting */
watchdog_clearer_init();
LOG_DEBUG("startup", "Starting FreeRTOS ...");
vTaskStartScheduler();
......
......@@ -20,6 +20,7 @@
#include "rtc.h"
#include "spi.h"
#include "trng.h"
#include "wdt.h"
/*
* Early init is called at the very beginning and is meant for modules which
......@@ -28,6 +29,23 @@
*/
int hardware_early_init(void)
{
/*
* Watchdog timer
*/
sys_cfg_wdt_t wdt_cfg = NULL;
WDT_Init(MXC_WDT0, wdt_cfg);
if (WDT_GetResetFlag(MXC_WDT0)) {
WDT_ClearResetFlag(MXC_WDT0);
LOG_INFO("watchdog", "Reset due to watchdog timeout");
}
WDT_Enable(MXC_WDT0, 1);
WDT_SetResetPeriod(
MXC_WDT0,
WDT_PERIOD_2_27); /* Clocked by PCLK at 50MHz, reset at 2^27 ticks = 2.7 seconds */
WDT_EnableReset(MXC_WDT0, 1);
/*
* I2C bus for onboard peripherals (ie. PMIC, BMA400, BHI160, BME680,
* ...)
......
......@@ -18,4 +18,5 @@ module_sources = files(
'stream.c',
'trng.c',
'vibra.c',
'watchdog.c',
)
......@@ -35,6 +35,9 @@ int personal_state_enabled();
/* ---------- PMIC --------------------------------------------------------- */
void vPmicTask(void *pvParameters);
/* ---------- Watchdog ----------------------------------------------------- */
void watchdog_clearer_init();
/* Critical battery voltage */
#define BATTERY_CRITICAL 3.40f
......
#include "modules/log.h"
#include "modules/modules.h"
#include "timers.h"
#include "mxc_sys.h"
#include "wdt.h"
static TimerHandle_t clearer_timer;
static StaticTimer_t clearer_timer_buffer;
#define CLEAR_PERIOD pdMS_TO_TICKS(2000)
static void watchdog_clearer_callback()
{
WDT_ResetTimer(MXC_WDT0);
}
void watchdog_clearer_init()
{
clearer_timer = xTimerCreateStatic(
"watchdog_clearer_timer",
CLEAR_PERIOD,
pdTRUE,
NULL,
watchdog_clearer_callback,
&clearer_timer_buffer
);
xTimerStart(clearer_timer, 0);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment