Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/auto_init: control the wdt thread #21024

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 */
/** @} */
Loading