Remove window and sleep mode options for watchdog API

pull/10657/head
Steven Cartmell 2017-12-04 11:38:24 +00:00 committed by Filip Jagodzinski
parent 8fa38bb25b
commit 7c392a16d4
7 changed files with 42 additions and 160 deletions

View File

@ -1,5 +1,3 @@
/** \addtogroup hal */
/** @{*/
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
@ -25,10 +23,11 @@
namespace mbed
{
/** \addtogroup drivers */
/** @{*/
/**
* \defgroup reset_reason reset reason functions
* @{
/** ResetReason API. When the system is restarted, the reason for the restart is
* contained in the system registers at boot time in a platform specific manner,
* this API provides a generic method of fetching the reason for the restart.
*
* @ingroup drivers
*/
class ResetReason
{
@ -58,20 +57,14 @@ public:
* Example:
* @code
* if (ResetReason::get() == RESET_REASON_PLATFORM) {
* const uint32_t platform_reason = ResetReason::get_raw();
* const uint32_t platform_reason = ResetReason::get_raw();
* }
* @endcode
*/
static uint32_t get_raw();
};
/**@}*/
/**@}*/
} // namespace mbed
/**@}*/
#endif // DEVICE_RESET_REASON
#endif // MBED_RESET_REASON_H

View File

@ -20,19 +20,10 @@
namespace mbed
{
watchdog_status_t Watchdog::start(const uint32_t timeout, const bool enable_sleep)
{
return start(timeout, 0, enable_sleep);
}
watchdog_status_t Watchdog::start(const uint32_t timeout, const uint32_t window, const bool enable_sleep)
watchdog_status_t Watchdog::start(const uint32_t timeout)
{
watchdog_config_t config;
config.timeout_ms = timeout;
config.window_ms = window;
config.enable_window = (window != 0);
config.enable_sleep = enable_sleep;
config.timeout_ms = timeout;
return hal_watchdog_init(&config);
}

View File

@ -1,5 +1,3 @@
/** \addtogroup hal */
/** @{*/
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
@ -28,7 +26,6 @@
namespace mbed {
/** \addtogroup drivers */
/** @{*/
/** A system timer that will reset the system in the case of system failures or
* malfunctions.
*
@ -36,8 +33,7 @@ namespace mbed {
* @code
*
* Watchdog watchdog = Watchdog();
* watchdog.set_timeout(2000);
* watchdog.start();
* watchdog.start(2000);
*
* while (true) {
* watchdog.kick();
@ -45,7 +41,7 @@ namespace mbed {
* // Application code
* }
* @endcode
*
* @ingroup drivers
*/
class Watchdog
{
@ -56,10 +52,6 @@ public:
/** Start an independent watchdog timer with specified parameters
*
* @param timeout Timeout of the watchdog in milliseconds
* @param enable_sleep Sets sleep mode behaviour. When enabled the watchdog
* will continue to run in sleep mode. When disable the
* watchdog will be paused. This feature is not
* supported on all platforms.
*
* @return status WATCHDOG_STATUS_OK if the watchdog timer was started
* successfully. WATCHDOG_INVALID_ARGUMENT if one of the input
@ -67,25 +59,7 @@ public:
* WATCHDOG_NOT_SUPPORTED if one of the enabled input
* parameters is not supported by the current platform.
*/
watchdog_status_t start(const uint32_t timeout, const bool enable_sleep = true);
/** Start a windowed watchdog timer with specified parameters
*
* @param timeout Timeout of the watchdog in milliseconds
* @param window Time period of the window of the watchdog
* @param enable_sleep Sets sleep mode behaviour. When enabled the watchdog
* will continue to run in sleep mode. When disable the
* watchdog will be paused. This feature is not
* supported on all platforms.
*
* @return status WATCHDOG_STATUS_OK if the watchdog timer was started
* successfully. WATCHDOG_INVALID_ARGUMENT if one of the input
* parameters is out of range for the current platform.
* WATCHDOG_NOT_SUPPORTED if one of the enabled input
* parameters is not supported by the current platform.
*/
watchdog_status_t start(const uint32_t timeout, const uint32_t window, const bool enable_sleep = true);
watchdog_status_t start(const uint32_t timeout);
/** Refreshes the watchdog timer.
@ -130,8 +104,5 @@ public:
} // namespace mbed
/**@}*/
/**@}*/
#endif // DEVICE_WATCHDOG
#endif // MBED_WATCHDOG_H

View File

@ -35,13 +35,6 @@
* wraps. To prevent the system reset the timer must be continually
* kicked/refreshed by calling hal_watchdog_kick which will reset the countdown
* to the user specified reset value.
*
* The watchdog timer supports a second mode of operation called windowed mode.
* When configured in this mode by setting enable_window to true, the watchdog
* will enable a restriction on the kick. If the watchdog timer is kicked too
* soon after it has last been refreshed a system reset occurs. The earliest
* time in milliseconds the timer can be kicked without triggering a reset is
* specified by window_ms.
*/
typedef struct
@ -55,28 +48,6 @@ typedef struct
* WATCHDOG_STATUS_INVALID_ARGUMENT.
*/
uint32_t timeout_ms;
/**
* Configures the watchdog for windowed mode of operation instead of running
* the independent watchdog. In this mode a restriction is placed on the
* time period in which the watchdog can be refreshed/kicked. If the
* watchdog is kicked too soon after it has last been refreshed the system
* will be reset. The period of time in which the reset will be triggered is
* defined by window_ms. This value is false by default.
*/
bool enable_window;
/**
* Specifies the time window for the watchdog window in milliseconds. If the
* watchdog is configured to run in windowed mode kicking the watchdog less
* than this many milliseconds after it has last been kicked will trigger a
* system reset. This value must be less than timeout_ms.
*/
uint32_t window_ms;
/**
* Configures the watchdog behaviour while the system is in sleep mode. When
* this flag is enabled the watchdog timer runs normally while the system is
* in sleep mode, when disabled the watchdog is paused during this time.
*/
bool enable_sleep;
} watchdog_config_t;
@ -86,15 +57,6 @@ typedef struct
* Maximum timeout value for the watchdog in milliseconds.
*/
uint32_t max_timeout;
/**
* Maximum timeout value for the watchdog in milliseconds during window
* operation mode
*/
uint32_t max_timeout_window_mode;
/**
* Watchdog timer supports window mode operation
*/
bool window_mode;
/**
* Watchdog configuration can be updated after the watchdog has been started
*/
@ -103,10 +65,6 @@ typedef struct
* Watchdog can be stopped after it is started without a reset
*/
bool disable_watchdog;
/**
* Watchdog can be paused while the core is in sleep mode
*/
bool pause_during_sleep;
} watchdog_features_t;
@ -125,12 +83,8 @@ typedef enum {
* If the watchdog timer is configured and started successfully this
* function will return WATCHDOG_STATUS_OK.
*
* If the enable_window is set but windowed mode is not supported by the
* platform the function will return WATCHDOG_STATUS_NOT_SUPPORTED.
*
* If the timeout specified is outside the range supported by the platform,
* or if the window period is greater than the timeout period it will return
* WATCHDOG_STATUS_INVALID_ARGUMENT.
* If the timeout specified is outside the range supported by the platform
* it will return WATCHDOG_STATUS_INVALID_ARGUMENT.
*
* @param[in] config Configuration settings for the watchdog timer
*
@ -144,10 +98,6 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config);
* This function should be called periodically before the watchdog times out.
* Otherwise, the system is reset.
*
* If using the windowed operation mode this function must be called within the
* configured timeout window. If the function is called before the window is
* reached the system is reset.
*
* If a watchdog is not currently running this function does nothing
*/
void hal_watchdog_kick(void);

View File

@ -19,13 +19,6 @@ const uint64_t max_timeout_ms = ((MAX_TIMEOUT / TICKS_PER_MS) * MAX_PRESCALER);
((MAX_TIMEOUT / TICKS_PER_MS) * scale)
#if defined(FSL_FEATURE_WDOG_HAS_WAITEN) && FSL_FEATURE_WDOG_HAS_WAITEN
#define PLATFORM_SUPPORTS_SLEEP true
#else
#define PLATFORM_SUPPORTS_SLEEP false
#endif
static uint32_t calculate_prescaler_value(const uint32_t timeout_ms)
{
if (timeout_ms > max_timeout_ms) {
@ -57,27 +50,15 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}
if (config->window_ms > max_timeout_ms) {
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}
if (config->window_ms > config->timeout_ms) {
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}
if (config->enable_sleep && !PLATFORM_SUPPORTS_SLEEP) {
return WATCHDOG_STATUS_NOT_SUPPORTED;
}
wdog_config_t cfg;
cfg.enableWdog = true;
cfg.clockSource = kWDOG_LpoClockSource;
cfg.windowValue = 0;
cfg.enableUpdate = true;
cfg.enableInterrupt = false;
cfg.enableWindowMode = config->enable_window;
#if PLATFORM_SUPPORTS_SLEEP
cfg.workMode.enableWait = config->enable_sleep;
#endif
cfg.enableWindowMode = false;
cfg.workMode.enableWait = true;
cfg.workMode.enableStop = false;
cfg.workMode.enableDebug = false;
@ -89,7 +70,6 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
cfg.prescaler = (wdog_clock_prescaler_t)(prescaler - 1);
cfg.timeoutValue = (TICKS_PER_MS * config->timeout_ms) / prescaler;
cfg.windowValue = (TICKS_PER_MS * config->window_ms) / prescaler;
WDOG_Init(WDOG, &cfg);
@ -119,14 +99,12 @@ uint32_t hal_watchdog_get_reload_value(void)
}
watchdog_features_t hal_watchdog_get_max_timeout(void)
watchdog_features_t hal_watchdog_get_platform_features(void)
{
watchdog_features_t features;
features.max_timeout = max_timeout_ms;
features.max_timeout_window_mode = max_timeout_ms;
features.update_config = true;
features.disable_watchdog = true;
features.pause_during_sleep = true;
return features;
}

View File

@ -2,8 +2,11 @@
#include "reset_reason_api.h"
#ifdef DEVICE_WATCHDOG
#include "device.h"
#include <stdbool.h>
// Platform specific watchdog definitions
#define LPO_CLOCK_FREQUENCY 40000
@ -22,7 +25,7 @@ const uint64_t max_timeout_ms = ((MAX_TIMEOUT / TICKS_PER_MS) * MAX_PRESCALER);
static uint32_t calculate_prescaler_value(const uint32_t timeout_ms)
{
if (timeout_ms > MAX_TIMEOUT_MS) {
if (timeout_ms > max_timeout_ms) {
return 0;
}
@ -49,23 +52,10 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}
if (config->timeout_ms > MAX_TIMEOUT_MS) {
if (config->timeout_ms > max_timeout_ms) {
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}
if (config->window_ms > MAX_TIMEOUT_MS) {
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}
if (config->window_ms > config->timeout_ms) {
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}
if (config->enable_sleep == false) {
return WATCHDOG_STATUS_NOT_SUPPORTED;
}
const uint32_t prescaler = calculate_prescaler_value(config->timeout_ms);
if (prescaler == 0) {
@ -108,14 +98,15 @@ uint32_t hal_watchdog_get_reload_value(void)
return ((timeout / TICKS_PER_MS) * prescaler);
}
watchdog_features_t hal_watchdog_get_max_timeout(void)
watchdog_features_t hal_watchdog_get_platform_features(void)
{
watchdog_features_t features;
features.max_timeout = max_timeout_ms;
features.max_timeout_window_mode = max_timeout_ms;
features.update_config = true;
features.disable_watchdog = false;
features.pause_during_sleep = true;
return features;
}
#endif // DEVICE_WATCHDOG

View File

@ -2490,7 +2490,8 @@
"device_has_add": [
"SERIAL_ASYNCH",
"FLASH",
"MPU"
"MPU",
"WATCHDOG"
],
"release_versions": ["2", "5"],
"device_name": "STM32F401RE"
@ -2547,7 +2548,8 @@
"SERIAL_ASYNCH",
"TRNG",
"FLASH",
"MPU"
"MPU",
"WATCHDOG"
],
"release_versions": ["2", "5"],
"device_name": "STM32F410RB"
@ -2570,7 +2572,8 @@
"device_has_add": [
"SERIAL_ASYNCH",
"FLASH",
"MPU"
"MPU",
"WATCHDOG"
],
"release_versions": ["2", "5"],
"device_name": "STM32F411RE",
@ -2898,7 +2901,8 @@
"SERIAL_ASYNCH",
"TRNG",
"FLASH",
"MPU"
"MPU",
"WATCHDOG",
],
"detect_code": ["0797"],
"release_versions": ["2", "5"],
@ -2963,7 +2967,8 @@
"CAN",
"SERIAL_ASYNCH",
"FLASH",
"MPU"
"MPU",
"WATCHDOG"
],
"release_versions": ["2", "5"],
"device_name": "STM32F446RE",
@ -3005,7 +3010,8 @@
"CAN",
"SERIAL_ASYNCH",
"FLASH",
"MPU"
"MPU",
"WATCHDOG"
],
"release_versions": ["2", "5"],
"device_name": "STM32F446VE"
@ -4328,7 +4334,7 @@
"function": "MTSCode.combine_bins_mts_dragonfly",
"toolchains": ["GCC_ARM", "ARM_STD", "ARM_MICRO", "IAR"]
},
"device_has_add": ["MPU", "FLASH"],
"device_has_add": ["MPU", "FLASH", "WATCHDOG"],
"device_has_remove": [
"SERIAL_FC"
],
@ -4535,6 +4541,7 @@
"EMAC",
"TRNG",
"FLASH",
"WATCHDOG",
"WIFI",
"SERIAL"
],
@ -4634,7 +4641,8 @@
"EMAC",
"TRNG",
"FLASH",
"MPU"
"MPU",
"WATCHDOG"
],
"public": false,
"device_name": "STM32F437VG",