Mbed OS Reference
Loading...
Searching...
No Matches
watchdog_api.h
1/** \addtogroup hal */
2/** @{*/
3
4/*
5 * Copyright (c) 2018-2019 Arm Limited and affiliates.
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#ifndef MBED_WATCHDOG_API_H
22#define MBED_WATCHDOG_API_H
23
24#if DEVICE_WATCHDOG
25
26#include <stdbool.h>
27#include <stdint.h>
28
29/**
30 * \defgroup hal_watchdog Watchdog HAL API
31 * Low-level interface to the Independent Watchdog Timer of a target.
32 *
33 * This module provides platform independent access to the system watchdog timer
34 * which is an embedded peripheral that will reset the system in the case of
35 * system failures or malfunctions.
36 *
37 * The watchdog timer initializes a system timer with a time period specified in
38 * the configuration. This timer counts down and triggers a system reset when it
39 * wraps. To prevent the system reset the timer must be continually
40 * kicked/refreshed by calling ::hal_watchdog_kick which will reset the countdown
41 * to the user specified reset value.
42 *
43 * # Defined behavior
44 * * Sleep and debug modes don't stop the watchdog timer from counting down or timing out.
45 * * The function ::hal_watchdog_init is safe to call repeatedly. The
46 * function's implementation must not do anything if ::hal_watchdog_init has
47 * already initialized the hardware watchdog timer.
48 * * Maximum supported timeout is `UINT32_MAX` milliseconds; minimum timeout
49 * is 1 millisecond.
50 * * The uncalibrated watchdog should trigger at or after the timeout value
51 * multiplied by the frequency accuracy ratio of its oscillator (typical_frequency / max_frequency).
52 * * The calibrated watchdog should trigger at or after the timeout value.
53 * * The watchdog should trigger before twice the timeout value.
54 * * On some devices (Kinetis MCUs), if the watchdog times out during deep sleep mode, the timer will reset
55 * and count up to the timeout value again before resetting the system. This means that if your MCU may be
56 * in deep sleep mode when the timer times out, allow for up to double the configured watchdog time before timeout.
57 * See here for details: https://github.com/ARMmbed/mbed-os/issues/11774
58 *
59 * # Undefined behavior
60 * * Calling any function other than ::hal_watchdog_init or
61 * ::hal_watchdog_get_platform_features before you have initialized the watchdog.
62 *
63 * # Notes
64 * * A software reset may not stop the watchdog timer; the behavior is platform specific.
65 *
66 * @{
67 */
68
69/**
70 * \defgroup hal_watchdog_tests Watchdog HAL tests
71 * Greentea tests for the Watchdog HAL.
72 *
73 * To run the Watchdog HAL tests use the command:
74 *
75 * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-watchdog*
76 *
77 */
78
79/** Watchdog configuration.
80 */
81typedef struct {
82 /**
83 * Refresh value for the watchdog in milliseconds. The maximum value of this
84 * setting is platform dependent, to find the maximum value for the current
85 * platform call hal_watchdog_get_features() and check the timeout value
86 * member. The minimum valid value for this setting is 1. Attempting to
87 * initialize the watchdog with a timeout of 0 ms returns
88 * WATCHDOG_STATUS_INVALID_ARGUMENT.
89 */
90 uint32_t timeout_ms;
92
93/** Watchdog features.
94 */
95typedef struct {
96 /**
97 * Maximum timeout value for the watchdog in milliseconds.
98 */
99 uint32_t max_timeout;
100 /**
101 * You can update the watchdog configuration after the watchdog has started.
102 */
104 /**
105 * You can stop the watchdog after it starts without a reset.
106 */
108 /**
109 * Typical frequency of not calibrated watchdog clock in Hz.
110 */
112 /**
113 * Maximum frequency of not calibrated watchdog clock in Hz.
114 */
117
118
119/** Status of a watchdog operation.
120*/
121typedef enum {
122 WATCHDOG_STATUS_OK, /**< Operation successful. **/
123 WATCHDOG_STATUS_NOT_SUPPORTED, /**< Operation not supported. **/
124 WATCHDOG_STATUS_INVALID_ARGUMENT /**< Invalid argument. **/
126
127#ifdef __cplusplus
128extern "C" {
129#endif
130
131/** Initialize and start a watchdog timer with the given configuration.
132 *
133 * If the watchdog timer is configured and starts successfully, this
134 * function returns ::WATCHDOG_STATUS_OK.
135 *
136 * If the timeout specified is outside the range supported by the platform,
137 * it returns ::WATCHDOG_STATUS_INVALID_ARGUMENT.
138 *
139 * @param[in] config Configuration settings for the watchdog timer
140 *
141 * @return ::WATCHDOG_STATUS_OK if the watchdog is configured correctly and
142 * has started. Otherwise a status indicating the fault.
143 */
145
146/** Refreshes the watchdog timer.
147 *
148 * Call this function periodically before the watchdog times out.
149 * Otherwise, the system resets.
150 *
151 * If a watchdog is not running, this function does nothing.
152 */
154
155/** Stops the watchdog timer.
156 *
157 * Calling this function disables any running watchdog
158 * timers if the current platform supports them.
159 *
160 * @return Returns ::WATCHDOG_STATUS_OK if the watchdog timer was succesfully
161 * stopped, or if the timer was never started. Returns
162 * ::WATCHDOG_STATUS_NOT_SUPPORTED if the watchdog cannot be disabled on
163 * the current platform.
164 */
166
167/** Get the watchdog timer refresh value.
168 *
169 * This function returns the configured refresh timeout of the watchdog timer.
170 *
171 * @return Reload value for the watchdog timer in milliseconds.
172 */
174
175/** Get information on the current platforms supported watchdog functionality.
176 *
177 * @return watchdog_feature_t indicating supported watchdog features on the
178 * current platform
179 */
181
182/**@}*/
183
184#ifdef __cplusplus
185}
186#endif
187
188#endif // DEVICE_WATCHDOG
189
190#endif // MBED_WATCHDOG_API_H
191
192/** @}*/
watchdog_status_t hal_watchdog_stop(void)
Stops the watchdog timer.
watchdog_features_t hal_watchdog_get_platform_features(void)
Get information on the current platforms supported watchdog functionality.
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
Initialize and start a watchdog timer with the given configuration.
watchdog_status_t
Status of a watchdog operation.
void hal_watchdog_kick(void)
Refreshes the watchdog timer.
uint32_t hal_watchdog_get_reload_value(void)
Get the watchdog timer refresh value.
@ WATCHDOG_STATUS_INVALID_ARGUMENT
Invalid argument.
@ WATCHDOG_STATUS_NOT_SUPPORTED
Operation not supported.
@ WATCHDOG_STATUS_OK
Operation successful.
Watchdog configuration.
uint32_t timeout_ms
Refresh value for the watchdog in milliseconds.
Watchdog features.
uint32_t clock_typical_frequency
Typical frequency of not calibrated watchdog clock in Hz.
bool disable_watchdog
You can stop the watchdog after it starts without a reset.
bool update_config
You can update the watchdog configuration after the watchdog has started.
uint32_t clock_max_frequency
Maximum frequency of not calibrated watchdog clock in Hz.
uint32_t max_timeout
Maximum timeout value for the watchdog in milliseconds.