mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 01:40:14 +01:00
rp2/machine_wdt: Check for the maximum timeout value of watchdog.
The value will be checked for timeout <= 8388. Notes were added to the documentation.
This commit is contained in:
@@ -29,6 +29,9 @@
|
||||
|
||||
#include "hardware/watchdog.h"
|
||||
|
||||
// The maximum timeout in milliseconds is: 0xffffff / 2 / 1000
|
||||
#define WDT_TIMEOUT_MAX 8388
|
||||
|
||||
typedef struct _machine_wdt_obj_t {
|
||||
mp_obj_base_t base;
|
||||
} machine_wdt_obj_t;
|
||||
@@ -53,7 +56,11 @@ STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
}
|
||||
|
||||
// Start the watchdog (timeout is in milliseconds).
|
||||
watchdog_enable(args[ARG_timeout].u_int, false);
|
||||
uint32_t timeout = args[ARG_timeout].u_int;
|
||||
if (timeout > WDT_TIMEOUT_MAX) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("timeout exceeds " MP_STRINGIFY(WDT_TIMEOUT_MAX)));
|
||||
}
|
||||
watchdog_enable(timeout, false);
|
||||
|
||||
return MP_OBJ_FROM_PTR(&machine_wdt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user