watchdog.c 957 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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);
}

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void watchdog_init()
{
	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", "Last reset was due to watchdog timeout");
	}

	WDT_Enable(MXC_WDT0, 1);
	WDT_SetResetPeriod(
		MXC_WDT0,
		WDT_PERIOD_2_28); /* Clocked by PCLK at 50MHz, reset at 2^28 ticks = 5.4 seconds */
	WDT_EnableReset(MXC_WDT0, 1);
}

34
35
void watchdog_clearer_init()
{
36
37
	WDT_ResetTimer(MXC_WDT0);

38
39
40
41
42
43
44
45
46
47
	clearer_timer = xTimerCreateStatic(
		"watchdog_clearer_timer",
		CLEAR_PERIOD,
		pdTRUE,
		NULL,
		watchdog_clearer_callback,
		&clearer_timer_buffer
	);
	xTimerStart(clearer_timer, 0);
}