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 <cstdio>
|
2019-01-03 12:33:26 +00:00
|
|
|
#include "mbed_error.h"
|
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
|
|
|
#include "platform/mbed_critical.h"
|
|
|
|
#include "platform/mbed_power_mgmt.h"
|
2019-03-12 18:42:03 +00:00
|
|
|
#include "mbed_assert.h"
|
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-26 15:18:16 +00:00
|
|
|
/** Services that need to monitor nonblocking periodic behavior or
|
|
|
|
* malfunctions, such as Wi-Fi and TLS, use a software watchdog.
|
|
|
|
* Normally, one instance of a software watchdog gets created during hardware watchdog startup, so you can access the software watchdog.
|
|
|
|
* The hardware watchdog periodically calls the "process" method of the services to check nonblocking periodic behavior.
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
*
|
2019-01-25 11:41:23 +00:00
|
|
|
* Watchdog watchdog(300,"Software Watchdog");
|
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) {
|
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.kick();
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
|
|
|
* // Application code
|
|
|
|
* }
|
|
|
|
* @endcode
|
2017-12-04 11:38:24 +00:00
|
|
|
* @ingroup drivers
|
2017-11-28 14:00:56 +00:00
|
|
|
*/
|
2019-01-25 11:41:23 +00:00
|
|
|
class Watchdog {
|
2017-11-28 14:00:56 +00:00
|
|
|
public:
|
2019-03-13 11:30:11 +00:00
|
|
|
|
2019-06-26 15:18:16 +00:00
|
|
|
/** Constructor configured with timeout and name for this software watchdog instance.
|
2019-03-13 11:30:11 +00:00
|
|
|
*
|
|
|
|
*/
|
2019-01-25 11:41:23 +00:00
|
|
|
Watchdog(uint32_t timeout = 1, const char *const str = NULL);
|
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();
|
|
|
|
public:
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2019-06-26 15:18:16 +00:00
|
|
|
/** Start an independent watchdog timer with specified parameters.
|
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-26 15:18:16 +00:00
|
|
|
* Assert for multiple calls of start.
|
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
|
|
|
*/
|
|
|
|
void start();
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2019-06-26 15:18:16 +00:00
|
|
|
/** This stops the watchdog timer.
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-26 15:18:16 +00:00
|
|
|
* Calling this function disables any running
|
|
|
|
* watchdog timers if the platform supports them.
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-26 15:18:16 +00:00
|
|
|
* Assert without calling start.
|
2017-11-28 14:00:56 +00:00
|
|
|
*/
|
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
|
|
|
void stop();
|
2017-11-28 14:00:56 +00:00
|
|
|
|
2019-06-26 15:18:16 +00:00
|
|
|
/** This function refreshes the watchdog timer.
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-26 15:18:16 +00:00
|
|
|
* Call this function periodically before the watchdog times out.
|
|
|
|
* Otherwise, the system resets.
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-26 15:18:16 +00:00
|
|
|
* If the watchdog timer is not running, this function does nothing.
|
2017-11-28 14:00:56 +00:00
|
|
|
*/
|
|
|
|
void kick();
|
|
|
|
|
2019-06-26 15:18:16 +00:00
|
|
|
/** mbed_watchdog_manager (runs by periodic call from ticker) used this API interface
|
2019-01-25 11:41:23 +00:00
|
|
|
* to go through all the registered user/threads of watchdog.
|
|
|
|
*
|
|
|
|
* @param elapsed_ms completed ticker callback elapsed milliseconds
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-26 15:18:16 +00:00
|
|
|
* Call this function from mbed_watchdog_manager_kick to monitor all the
|
|
|
|
* user/threads alive states.
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
2019-06-26 15:18:16 +00:00
|
|
|
* Otherwise, the system resets.
|
2017-11-28 14:00:56 +00:00
|
|
|
*/
|
2019-03-22 16:59:40 +00:00
|
|
|
static void process(uint32_t elapsed_ms);
|
2019-01-03 12:33:26 +00:00
|
|
|
protected :
|
|
|
|
|
2019-06-26 15:18:16 +00:00
|
|
|
/** Use add_to_list to store the registered user in the list.
|
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
|
|
|
* This API is only used to call from start.
|
|
|
|
*/
|
|
|
|
void add_to_list();
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2019-06-26 15:18:16 +00:00
|
|
|
/** Use remove_from_list to remove the entry from the list.
|
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
|
|
|
* This API is only used to call from stop.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void remove_from_list();
|
2019-01-03 12:33:26 +00:00
|
|
|
private:
|
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
|
|
|
uint32_t _max_timeout; //_max_timeout initialized via constructor while creating instance of this class
|
2019-03-13 11:30:11 +00:00
|
|
|
const char *_name; //To store the details of user
|
|
|
|
uint32_t _current_count; //this parameter is used to reset everytime threads/user calls kick
|
|
|
|
bool _is_initialized; //To control start and stop functionality
|
|
|
|
static Watchdog *_first; //List to store the user/threads who called start
|
2019-01-25 11:41:23 +00:00
|
|
|
Watchdog *_next;
|
2017-11-28 14:00:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif // DEVICE_WATCHDOG
|
|
|
|
#endif // MBED_WATCHDOG_H
|