Skip to main content

wdt-feed

Open the watchdog, feed it on a cadence, then disable it; then open it again in interrupt-only mode with an expiry callback. The minimal demo for <alp/wdt.h>.

Source: examples/power-timing/wdt-feed/.

board.yaml​

som:
sku: E1M-AEN801

preset: e1m-evk

cores:
m55_hp:
app: ./src
peripherals: [watchdog]

diagnostics:
log_level: info

Source (abbreviated)​

#include <stdio.h>

#include "alp/peripheral.h"
#include "alp/e1m_pinout.h"
#include "alp/wdt.h"

static void on_wdt_expire(alp_wdt_t *wdt, void *user) {
(void)wdt;
printf("[wdt] on_expire fired, user=%p\n", user);
}

int main(void) {
/* 1. Reset mode: the watchdog runs from open(); feed it within 5 s. */
alp_wdt_t *wdt = alp_wdt_open(&(alp_wdt_config_t){
.wdt_id = ALP_E1M_WDT0,
.timeout_ms = 5000,
.on_timeout = ALP_WDT_RESET_SOC,
});
if (wdt != NULL) {
for (int i = 0; i < 3; i++) {
printf("[wdt] feed %d -> %d\n", i, (int)alp_wdt_feed(wdt));
alp_delay_ms(500);
}
/* ALP_ERR_NOSUPPORT on a one-shot watchdog that cannot be stopped */
printf("[wdt] disable -> %d\n", (int)alp_wdt_disable(wdt));
alp_wdt_close(wdt);
}

/* 2. Interrupt-only mode needs an on_expire callback. */
int cookie = 42;
alp_wdt_t *wdt_irq = alp_wdt_open(&(alp_wdt_config_t){
.wdt_id = ALP_E1M_WDT0,
.timeout_ms = 5000,
.on_timeout = ALP_WDT_INTERRUPT_ONLY,
.on_expire = on_wdt_expire,
.user = &cookie,
});
if (wdt_irq != NULL) {
alp_wdt_feed(wdt_irq);
alp_wdt_close(wdt_irq);
}
return 0;
}

Expected behaviour​

Three feeds 500 ms apart, then alp_wdt_disable(). A watchdog that cannot be stopped once started returns ALP_ERR_NOSUPPORT there, which is expected. The interrupt-only open, feed and close follow. <alp/wdt.h> has no separate start call (the watchdog runs from alp_wdt_open()) and no reset-cause query.

See also​

Questions about this page? Email contact@alplab.ai