Skip to content

Commit

Permalink
NULL watchdog callback
Browse files Browse the repository at this point in the history
Allow NULL watchdog callback if no conditions need to be checked
  • Loading branch information
sri9311 committed Oct 4, 2024
1 parent 4b4dda0 commit 22301c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 10 additions & 1 deletion lib/errors/errors_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ trigger_z_oops(void)
}
#endif

#ifdef CONFIG_ORB_LIB_WATCHDOG
static bool
watchdog_feed_callback(void)
{
/* Deliberately prevent feeding the watchdog */
return false;
}
#endif

void
fatal_errors_trigger(enum error_case_e type)
{
Expand Down Expand Up @@ -153,7 +162,7 @@ fatal_errors_trigger(enum error_case_e type)
#endif
#ifdef CONFIG_ORB_LIB_WATCHDOG
case FATAL_WATCHDOG:
(void)watchdog_init(NULL);
(void)watchdog_init(watchdog_feed_callback);
break;
#endif

Expand Down
11 changes: 6 additions & 5 deletions lib/watchdog/watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ static void
watchdog_thread()
{
while (wdt_channel_id >= 0) {
if (watchdog_callback()) {
// Allow null callback
if (watchdog_callback == NULL) {
wdt_feed(watchdog_dev, wdt_channel_id);
} else {
if (watchdog_callback() == true) {
wdt_feed(watchdog_dev, wdt_channel_id);
}
}
k_sleep(K_MSEC(WATCHDOG_RELOAD_MS));
}
Expand All @@ -41,10 +46,6 @@ watchdog_thread()
int
watchdog_init(bool (*callback)(void))
{
if (callback == NULL) {
return RET_ERROR_INVALID_PARAM;
}

watchdog_callback = callback;

int err_code;
Expand Down

0 comments on commit 22301c0

Please sign in to comment.