mirror of https://github.com/ARMmbed/mbed-os.git
Move watchdog parameter validation into the driver layer
parent
31924b2481
commit
e7761a1d39
|
@ -22,6 +22,14 @@ namespace mbed
|
||||||
|
|
||||||
watchdog_status_t Watchdog::start(const uint32_t timeout)
|
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;
|
watchdog_config_t config;
|
||||||
config.timeout_ms = timeout;
|
config.timeout_ms = timeout;
|
||||||
|
|
||||||
|
|
|
@ -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)
|
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;
|
wdog_config_t cfg;
|
||||||
cfg.enableWdog = true;
|
cfg.enableWdog = true;
|
||||||
cfg.clockSource = kWDOG_LpoClockSource;
|
cfg.clockSource = kWDOG_LpoClockSource;
|
||||||
|
|
|
@ -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)
|
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);
|
const uint32_t prescaler = calculate_prescaler_value(config->timeout_ms);
|
||||||
|
|
||||||
if (prescaler == 0) {
|
if (prescaler == 0) {
|
||||||
|
|
Loading…
Reference in New Issue