Skip to content

Commit 47c45d0

Browse files
robert-hhdpgeorge
authored andcommitted
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.
1 parent 8308f9c commit 47c45d0

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

docs/library/machine.WDT.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Example usage::
1515
wdt = WDT(timeout=2000) # enable it with a timeout of 2s
1616
wdt.feed()
1717

18-
Availability of this class: pyboard, WiPy, esp8266, esp32.
18+
Availability of this class: pyboard, WiPy, esp8266, esp32, rp2040, mimxrt.
1919

2020
Constructors
2121
------------
@@ -26,7 +26,8 @@ Constructors
2626
Once it is running the timeout cannot be changed and the WDT cannot be stopped either.
2727

2828
Notes: On the esp32 the minimum timeout is 1 second. On the esp8266 a timeout
29-
cannot be specified, it is determined by the underlying system.
29+
cannot be specified, it is determined by the underlying system. On rp2040 devices,
30+
the maximum timeout is 8388 ms.
3031

3132
Methods
3233
-------

docs/rp2/quickref.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ See :ref:`machine.WDT <machine.WDT>`. ::
296296
wdt = WDT(timeout=5000)
297297
wdt.feed()
298298

299+
The maximum value for timeout is 8388 ms.
299300

300301
OneWire driver
301302
--------------

ports/rp2/machine_wdt.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
#include "hardware/watchdog.h"
3131

32+
// The maximum timeout in milliseconds is: 0xffffff / 2 / 1000
33+
#define WDT_TIMEOUT_MAX 8388
34+
3235
typedef struct _machine_wdt_obj_t {
3336
mp_obj_base_t base;
3437
} 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
5356
}
5457

5558
// Start the watchdog (timeout is in milliseconds).
56-
watchdog_enable(args[ARG_timeout].u_int, false);
59+
uint32_t timeout = args[ARG_timeout].u_int;
60+
if (timeout > WDT_TIMEOUT_MAX) {
61+
mp_raise_ValueError(MP_ERROR_TEXT("timeout exceeds " MP_STRINGIFY(WDT_TIMEOUT_MAX)));
62+
}
63+
watchdog_enable(timeout, false);
5764

5865
return MP_OBJ_FROM_PTR(&machine_wdt);
5966
}

0 commit comments

Comments
 (0)