Skip to content

Commit

Permalink
sys/auto_init: control the wdt thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mariemC committed Nov 21, 2024
1 parent 8179312 commit df8e4d1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sys/auto_init/wdt_thread/wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "architecture.h"
#include "periph/wdt.h"
#include "wdt_thread.h"
#include "ztimer.h"

#ifndef WDT_THREAD_STACKSIZE
Expand All @@ -36,13 +37,24 @@

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;
unsigned sleep_ms = (CONFIG_PERIPH_WDT_WIN_MIN_MS + CONFIG_PERIPH_WDT_WIN_MAX_MS)
/ 2;
while (1) {
ztimer_sleep(ZTIMER_MSEC, sleep_ms);
if (!_wdt_enabled) {
break;
}
wdt_kick();
}

Expand Down
41 changes: 41 additions & 0 deletions sys/include/wdt_thread.h
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

#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);


Check warning on line 35 in sys/include/wdt_thread.h

View workflow job for this annotation

GitHub Actions / static-tests

too many consecutive empty lines
#ifdef __cplusplus
}
#endif

#endif /* WDT_THREAD_H */
/** @} */

0 comments on commit df8e4d1

Please sign in to comment.