Files @ 752fd27f607a
Branch filter:

Location: therm-ng/src/system/watchdog.c

Ethan Zonca
Basic code cleanup
//
// Watchdog: configure and initialize the watchdog peripheral
//

#include "stm32f3xx_hal.h"

#include "config.h"
#include "watchdog.h"

#ifdef WATCHDOG_ENABLE
static IWDG_HandleTypeDef hiwdg;
uint8_t watchdog_enabled = 0;
#endif


// Initialize the watchdog timer
void watchdog_init(void)
{
#ifdef WATCHDOG_ENABLE
	// ~2 seconds?
    hiwdg.Instance = IWDG;
    hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
    hiwdg.Init.Window = 4095;
    hiwdg.Init.Reload = 4095;
    HAL_IWDG_Init(&hiwdg);
	watchdog_feed();
	HAL_IWDG_Start(&hiwdg);
	watchdog_enabled = 1;
#endif
}


// Feed the watchdog timer
void watchdog_feed(void)
{
#ifdef WATCHDOG_ENABLE
	if(watchdog_enabled)
		HAL_IWDG_Refresh(&hiwdg);
#endif
}