mirror of https://github.com/ARMmbed/mbed-os.git
watchdog: remove manager
Watchdog can handle callbacks - VirtualManager can attach to the tick. This should simplify the logic. Watchdog can tick on its own using tickers. VirtualWatchdog uses attach to get a callback when Watchdog ticks - to process own linked list of virtual watchdogs.pull/10857/head
parent
698b0eda8a
commit
f98c2fdbba
|
@ -31,7 +31,7 @@ VirtualWatchdog::VirtualWatchdog(uint32_t timeout, const char *const str): _name
|
||||||
_max_timeout = timeout;
|
_max_timeout = timeout;
|
||||||
// start watchdog
|
// start watchdog
|
||||||
Watchdog& watchdog = Watchdog::get_instance();
|
Watchdog& watchdog = Watchdog::get_instance();
|
||||||
watchdog.start(&VirtualWatchdog::process, WatchdogManager::elapsed_ms);
|
watchdog.start(&VirtualWatchdog::process, Watchdog::elapsed_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualWatchdog::~VirtualWatchdog()
|
VirtualWatchdog::~VirtualWatchdog()
|
||||||
|
@ -104,7 +104,7 @@ void VirtualWatchdog::process()
|
||||||
if (cur_ptr->_current_count > cur_ptr->_max_timeout) {
|
if (cur_ptr->_current_count > cur_ptr->_max_timeout) {
|
||||||
system_reset();
|
system_reset();
|
||||||
} else {
|
} else {
|
||||||
cur_ptr->_current_count += WatchdogManager::elapsed_ms;
|
cur_ptr->_current_count += Watchdog::elapsed_ms;
|
||||||
}
|
}
|
||||||
cur_ptr = cur_ptr->_next;
|
cur_ptr = cur_ptr->_next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "platform/mbed_critical.h"
|
#include "platform/mbed_critical.h"
|
||||||
#include "platform/mbed_power_mgmt.h"
|
#include "platform/mbed_power_mgmt.h"
|
||||||
#include "mbed_assert.h"
|
#include "mbed_assert.h"
|
||||||
#include "WatchdogManager.h"
|
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ bool Watchdog::start(Callback<void()> func, uint32_t timeout)
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
if (_running) {
|
if (_running) {
|
||||||
us_timestamp_t ticker_timeout = (MS_TO_US(((timeout <= 0) ? 1 : timeout)));
|
us_timestamp_t ticker_timeout = (MS_TO_US(((timeout <= 0) ? 1 : timeout)));
|
||||||
WatchdogManager::attach(callback(this, &Watchdog::kick), ticker_timeout);
|
_ticker->attach(callback(this, &Watchdog::kick), ticker_timeout);
|
||||||
}
|
}
|
||||||
return _running;
|
return _running;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ bool Watchdog::stop()
|
||||||
if (sts != WATCHDOG_STATUS_OK) {
|
if (sts != WATCHDOG_STATUS_OK) {
|
||||||
msts = false;
|
msts = false;
|
||||||
} else {
|
} else {
|
||||||
WatchdogManager::detach();
|
_ticker->detach();
|
||||||
_running = false;
|
_running = false;
|
||||||
_callback = NULL;
|
_callback = NULL;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@ void Watchdog::kick()
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
hal_watchdog_kick();
|
hal_watchdog_kick();
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
if (_callback) {
|
if (_callback) {
|
||||||
_callback();
|
_callback();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ namespace mbed {
|
||||||
*/
|
*/
|
||||||
class Watchdog : private NonCopyable<Watchdog> {
|
class Watchdog : private NonCopyable<Watchdog> {
|
||||||
public:
|
public:
|
||||||
|
const uint32_t watchdog_timeout = MBED_CONF_TARGET_WATCHDOG_TIMEOUT / 2;
|
||||||
|
|
||||||
/** As Watchdog might not stop ever, there is just one instance - we use single instance.
|
/** 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.
|
* This ensures we keep Watchdog alive. To operate watchdog, use start/stop methods.
|
||||||
|
@ -70,7 +71,7 @@ public:
|
||||||
* successfully. assert if one of the input parameters is out of range for the current platform.
|
* successfully. assert if one of the input parameters is out of range for the current platform.
|
||||||
* false if watchdog timer was not started
|
* false if watchdog timer was not started
|
||||||
*/
|
*/
|
||||||
bool start(Callback<void()> func = NULL, uint32_t timeout = WatchdogManager::elapsed_ms);
|
bool start(Callback<void()> func = NULL, uint32_t timeout = watchdog_timeout);
|
||||||
|
|
||||||
/** Stops the watchdog timer
|
/** Stops the watchdog timer
|
||||||
*
|
*
|
||||||
|
@ -106,12 +107,25 @@ public:
|
||||||
bool is_running() const;
|
bool is_running() const;
|
||||||
|
|
||||||
void kick();
|
void kick();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Watchdog();
|
Watchdog();
|
||||||
~Watchdog();
|
~Watchdog();
|
||||||
|
|
||||||
bool _running;
|
bool _running;
|
||||||
Callback<void()> _callback;
|
Callback<void()> _callback;
|
||||||
|
|
||||||
|
#if DEVICE_LPTICKER
|
||||||
|
/** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick.
|
||||||
|
*/
|
||||||
|
SingletonPtr<LowPowerTicker> _ticker;
|
||||||
|
#else
|
||||||
|
/** Create singleton instance of Ticker for watchdog periodic call back of kick.
|
||||||
|
*/
|
||||||
|
SingletonPtr<Ticker> _ticker;
|
||||||
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018-2019 Arm Limited and affiliates.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
|
|
||||||
#include "WatchdogManager.h"
|
|
||||||
|
|
||||||
namespace mbed {
|
|
||||||
|
|
||||||
#if DEVICE_LPTICKER
|
|
||||||
/** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick.
|
|
||||||
*/
|
|
||||||
SingletonPtr<LowPowerTicker> _ticker;
|
|
||||||
#else
|
|
||||||
/** Create singleton instance of Ticker for watchdog periodic call back of kick.
|
|
||||||
*/
|
|
||||||
SingletonPtr<Ticker> _ticker;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void WatchdogManager::attach(Callback<void()> func, us_timestamp_t timeout)
|
|
||||||
{
|
|
||||||
_ticker->attach_us(func, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WatchdogManager::detach()
|
|
||||||
{
|
|
||||||
_ticker->detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace mbed
|
|
||||||
|
|
||||||
|
|
||||||
#endif // DEVICE_WATCHDOG
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Arm Limited and affiliates.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* 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_MANAGER_H
|
|
||||||
#define MBED_WATCHDOG_MANAGER_H
|
|
||||||
|
|
||||||
#include "platform/SingletonPtr.h"
|
|
||||||
#include "drivers/LowPowerTicker.h"
|
|
||||||
#include "platform/Callback.h"
|
|
||||||
#include "hal/ticker_api.h"
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
|
|
||||||
namespace mbed {
|
|
||||||
|
|
||||||
/** \addtogroup drivers */
|
|
||||||
|
|
||||||
class WatchdogManager {
|
|
||||||
public:
|
|
||||||
static void attach(Callback<void()> func, us_timestamp_t timeout);
|
|
||||||
static void detach();
|
|
||||||
// static uint32_t get_elapsed();
|
|
||||||
static const uint32_t elapsed_ms = MBED_CONF_TARGET_WATCHDOG_TIMEOUT / 2;
|
|
||||||
private:
|
|
||||||
#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
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mbed
|
|
||||||
|
|
||||||
#endif // MBED_WATCHDOG_MANAGER_H
|
|
Loading…
Reference in New Issue