Move watchdog parameter validation into the driver layer

pull/10657/head
Steven Cartmell 2018-01-08 12:49:50 +00:00 committed by Filip Jagodzinski
parent 31924b2481
commit e7761a1d39
3 changed files with 8 additions and 27 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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) {