mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-03 06:33:50 +08:00
81da8ac9f4
date: 2024-06-11T01:36:39 master commit: f8cb04e4a8b032b72a909f68b808a50936184bee
25 lines
528 B
C
25 lines
528 B
C
typedef enum {
|
|
WATCHDOG_50_MS = (400U - 1U),
|
|
WATCHDOG_500_MS = 4000U,
|
|
} WatchdogTimeout;
|
|
|
|
void watchdog_feed(void) {
|
|
IND_WDG->KR = 0xAAAAU;
|
|
}
|
|
|
|
void watchdog_init(WatchdogTimeout timeout) {
|
|
// enable watchdog
|
|
IND_WDG->KR = 0xCCCCU;
|
|
IND_WDG->KR = 0x5555U;
|
|
|
|
// 32KHz / 4 prescaler = 8000Hz
|
|
register_set(&(IND_WDG->PR), 0x0U, IWDG_PR_PR_Msk);
|
|
register_set(&(IND_WDG->RLR), timeout, IWDG_RLR_RL_Msk);
|
|
|
|
// wait for watchdog to be updated
|
|
while (IND_WDG->SR != 0U);
|
|
|
|
// start the countdown
|
|
watchdog_feed();
|
|
}
|