mbed-os/drivers/Watchdog.h

118 lines
3.2 KiB
C
Raw Normal View History

2019-06-26 08:33:48 +00:00
/*
* Copyright (c) 2018 Arm Limited and affiliates.
2018-11-19 16:55:27 +00:00
* SPDX-License-Identifier: Apache-2.0
2017-11-28 14:00:56 +00:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_WATCHDOG_H
#define MBED_WATCHDOG_H
#ifdef DEVICE_WATCHDOG
#include "mbed_error.h"
2019-03-12 18:42:03 +00:00
#include "mbed_assert.h"
#include "platform/mbed_critical.h"
#include "watchdog_api.h"
#include <cstdio>
2019-03-13 11:30:11 +00:00
namespace mbed {
2017-11-28 14:00:56 +00:00
/** \addtogroup drivers */
/** Hardware system timer that will reset the system in the case of system failures or
* malfunctions.
2017-11-28 14:00:56 +00:00
*
* Example:
* @code
*
* Watchdog watchdog();
* watchdog.start();
2017-11-28 14:00:56 +00:00
*
* while (true) {
* // Application code
* }
* @endcode
* @ingroup drivers
2017-11-28 14:00:56 +00:00
*/
class Watchdog : private NonCopyable<Watchdog> {
2017-11-28 14:00:56 +00:00
public:
2019-03-13 11:30:11 +00:00
/** Constructor configured with timeout
2019-03-13 11:30:11 +00:00
*
*/
Watchdog();
~Watchdog();
public:
/** Start the watchdog timer
*
*
* @return status true if the watchdog timer was started
* successfully. assert if one of the input parameters is out of range for the current platform.
* false if watchdog timer was not started
*/
bool start();
/** Stops the watchdog timer
2017-11-28 14:00:56 +00:00
*
* Calling this function will attempt to disable any currently running
* watchdog timers if supported by the current platform.
2017-11-28 14:00:56 +00:00
*
* @return Returns true if the watchdog timer was successfully
* stopped, Returns false if the watchdog cannot be disabled
* on the current platform or if the timer was never started.
2017-11-28 14:00:56 +00:00
*/
bool stop();
2017-11-28 14:00:56 +00:00
/** Get the watchdog timer refresh value
2017-11-28 14:00:56 +00:00
*
* This function returns the refresh timeout of the watchdog timer.
2017-11-28 14:00:56 +00:00
*
* @return Reload value for the watchdog timer in milliseconds.
2017-11-28 14:00:56 +00:00
*/
uint32_t get_timeout() const;
2017-11-28 14:00:56 +00:00
/** Get the maximum refresh value for the current platform in milliseconds
*
* @return Maximum refresh value supported by the watchdog for the current
* platform in milliseconds
2017-11-28 14:00:56 +00:00
*/
uint32_t get_max_timeout() const;
/** Check if watchdog is already running
*
* @return Maximum refresh value supported by the watchdog for the current
* platform in milliseconds
*/
bool is_running() const;
private:
static void kick();
static uint32_t _elapsed_ms;
static bool _running;
#if DEVICE_LPTICKER
/** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick.
*/
static SingletonPtr<LowPowerTicker> _ticker;
#else
/** Create singleton instance of Ticker for watchdog periodic call back of kick.
*/
static SingletonPtr<Ticker> _ticker;
#endif
2017-11-28 14:00:56 +00:00
};
} // namespace mbed
#endif // DEVICE_WATCHDOG
#endif // MBED_WATCHDOG_H