diff --git a/firmware/inc/hw_config.h b/firmware/inc/hw_config.h index 86850b0..82726c4 100644 --- a/firmware/inc/hw_config.h +++ b/firmware/inc/hw_config.h @@ -120,6 +120,11 @@ #define SI406X_TCXO_GCLK GCLK_GENERATOR_3 #define SI406X_TCXO_FREQUENCY 16369000 +/** + * Watchdog Timer + */ +#define WDT_GCLK GCLK_GENERATOR_4 + /** * External Watchdog Timer */ diff --git a/firmware/src/main.c b/firmware/src/main.c index 4122afe..7fbaae7 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -148,24 +148,24 @@ void set_timer(uint32_t time) tc_start_counter(TC2); } -/* void wdt_init() { */ -/* /\* 64 seconds timeout. So 2^(15+6) cycles of the wdt clock *\/ */ -/* system_gclk_gen_set_config(WDT_GCLK, */ -/* GCLK_SOURCE_OSCULP32K, /\* Source *\/ */ -/* false, /\* High When Disabled *\/ */ -/* 128, /\* Division Factor *\/ */ -/* false, /\* Run in standby *\/ */ -/* true); /\* Output Pin Enable *\/ */ -/* system_gclk_gen_enable(WDT_GCLK); */ +void wdt_init() { + /* 64 seconds timeout. So 2^(15+6) cycles of the wdt clock */ + system_gclk_gen_set_config(WDT_GCLK, + GCLK_SOURCE_OSCULP32K, /* Source */ + false, /* High When Disabled */ + 128, /* Division Factor */ + false, /* Run in standby */ + true); /* Output Pin Enable */ + system_gclk_gen_enable(WDT_GCLK); -/* /\* Set the watchdog timer. On 256Hz gclk 4 *\/ */ -/* wdt_set_config(true, /\* Lock WDT *\/ */ -/* true, /\* Enable WDT *\/ */ -/* GCLK_GENERATOR_4, /\* Clock Source *\/ */ -/* WDT_PERIOD_16384CLK, /\* Timeout Period *\/ */ -/* WDT_PERIOD_NONE, /\* Window Period *\/ */ -/* WDT_PERIOD_NONE); /\* Early Warning Period *\/ */ -/* } */ + /* Set the watchdog timer. On 256Hz gclk 4 */ + wdt_set_config(true, /* Lock WDT */ + true, /* Enable WDT */ + GCLK_GENERATOR_4, /* Clock Source */ + WDT_PERIOD_16384CLK, /* Timeout Period */ + WDT_PERIOD_NONE, /* Window Period */ + WDT_PERIOD_NONE); /* Early Warning Period */ +} int main(void) { @@ -201,6 +201,10 @@ int main(void) * --------------------------------------------------------------------------- */ + /* Set the wdt here. We should get to the first reset in one min */ + wdt_init(); + wdt_reset_count(); + led_init(); gps_init(); @@ -227,6 +231,9 @@ int main(void) port_pin_set_output_level(SI406X_GPIO0_PIN, 0); + /* Watchdog */ + wdt_reset_count(); + gps_update(); /* Request updates from the gps */ led_on();