From: Nathael Pajani Date: Sun, 30 Jan 2022 03:16:01 +0000 (+0100) Subject: Update watchdog code to allow use of watchdog as wake-up source X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=52ed3909f57962b814919b3115d71afc62c2e200;p=soft%2Flpc82x%2Fcore Update watchdog code to allow use of watchdog as wake-up source --- diff --git a/core/watchdog.c b/core/watchdog.c index ae3870c..93ffec4 100644 --- a/core/watchdog.c +++ b/core/watchdog.c @@ -30,6 +30,7 @@ + /***************************************************************************** */ void watchdog_feed(void) { @@ -66,7 +67,9 @@ uint32_t watchdog_get_timer_val(void) return wdt->timer_value; } + /* Change the watchdog timer value, if not protected */ +#define LPC_WDT_TIMER_MAX 0xFFFFFF /* This one is the shiffted value, and must not be exported to user */ void watchdog_set_timer_val(uint32_t nb_clk) { struct lpc_watchdog* wdt = LPC_WDT; @@ -143,10 +146,10 @@ void watchdog_config(const struct wdt_config* wd_conf) /* Power wadchdog block before changing it's configuration */ subsystem_power(LPC_SYS_AHB_CLK_CTRL_Watchdog, 1); - /* Configure the watchdog clock source frequency */ - sys_config->WDT_osc_ctrl = LPC_WDT_CLK_DIVIDER(4) | LPC_WDT_FREQSEL_4MHz; /* 1MHz */ /* Power ON Watchdog clock */ sys_config->powerdown_run_cfg &= ~(LPC_POWER_DOWN_WDT_OSC); + /* Configure the watchdog clock source frequency */ + sys_config->WDT_osc_ctrl = LPC_WDT_CLK_DIVIDER(4) | LPC_WDT_FREQSEL_4MHz; /* 1MHz */ /* Configure watchdog timeout for normal operation */ wdt->timer_const = ((wd_conf->nb_clk >> 2) & LPC_WDT_TIMER_MAX); @@ -177,6 +180,9 @@ void watchdog_config(const struct wdt_config* wd_conf) } } + /* Enable Watchdog as wakeup source from deep sleep and power down modes */ + enable_intr_wake_source(LPC_WWDT_INT_WAKEUP_EN); + /* Feed sequence to validate the configuration */ watchdog_feed(); diff --git a/include/core/watchdog.h b/include/core/watchdog.h index 8cbf288..de6df1f 100644 --- a/include/core/watchdog.h +++ b/include/core/watchdog.h @@ -74,7 +74,9 @@ void watchdog_clear_timeout_flag(void); /* Return current watchdog timer value */ uint32_t watchdog_get_timer_val(void); -/* Change the watchdog timer value, if not protected */ +/* Change the watchdog timer value, if not protected + * The change will take effect at the next watchdog feed. + */ void watchdog_set_timer_val(uint32_t nb_clk); @@ -140,7 +142,7 @@ struct lpc_watchdog }; #define LPC_WDT ((struct lpc_watchdog *) LPC_WDT_BASE) -#define LPC_WDT_TIMER_MAX 0xFFFFFF +#define LPC_WATCHDOG_TIMER_MAX_VAL 0x03FFFFFF /* Mode register */ #define LPC_WDT_EN (0x01 << 0)