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
|
|
|
|
|
2019-06-28 10:06:06 +00:00
|
|
|
#include "platform/mbed_error.h"
|
|
|
|
#include "platform/mbed_assert.h"
|
2019-06-27 09:55:24 +00:00
|
|
|
#include "platform/mbed_critical.h"
|
2019-06-28 10:06:06 +00:00
|
|
|
#include "hal/watchdog_api.h"
|
2019-06-27 10:03:20 +00:00
|
|
|
#include "platform/NonCopyable.h"
|
2019-06-27 09:55:24 +00:00
|
|
|
#include <cstdio>
|
2019-03-13 11:30:11 +00:00
|
|
|
|
2019-01-25 11:41:23 +00:00
|
|
|
namespace mbed {
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2017-11-28 14:00:56 +00:00
|
|
|
/** \addtogroup drivers */
|
2019-06-27 09:55:24 +00:00
|
|
|
/** Hardware system timer that will reset the system in the case of system failures or
|
2019-06-27 13:10:35 +00:00
|
|
|
* malfunctions. There is only one instance in the system.
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
*
|
2019-06-28 08:52:23 +00:00
|
|
|
* Watchdog &watchdog = Watchdog::get_instance();
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
* watchdog.start();
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
|
|
|
* while (true) {
|
2019-06-28 11:54:21 +00:00
|
|
|
// kick watchdog regularly within provided timeout
|
|
|
|
watchdog.kick();
|
|
|
|
// Application code
|
2017-11-28 14:00:56 +00:00
|
|
|
* }
|
|
|
|
* @endcode
|
2019-06-28 08:52:23 +00:00
|
|
|
*
|
|
|
|
* @note Synchronization level: Interrupt safe
|
2017-12-04 11:38:24 +00:00
|
|
|
* @ingroup drivers
|
2017-11-28 14:00:56 +00:00
|
|
|
*/
|
2019-06-27 09:55:24 +00:00
|
|
|
class Watchdog : private NonCopyable<Watchdog> {
|
2017-11-28 14:00:56 +00:00
|
|
|
public:
|
2019-06-28 09:50:49 +00:00
|
|
|
static const uint32_t watchdog_timeout = MBED_CONF_TARGET_WATCHDOG_TIMEOUT;
|
2019-03-13 11:30:11 +00:00
|
|
|
|
2019-06-27 13:10:35 +00:00
|
|
|
/** As Watchdog might not stop ever, there is just one instance - we use single instance.
|
|
|
|
* This ensures we keep Watchdog alive. To operate watchdog, use start/stop methods.
|
2019-06-27 20:06:24 +00:00
|
|
|
*/
|
2019-06-27 13:10:35 +00:00
|
|
|
static Watchdog &get_instance()
|
|
|
|
{
|
|
|
|
// Use this implementation of singleton (Meyer's) rather than the one that allocates
|
|
|
|
// the instance on the heap because it ensures destruction at program end (preventing warnings
|
|
|
|
// from memory checking tools, such as valgrind).
|
|
|
|
static Watchdog instance;
|
|
|
|
return instance;
|
|
|
|
}
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
/** Start the watchdog timer
|
|
|
|
*
|
2019-06-28 10:43:07 +00:00
|
|
|
* @param timeout Watchdog timeout
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
*
|
2019-06-27 09:55:24 +00:00
|
|
|
* @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
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
*/
|
2019-06-28 10:43:07 +00:00
|
|
|
bool start(uint32_t timeout = watchdog_timeout);
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
/** Stops the watchdog timer
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-27 09:55:24 +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
|
|
|
*
|
2019-06-27 09:55:24 +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
|
|
|
*/
|
2019-06-27 09:55:24 +00:00
|
|
|
bool stop();
|
2017-11-28 14:00:56 +00:00
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
/** Get the watchdog timer refresh value
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-27 09:55:24 +00:00
|
|
|
* This function returns the refresh timeout of the watchdog timer.
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-27 09:55:24 +00:00
|
|
|
* @return Reload value for the watchdog timer in milliseconds.
|
2017-11-28 14:00:56 +00:00
|
|
|
*/
|
2019-06-27 09:55:24 +00:00
|
|
|
uint32_t get_timeout() const;
|
2017-11-28 14:00:56 +00:00
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
/** Get the maximum refresh value for the current platform in milliseconds
|
2019-01-25 11:41:23 +00:00
|
|
|
*
|
2019-06-27 09:55:24 +00:00
|
|
|
* @return Maximum refresh value supported by the watchdog for the current
|
|
|
|
* platform in milliseconds
|
2017-11-28 14:00:56 +00:00
|
|
|
*/
|
2019-06-27 09:55:24 +00:00
|
|
|
uint32_t get_max_timeout() const;
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
/** Check if watchdog is already running
|
|
|
|
*
|
2019-06-28 10:43:07 +00:00
|
|
|
* @return true if watchdog is running, false otherwise
|
2019-06-27 09:55:24 +00:00
|
|
|
*/
|
|
|
|
bool is_running() const;
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2019-06-28 08:52:23 +00:00
|
|
|
/** Kick watchdog
|
|
|
|
*
|
2019-06-28 10:43:07 +00:00
|
|
|
* This method is useful to control kicking by application in ticker callback periodically
|
2019-06-28 08:52:23 +00:00
|
|
|
*/
|
2019-06-27 16:11:30 +00:00
|
|
|
void kick();
|
2019-06-27 17:11:38 +00:00
|
|
|
|
2019-01-03 12:33:26 +00:00
|
|
|
private:
|
2019-06-27 13:10:35 +00:00
|
|
|
Watchdog();
|
|
|
|
~Watchdog();
|
|
|
|
|
2019-06-27 14:46:06 +00:00
|
|
|
bool _running;
|
2017-11-28 14:00:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif // DEVICE_WATCHDOG
|
|
|
|
#endif // MBED_WATCHDOG_H
|