diff --git a/sys/auto_init/wdt_thread/wdt.c b/sys/auto_init/wdt_thread/wdt.c index 71f6a745b967..cd0536fee467 100644 --- a/sys/auto_init/wdt_thread/wdt.c +++ b/sys/auto_init/wdt_thread/wdt.c @@ -24,6 +24,7 @@ #include "architecture.h" #include "periph/wdt.h" +#include "wdt_thread.h" #include "ztimer.h" #ifndef WDT_THREAD_STACKSIZE @@ -36,6 +37,14 @@ static char WORD_ALIGNED wdt_stack[WDT_THREAD_STACKSIZE]; +static bool _wdt_enabled = true; + +void wdt_thread_stop(void) +{ + _wdt_enabled = false; + wdt_stop(); +} + static void *_wdt_thread(void *ctx) { (void)ctx; @@ -43,6 +52,9 @@ static void *_wdt_thread(void *ctx) / 2; while (1) { ztimer_sleep(ZTIMER_MSEC, sleep_ms); + if (!_wdt_enabled) { + break; + } wdt_kick(); } diff --git a/sys/include/wdt_thread.h b/sys/include/wdt_thread.h new file mode 100644 index 000000000000..399ab7056bd8 --- /dev/null +++ b/sys/include/wdt_thread.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_wdt_thread wdt thread control + * @ingroup sys + * @brief Utility functions for controlling the wdt thread + * + * @{ + * @file + * @brief WDT thread control functions + * + * @author Mariem Charrada + */ + +#ifndef WDT_THREAD_H +#define WDT_THREAD_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Stop the wdt thread + * + * This function is useful for stopping at any time the wdt thread + */ +void wdt_thread_stop(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* WDT_THREAD_H */ +/** @} */