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
27 lines
620 B
C
27 lines
620 B
C
typedef struct simple_watchdog_state_t {
|
|
uint32_t fault;
|
|
uint32_t last_ts;
|
|
uint32_t threshold;
|
|
} simple_watchdog_state_t;
|
|
|
|
simple_watchdog_state_t wd_state;
|
|
|
|
|
|
void simple_watchdog_kick(void) {
|
|
uint32_t ts = microsecond_timer_get();
|
|
|
|
uint32_t et = get_ts_elapsed(ts, wd_state.last_ts);
|
|
if (et > wd_state.threshold) {
|
|
print("WD timeout 0x"); puth(et); print("\n");
|
|
fault_occurred(wd_state.fault);
|
|
}
|
|
|
|
wd_state.last_ts = ts;
|
|
}
|
|
|
|
void simple_watchdog_init(uint32_t fault, uint32_t threshold) {
|
|
wd_state.fault = fault;
|
|
wd_state.threshold = threshold;
|
|
wd_state.last_ts = microsecond_timer_get();
|
|
}
|