mirror of https://github.com/ARMmbed/mbed-os.git
Add HwWatchdog
- mbed_watchdog_mgr has interface name mbed_wdog_manager_start(),mbed_wdog_manager_stop(),mbed_wdog_manager_kick() - HwWatchdog is going to attach with LowPowerTIcker for periodic callback functionality - mbed_wdog_manager_start() will either get start either by BL/RTOS Aps,it reads the timeout value specified via macro and macro gets defined in target.json file. - mbed_wdog_manager_start() internally configure below HAL hw watchdog with timeout specified via target.json - mbed_wdog_manager_start() internally divide the timeout(specified in target.json) by the 2 and attach LowPowerTicker with periodic callback of hw_kick() - mbed_wdog_manager_start() internally create one instance of sw watchdog class,to access the static list data structure of sw watchdog class - mbed_wdog_manager_kick() function periodically get called and refresh the hw watchdog to avoid watchdog reset - converted C++ code into C based APIs - added boolean to control watchdog start and stop - Added detach from ticker on stop APIpull/11023/head
parent
bb9ccb8f47
commit
1ab851bacf
2
mbed.h
2
mbed.h
|
@ -77,7 +77,7 @@
|
|||
|
||||
// mbed Internal components
|
||||
#include "drivers/ResetReason.h"
|
||||
#include "drivers/Watchdog.h"
|
||||
#include "platform/mbed_watchdog_mgr.h"
|
||||
#include "drivers/Timer.h"
|
||||
#include "drivers/Ticker.h"
|
||||
#include "drivers/Timeout.h"
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018 ARM Limited
|
||||
* 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 "mbed_watchdog_mgr.h"
|
||||
|
||||
static bool is_watchdog_started = false; //boolean to control watchdog start and stop
|
||||
#define MS_TO_US(x) ((x) * 1000) //macro to convert millisecond to microsecond
|
||||
|
||||
MBED_STATIC_ASSERT((HW_WATCHDOG_TIMEOUT >= 0),"Timeout must be greater than zero");
|
||||
|
||||
|
||||
/** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick.
|
||||
*/
|
||||
static LowPowerTicker *get_ticker()
|
||||
{
|
||||
static LowPowerTicker ticker;
|
||||
return &ticker;
|
||||
}
|
||||
|
||||
/** Refreshes the watchdog timer.
|
||||
*
|
||||
* This function should be called periodically before the watchdog times out.
|
||||
* Otherwise, the system is reset.
|
||||
*
|
||||
* If the watchdog timer is not currently running this function does nothing
|
||||
*/
|
||||
static void mbed_wdog_manager_kick()
|
||||
{
|
||||
core_util_critical_section_enter();
|
||||
hal_watchdog_kick();
|
||||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
uint32_t mbed_wdog_manager_get_max_timeout()
|
||||
{
|
||||
const watchdog_features_t features = hal_watchdog_get_platform_features();
|
||||
return features.max_timeout;
|
||||
}
|
||||
|
||||
bool mbed_wdog_manager_start()
|
||||
{
|
||||
|
||||
watchdog_status_t sts;
|
||||
bool msts = true;
|
||||
MBED_ASSERT(HW_WATCHDOG_TIMEOUT < mbed_wdog_manager_get_max_timeout());
|
||||
core_util_critical_section_enter();
|
||||
if(is_watchdog_started) {
|
||||
core_util_critical_section_exit();
|
||||
return false;
|
||||
}
|
||||
watchdog_config_t config;
|
||||
config.timeout_ms = HW_WATCHDOG_TIMEOUT;
|
||||
sts = hal_watchdog_init(&config);
|
||||
if(sts != WATCHDOG_STATUS_OK) {
|
||||
msts = false;
|
||||
} else {
|
||||
us_timestamp_t timeout = (MS_TO_US(HW_WATCHDOG_TIMEOUT)/2);
|
||||
get_ticker()->attach_us(callback(&mbed_wdog_manager_kick),timeout);
|
||||
is_watchdog_started = true;
|
||||
}
|
||||
core_util_critical_section_exit();
|
||||
return msts;
|
||||
}
|
||||
|
||||
bool mbed_wdog_manager_stop()
|
||||
{
|
||||
watchdog_status_t sts;
|
||||
bool msts = true;
|
||||
core_util_critical_section_enter();
|
||||
if(is_watchdog_started) {
|
||||
sts = hal_watchdog_stop();
|
||||
if(sts != WATCHDOG_STATUS_OK) {
|
||||
msts = false;
|
||||
} else {
|
||||
get_ticker()->detach();
|
||||
is_watchdog_started = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
msts = false;
|
||||
}
|
||||
core_util_critical_section_exit();
|
||||
return msts;
|
||||
}
|
||||
|
||||
|
||||
uint32_t mbed_wdog_manager_get_reload_value()
|
||||
{
|
||||
return hal_watchdog_get_reload_value();
|
||||
}
|
||||
|
||||
|
||||
#endif // DEVICE_WATCHDOG
|
|
@ -0,0 +1,92 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018 ARM Limited
|
||||
* 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_H
|
||||
#define MBED_WATCHDOG_H
|
||||
|
||||
#ifdef DEVICE_WATCHDOG
|
||||
|
||||
#include "watchdog_api.h"
|
||||
#include "mbed_error.h"
|
||||
#include "mbed.h"
|
||||
#include "platform/mbed_critical.h"
|
||||
#include "LowPowerTicker.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \addtogroup drivers */
|
||||
/** A system timer that will reset the system in the case of system failures or
|
||||
* malfunctions.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
*
|
||||
* mbed_wdog_manager_start();
|
||||
*
|
||||
* while (true) {
|
||||
* wait(0.3);
|
||||
*
|
||||
* }
|
||||
* @endcode
|
||||
* @ingroup drivers
|
||||
*/
|
||||
|
||||
/** Start an independent 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 mbed_wdog_manager_start();
|
||||
|
||||
/** Stops the watchdog timer
|
||||
*
|
||||
* Calling this function will attempt to disable any currently running
|
||||
* watchdog timers if supported by the current platform.
|
||||
*
|
||||
* @return Returns true if the watchdog timer was succesfully
|
||||
* stopped, or if the timer was never started. Returns
|
||||
* false if the watchdog cannot be disabled
|
||||
* on the current platform.
|
||||
*/
|
||||
bool mbed_wdog_manager_stop();
|
||||
|
||||
|
||||
/** Get the watchdog timer refresh value
|
||||
*
|
||||
* This function returns the refresh timeout of the watchdog timer.
|
||||
*
|
||||
* @return Reload value for the watchdog timer in milliseconds.
|
||||
*/
|
||||
uint32_t mbed_wdog_manager_get_reload_value();
|
||||
|
||||
|
||||
/** 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
|
||||
*/
|
||||
uint32_t mbed_wdog_manager_get_max_timeout();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // DEVICE_WATCHDOG
|
||||
#endif // MBED_WATCHDOG_H
|
|
@ -51,6 +51,11 @@
|
|||
"init-us-ticker-at-boot": {
|
||||
"help": "Initialize the microsecond ticker at boot rather than on first use, and leave it initialized. This speeds up wait_us in particular.",
|
||||
"value": false
|
||||
},
|
||||
"hw-watchdog_timeout": {
|
||||
"help": "Define the timeout in ms value LowPowerTicker to do HW kick",
|
||||
"value": "800",
|
||||
"macro_name": "HW_WATCHDOG_TIMEOUT"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue