Mistake on this page?
Report an issue in GitHub or email us
Watchdog.h
1 /*
2  * Copyright (c) 2018 Arm Limited and affiliates.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef MBED_WATCHDOG_H
19 #define MBED_WATCHDOG_H
20 
21 #ifdef DEVICE_WATCHDOG
22 
23 #include "platform/mbed_error.h"
24 #include "platform/mbed_assert.h"
25 #include "platform/mbed_critical.h"
26 #include "hal/watchdog_api.h"
27 #include "platform/NonCopyable.h"
28 #include <cstdio>
29 
30 namespace mbed {
31 
32 /** \addtogroup drivers */
33 /** Hardware system timer that will reset the system in the case of system failures or
34  * malfunctions. There is only one instance in the system.
35  *
36  * Example:
37  * @code
38  *
39  * Watchdog &watchdog = Watchdog::get_instance();
40  * watchdog.start();
41  *
42  * while (true) {
43  // kick watchdog regularly within provided timeout
44  watchdog.kick();
45  // Application code
46  * }
47  * @endcode
48  *
49  * @note Synchronization level: Interrupt safe
50  * @ingroup drivers
51  */
52 class Watchdog : private NonCopyable<Watchdog> {
53 public:
54 
55  /** As Watchdog might not stop ever, there is just one instance - we use single instance.
56  * This ensures we keep Watchdog alive. To operate watchdog, use start/stop methods.
57  */
59  {
60  // Use this implementation of singleton (Meyer's) rather than the one that allocates
61  // the instance on the heap because it ensures destruction at program end (preventing warnings
62  // from memory checking tools, such as valgrind).
63  static Watchdog instance;
64  return instance;
65  }
66 
67  /** Start the watchdog timer with the maximum timeout available on a target
68  *
69  * Timeout is defined as get_max_timeout()
70  *
71  * @return status true if the watchdog timer was started
72  * successfully. assert if one of the input parameters is out of range for the current platform.
73  * false if watchdog timer was not started
74  */
75  bool start();
76 
77  /** Start the watchdog timer
78  *
79  * @param timeout Watchdog timeout
80  *
81  * @return status true if the watchdog timer was started
82  * successfully. assert if one of the input parameters is out of range for the current platform.
83  * false if watchdog timer was not started
84  */
85  bool start(uint32_t timeout);
86 
87  /** Stops the watchdog timer
88  *
89  * Calling this function will attempt to disable any currently running
90  * watchdog timers if supported by the current platform.
91  *
92  * @return Returns true if the watchdog timer was successfully
93  * stopped, Returns false if the watchdog cannot be disabled
94  * on the current platform or if the timer was never started.
95  */
96  bool stop();
97 
98  /** Get the watchdog timer refresh value
99  *
100  * This function returns the refresh timeout of the watchdog timer.
101  *
102  * @return Reload value for the watchdog timer in milliseconds.
103  */
104  uint32_t get_timeout() const;
105 
106  /** Get the maximum refresh value for the current platform in milliseconds
107  *
108  * @return Maximum refresh value supported by the watchdog for the current
109  * platform in milliseconds
110  */
111  uint32_t get_max_timeout() const;
112 
113  /** Check if watchdog is already running
114  *
115  * @return true if watchdog is running, false otherwise
116  */
117  bool is_running() const;
118 
119  /** Kick watchdog
120  *
121  * This method is useful to control kicking by application in ticker callback periodically
122  */
123  void kick();
124 
125 private:
126  Watchdog();
127  ~Watchdog();
128 
129  bool _running;
130 };
131 
132 } // namespace mbed
133 
134 #endif // DEVICE_WATCHDOG
135 #endif // MBED_WATCHDOG_H
bool start()
Start the watchdog timer with the maximum timeout available on a target.
static Watchdog & get_instance()
As Watchdog might not stop ever, there is just one instance - we use single instance.
Definition: Watchdog.h:58
bool is_running() const
Check if watchdog is already running.
Hardware system timer that will reset the system in the case of system failures or malfunctions...
Definition: Watchdog.h:52
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:168
uint32_t get_timeout() const
Get the watchdog timer refresh value.
void kick()
Kick watchdog.
uint32_t get_max_timeout() const
Get the maximum refresh value for the current platform in milliseconds.
bool stop()
Stops the watchdog timer.
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.