diff --git a/include/task_wdt/task_wdt.h b/include/task_wdt/task_wdt.h index cd3ba078315..68d488b3738 100644 --- a/include/task_wdt/task_wdt.h +++ b/include/task_wdt/task_wdt.h @@ -47,6 +47,9 @@ typedef void (*task_wdt_callback_t)(int channel_id, void *user_data); * * @retval 0 If successful. * @retval -ENOTSUP If assigning a hardware watchdog is not supported. + * @retval -Errno Negative errno if the fallback hw_wdt is used and the + * install timeout API fails. See wdt_install_timeout() + * API for possible return values. */ int task_wdt_init(const struct device *hw_wdt); diff --git a/samples/subsys/task_wdt/src/main.c b/samples/subsys/task_wdt/src/main.c index 2855d1068a4..c5c3bdf7e4c 100644 --- a/samples/subsys/task_wdt/src/main.c +++ b/samples/subsys/task_wdt/src/main.c @@ -58,6 +58,7 @@ static void task_wdt_callback(int channel_id, void *user_data) void main(void) { + int ret; #ifdef WDT_NODE const struct device *hw_wdt_dev = DEVICE_DT_GET(WDT_NODE); #else @@ -72,7 +73,12 @@ void main(void) hw_wdt_dev = NULL; } - task_wdt_init(hw_wdt_dev); + ret = task_wdt_init(hw_wdt_dev); + if (ret != 0) { + printk("task wdt init failure: %d\n", ret); + return; + } + /* passing NULL instead of callback to trigger system reset */ int task_wdt_id = task_wdt_add(1100U, NULL, NULL); diff --git a/subsys/task_wdt/task_wdt.c b/subsys/task_wdt/task_wdt.c index 71219182bbb..7941313be97 100644 --- a/subsys/task_wdt/task_wdt.c +++ b/subsys/task_wdt/task_wdt.c @@ -136,6 +136,10 @@ int task_wdt_init(const struct device *hw_wdt) hw_wdt_dev = hw_wdt; hw_wdt_channel = wdt_install_timeout(hw_wdt_dev, &wdt_config); + if (hw_wdt_channel < 0) { + LOG_ERR("hw_wdt install timeout failed: %d", hw_wdt_channel); + return hw_wdt_channel; + } #else return -ENOTSUP; #endif