From a56da4f3fd1b7d07f7c672fc33a3cba30c60f3ea Mon Sep 17 00:00:00 2001 From: Steven Cartmell Date: Mon, 8 Jan 2018 12:49:50 +0000 Subject: [PATCH] Move watchdog parameter validation into the driver layer --- drivers/Watchdog.cpp | 8 ++++++++ .../TARGET_MCU_K64F/watchdog.c | 14 -------------- targets/TARGET_STM/TARGET_STM32F4/watchdog.c | 13 ------------- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/Watchdog.cpp b/drivers/Watchdog.cpp index 6c8a6edf6d..36a6dd2e18 100644 --- a/drivers/Watchdog.cpp +++ b/drivers/Watchdog.cpp @@ -22,6 +22,14 @@ namespace mbed watchdog_status_t Watchdog::start(const uint32_t timeout) { + if (timeout == 0) { + return WATCHDOG_STATUS_INVALID_ARGUMENT; + } + + if (timeout > max_timeout()) { + return WATCHDOG_STATUS_INVALID_ARGUMENT; + } + watchdog_config_t config; config.timeout_ms = timeout; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog.c index 34d6bab1ae..e72f04db30 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/watchdog.c @@ -52,20 +52,6 @@ static uint32_t calculate_prescaler_value(const uint32_t timeout_ms) watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) { - // Validate the input parameters - if (config == NULL) { - return WATCHDOG_STATUS_INVALID_ARGUMENT; - } - - if (config->timeout_ms == 0) { - return WATCHDOG_STATUS_INVALID_ARGUMENT; - } - - if (config->timeout_ms > max_timeout_ms) { - return WATCHDOG_STATUS_INVALID_ARGUMENT; - } - - wdog_config_t cfg; cfg.enableWdog = true; cfg.clockSource = kWDOG_LpoClockSource; diff --git a/targets/TARGET_STM/TARGET_STM32F4/watchdog.c b/targets/TARGET_STM/TARGET_STM32F4/watchdog.c index a4550c2767..ac66d23fcf 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/watchdog.c +++ b/targets/TARGET_STM/TARGET_STM32F4/watchdog.c @@ -59,19 +59,6 @@ static uint32_t calculate_prescaler_value(const uint32_t timeout_ms) watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) { - // Validate the input parameters - if (config == NULL) { - return WATCHDOG_STATUS_INVALID_ARGUMENT; - } - - if (config->timeout_ms == 0) { - return WATCHDOG_STATUS_INVALID_ARGUMENT; - } - - if (config->timeout_ms > max_timeout_ms) { - return WATCHDOG_STATUS_INVALID_ARGUMENT; - } - const uint32_t prescaler = calculate_prescaler_value(config->timeout_ms); if (prescaler == 0) {