task_wdt: fix silent init failures
The task_wdt_init() API can fail to install a timeout for the fallback hardware WDT (hw_wdt) without returning an error code. This patch enables task_wdt_init() to return the hw_wdt install timeout error code if the hw_wdt install timeout fails. Signed-off-by: Nick Ward <nick.ward@setec.com.au>
This commit is contained in:
parent
59b76b2e24
commit
e0f18128bf
3 changed files with 14 additions and 1 deletions
|
@ -47,6 +47,9 @@ typedef void (*task_wdt_callback_t)(int channel_id, void *user_data);
|
||||||
*
|
*
|
||||||
* @retval 0 If successful.
|
* @retval 0 If successful.
|
||||||
* @retval -ENOTSUP If assigning a hardware watchdog is not supported.
|
* @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);
|
int task_wdt_init(const struct device *hw_wdt);
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ static void task_wdt_callback(int channel_id, void *user_data)
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
#ifdef WDT_NODE
|
#ifdef WDT_NODE
|
||||||
const struct device *hw_wdt_dev = DEVICE_DT_GET(WDT_NODE);
|
const struct device *hw_wdt_dev = DEVICE_DT_GET(WDT_NODE);
|
||||||
#else
|
#else
|
||||||
|
@ -72,7 +73,12 @@ void main(void)
|
||||||
hw_wdt_dev = NULL;
|
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 */
|
/* passing NULL instead of callback to trigger system reset */
|
||||||
int task_wdt_id = task_wdt_add(1100U, NULL, NULL);
|
int task_wdt_id = task_wdt_add(1100U, NULL, NULL);
|
||||||
|
|
|
@ -136,6 +136,10 @@ int task_wdt_init(const struct device *hw_wdt)
|
||||||
|
|
||||||
hw_wdt_dev = hw_wdt;
|
hw_wdt_dev = hw_wdt;
|
||||||
hw_wdt_channel = wdt_install_timeout(hw_wdt_dev, &wdt_config);
|
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
|
#else
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue