2019-06-26 08:33:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2019 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.
|
|
|
|
*/
|
|
|
|
#ifdef DEVICE_WATCHDOG
|
|
|
|
|
2019-06-27 16:11:30 +00:00
|
|
|
#include "drivers/Watchdog.h"
|
|
|
|
#include "drivers/WatchdogManager.h"
|
2019-06-27 09:55:24 +00:00
|
|
|
|
|
|
|
#define MS_TO_US(x) ((x) * 1000) //macro to convert millisecond to microsecond
|
2017-11-28 14:00:56 +00:00
|
|
|
|
2019-01-25 11:41:23 +00:00
|
|
|
namespace mbed {
|
|
|
|
|
2019-06-27 16:11:30 +00:00
|
|
|
Watchdog::Watchdog() : _running(false), _callback(NULL)
|
2019-06-27 14:46:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-27 16:11:30 +00:00
|
|
|
Watchdog::~Watchdog()
|
2019-06-27 15:26:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-27 16:11:30 +00:00
|
|
|
bool Watchdog::start(Callback<void()> func, uint32_t timeout)
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
2019-06-27 09:55:24 +00:00
|
|
|
MBED_ASSERT(MBED_CONF_TARGET_WATCHDOG_TIMEOUT < get_max_timeout());
|
2019-06-28 07:37:35 +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
|
|
|
core_util_critical_section_enter();
|
2019-06-28 07:37:35 +00:00
|
|
|
// we update callback always, to be able to register new hook if needed
|
|
|
|
_callback = func;
|
2019-06-27 09:55:24 +00:00
|
|
|
if (_running) {
|
|
|
|
core_util_critical_section_exit();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
watchdog_config_t config;
|
|
|
|
config.timeout_ms = MBED_CONF_TARGET_WATCHDOG_TIMEOUT;
|
2019-06-28 07:37:35 +00:00
|
|
|
watchdog_status_t sts = hal_watchdog_init(&config);
|
2019-06-27 09:55:24 +00:00
|
|
|
if (sts == WATCHDOG_STATUS_OK) {
|
|
|
|
_running = 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
|
|
|
core_util_critical_section_exit();
|
2019-06-28 07:37:35 +00:00
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
if (_running) {
|
2019-06-27 16:11:30 +00:00
|
|
|
us_timestamp_t ticker_timeout = (MS_TO_US(((timeout <= 0) ? 1 : timeout)));
|
2019-06-27 17:11:38 +00:00
|
|
|
_ticker->attach(callback(this, &Watchdog::kick), ticker_timeout);
|
2019-06-27 09:55:24 +00:00
|
|
|
}
|
|
|
|
return _running;
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
bool Watchdog::stop()
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
2019-06-27 09:55:24 +00:00
|
|
|
watchdog_status_t sts;
|
|
|
|
bool msts = 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
|
|
|
core_util_critical_section_enter();
|
2019-06-27 09:55:24 +00:00
|
|
|
if (_running) {
|
|
|
|
sts = hal_watchdog_stop();
|
|
|
|
if (sts != WATCHDOG_STATUS_OK) {
|
|
|
|
msts = false;
|
|
|
|
} else {
|
2019-06-27 17:11:38 +00:00
|
|
|
_ticker->detach();
|
2019-06-27 09:55:24 +00:00
|
|
|
_running = false;
|
2019-06-27 16:11:30 +00:00
|
|
|
_callback = NULL;
|
2019-06-27 09:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
msts = false;
|
|
|
|
}
|
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
|
|
|
core_util_critical_section_exit();
|
2019-06-27 09:55:24 +00:00
|
|
|
return msts;
|
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-01-03 12:33:26 +00:00
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
void Watchdog::kick()
|
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
|
|
|
{
|
|
|
|
core_util_critical_section_enter();
|
2019-06-27 09:55:24 +00:00
|
|
|
hal_watchdog_kick();
|
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
|
|
|
core_util_critical_section_exit();
|
2019-06-27 17:11:38 +00:00
|
|
|
|
2019-06-27 16:11:30 +00:00
|
|
|
if (_callback) {
|
|
|
|
_callback();
|
|
|
|
}
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 09:55:24 +00:00
|
|
|
|
|
|
|
bool Watchdog::is_running() const
|
2019-01-03 12:33:26 +00:00
|
|
|
{
|
2019-06-27 09:55:24 +00:00
|
|
|
return _running;
|
2019-01-03 12:33:26 +00:00
|
|
|
}
|
2017-11-28 14:00:56 +00:00
|
|
|
|
2019-06-27 13:10:35 +00:00
|
|
|
uint32_t Watchdog::get_timeout() const
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
2019-06-27 09:55:24 +00:00
|
|
|
return hal_watchdog_get_reload_value();
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 13:10:35 +00:00
|
|
|
uint32_t Watchdog::get_max_timeout() const
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
2019-06-27 09:55:24 +00:00
|
|
|
const watchdog_features_t features = hal_watchdog_get_platform_features();
|
|
|
|
return features.max_timeout;
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mbed
|
|
|
|
|
2019-06-27 14:46:06 +00:00
|
|
|
|
2017-11-28 14:00:56 +00:00
|
|
|
#endif // DEVICE_WATCHDOG
|