Mistake on this page?
Report an issue in GitHub or email us
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.
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 watchdog should trigger at or after the timeout value.
51  * * The watchdog should trigger before twice the timeout value.
52  *
53  * # Undefined behavior
54  * * Calling any function other than ::hal_watchdog_init or
55  * ::hal_watchdog_get_platform_features before you have initialized the watchdog.
56  *
57  * # Notes
58  * * A software reset may not stop the watchdog timer; the behavior is platform specific.
59  *
60  * @{
61  */
62 
63 /**
64  * \defgroup hal_watchdog_tests Watchdog HAL tests
65  * Greentea tests for the Watchdog HAL.
66  *
67  * To run the Watchdog HAL tests use the command:
68  *
69  * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-watchdog*
70  *
71  */
72 
73 /** Watchdog configuration.
74  */
75 typedef struct {
76  /**
77  * Refresh value for the watchdog in milliseconds. The maximum value of this
78  * setting is platform dependent, to find the maximum value for the current
79  * platform call hal_watchdog_get_features() and check the timeout value
80  * member. The minimum valid value for this setting is 1. Attempting to
81  * initialize the watchdog with a timeout of 0 ms returns
82  * WATCHDOG_STATUS_INVALID_ARGUMENT.
83  */
84  uint32_t timeout_ms;
86 
87 /** Watchdog features.
88  */
89 typedef struct {
90  /**
91  * Maximum timeout value for the watchdog in milliseconds.
92  */
93  uint32_t max_timeout;
94  /**
95  * You can update the watchdog configuration after the watchdog has started.
96  */
98  /**
99  * You can stop the watchdog after it starts without a reset.
100  */
103 
104 
105 /** Status of a watchdog operation.
106 */
107 typedef enum {
108  WATCHDOG_STATUS_OK, /**< Operation successful. **/
109  WATCHDOG_STATUS_NOT_SUPPORTED, /**< Operation not supported. **/
110  WATCHDOG_STATUS_INVALID_ARGUMENT /**< Invalid argument. **/
112 
113 #ifdef __cplusplus
114 extern "C" {
115 #endif
116 
117 /** Initialize and start a watchdog timer with the given configuration.
118  *
119  * If the watchdog timer is configured and starts successfully, this
120  * function returns ::WATCHDOG_STATUS_OK.
121  *
122  * If the timeout specified is outside the range supported by the platform,
123  * it returns ::WATCHDOG_STATUS_INVALID_ARGUMENT.
124  *
125  * @param[in] config Configuration settings for the watchdog timer
126  *
127  * @return ::WATCHDOG_STATUS_OK if the watchdog is configured correctly and
128  * has started. Otherwise a status indicating the fault.
129  */
131 
132 /** Refreshes the watchdog timer.
133  *
134  * Call this function periodically before the watchdog times out.
135  * Otherwise, the system resets.
136  *
137  * If a watchdog is not running, this function does nothing.
138  */
139 void hal_watchdog_kick(void);
140 
141 /** Stops the watchdog timer.
142  *
143  * Calling this function disables any running watchdog
144  * timers if the current platform supports them.
145  *
146  * @return Returns ::WATCHDOG_STATUS_OK if the watchdog timer was succesfully
147  * stopped, or if the timer was never started. Returns
148  * ::WATCHDOG_STATUS_NOT_SUPPORTED if the watchdog cannot be disabled on
149  * the current platform.
150  */
152 
153 /** Get the watchdog timer refresh value.
154  *
155  * This function returns the configured refresh timeout of the watchdog timer.
156  *
157  * @return Reload value for the watchdog timer in milliseconds.
158  */
159 uint32_t hal_watchdog_get_reload_value(void);
160 
161 /** Get information on the current platforms supported watchdog functionality.
162  *
163  * @return watchdog_feature_t indicating supported watchdog features on the
164  * current platform
165  */
167 
168 /**@}*/
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif // DEVICE_WATCHDOG
175 
176 #endif // MBED_WATCHDOG_API_H
177 
178 /** @}*/
uint32_t max_timeout
Maximum timeout value for the watchdog in milliseconds.
Definition: watchdog_api.h:93
watchdog_status_t
Status of a watchdog operation.
Definition: watchdog_api.h:107
Operation successful.
Definition: watchdog_api.h:108
bool disable_watchdog
You can stop the watchdog after it starts without a reset.
Definition: watchdog_api.h:101
uint32_t hal_watchdog_get_reload_value(void)
Get the watchdog timer refresh value.
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
Initialize and start a watchdog timer with the given configuration.
Watchdog features.
Definition: watchdog_api.h:89
watchdog_features_t hal_watchdog_get_platform_features(void)
Get information on the current platforms supported watchdog functionality.
watchdog_status_t hal_watchdog_stop(void)
Stops the watchdog timer.
uint32_t timeout_ms
Refresh value for the watchdog in milliseconds.
Definition: watchdog_api.h:84
void hal_watchdog_kick(void)
Refreshes the watchdog timer.
bool update_config
You can update the watchdog configuration after the watchdog has started.
Definition: watchdog_api.h:97
Operation not supported.
Definition: watchdog_api.h:109
Watchdog configuration.
Definition: watchdog_api.h:75
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.