Skip to content

Commit

Permalink
implement suggested changes
Browse files Browse the repository at this point in the history
- update the docs
- split out common `watchdog_reset`
- revert to using `None` instead of `WatchDogMode.NONE`
  • Loading branch information
microdev1 committed Sep 24, 2023
1 parent 05812e0 commit 27fd60d
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 104 deletions.
15 changes: 6 additions & 9 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ msgstr ""
msgid "%q must be <= %u"
msgstr ""

#: py/argcheck.c
msgid "%q must be >= %d"
msgstr ""

#: shared-bindings/analogbufio/BufferedIn.c
msgid "%q must be a bytearray or array of type 'H' or 'B'"
msgstr ""
Expand Down Expand Up @@ -447,10 +451,6 @@ msgstr ""
msgid "A hardware interrupt channel is already in use"
msgstr ""

#: ports/espressif/common-hal/analogio/AnalogIn.c
msgid "ADC2 is being used by WiFi"
msgstr ""

#: ports/raspberrypi/common-hal/wifi/Radio.c
msgid "AP could not be started"
msgstr ""
Expand Down Expand Up @@ -4185,7 +4185,8 @@ msgstr ""
msgid "unexpected keyword argument"
msgstr ""

#: py/bc.c py/objnamedtuple.c shared-bindings/traceback/__init__.c
#: py/argcheck.c py/bc.c py/objnamedtuple.c
#: shared-bindings/traceback/__init__.c
msgid "unexpected keyword argument '%q'"
msgstr ""

Expand Down Expand Up @@ -4279,10 +4280,6 @@ msgstr ""
msgid "value out of range of target"
msgstr ""

#: ports/espressif/common-hal/watchdog/WatchDogTimer.c
msgid "watchdog not initialized"
msgstr ""

#: shared-bindings/is31fl3741/FrameBuffer.c
msgid "width must be greater than zero"
msgstr ""
Expand Down
15 changes: 0 additions & 15 deletions ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include "py/runtime.h"

#include "shared/runtime/pyexec.h"

#include "shared-bindings/watchdog/__init__.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"
#include "shared-bindings/microcontroller/__init__.h"
Expand Down Expand Up @@ -82,19 +80,6 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
self->mode = WATCHDOGMODE_NONE;
}

void watchdog_reset(void) {
watchdog_watchdogtimer_obj_t *self = &common_hal_mcu_watchdogtimer_obj;
if (self->mode == WATCHDOGMODE_RESET) {
mp_obj_t exception = pyexec_result()->exception;
if (exception != MP_OBJ_NULL &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
return;
}
}
common_hal_watchdog_deinit(self);
}

mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {
return self->timeout;
}
Expand Down
6 changes: 3 additions & 3 deletions ports/atmel-samd/common-hal/watchdog/WatchDogTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H

#include "py/obj.h"

#include "shared-module/watchdog/__init__.h"

#include "shared-bindings/watchdog/WatchDogMode.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"

Expand All @@ -37,7 +40,4 @@ struct _watchdog_watchdogtimer_obj_t {
watchdog_watchdogmode_t mode;
};

// This needs to be called in order to disable the watchdog
void watchdog_reset(void);

#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H
15 changes: 0 additions & 15 deletions ports/espressif/common-hal/watchdog/WatchDogTimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

#include "py/runtime.h"

#include "shared/runtime/pyexec.h"

#include "shared-bindings/watchdog/__init__.h"
#include "shared-bindings/microcontroller/__init__.h"

Expand Down Expand Up @@ -68,19 +66,6 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
}
}

void watchdog_reset(void) {
watchdog_watchdogtimer_obj_t *self = &common_hal_mcu_watchdogtimer_obj;
if (self->mode == WATCHDOGMODE_RESET) {
mp_obj_t exception = pyexec_result()->exception;
if (exception != MP_OBJ_NULL &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
return;
}
}
common_hal_watchdog_deinit(self);
}

static void wdt_config(uint32_t timeout, watchdog_watchdogmode_t mode) {
// enable panic hanler in WATCHDOGMODE_RESET mode
// initialize Task Watchdog Timer (TWDT)
Expand Down
6 changes: 3 additions & 3 deletions ports/espressif/common-hal/watchdog/WatchDogTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H

#include "py/obj.h"

#include "shared-module/watchdog/__init__.h"

#include "shared-bindings/watchdog/WatchDogMode.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"

Expand All @@ -37,7 +40,4 @@ struct _watchdog_watchdogtimer_obj_t {
watchdog_watchdogmode_t mode;
};

// This needs to be called in order to disable the watchdog
void watchdog_reset(void);

#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H
15 changes: 0 additions & 15 deletions ports/nrf/common-hal/watchdog/WatchDogTimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include "py/objproperty.h"
#include "py/runtime.h"

#include "shared/runtime/pyexec.h"

#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/watchdog/__init__.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"
Expand Down Expand Up @@ -109,19 +107,6 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
self->mode = WATCHDOGMODE_NONE;
}

void watchdog_reset(void) {
watchdog_watchdogtimer_obj_t *self = &common_hal_mcu_watchdogtimer_obj;
if (self->mode == WATCHDOGMODE_RESET) {
mp_obj_t exception = pyexec_result()->exception;
if (exception != MP_OBJ_NULL &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
return;
}
}
common_hal_watchdog_deinit(self);
}

mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {
return self->timeout;
}
Expand Down
7 changes: 3 additions & 4 deletions ports/nrf/common-hal/watchdog/WatchDogTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#define MICROPY_INCLUDED_NRF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H

#include "py/obj.h"

#include "shared-module/watchdog/__init__.h"

#include "shared-bindings/watchdog/WatchDogMode.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"

Expand All @@ -37,8 +40,4 @@ struct _watchdog_watchdogtimer_obj_t {
watchdog_watchdogmode_t mode;
};

// This needs to be called in order to disable the watchdog if it's set to
// "RAISE". If set to "RESET", then the watchdog cannot be reset.
void watchdog_reset(void);

#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H
15 changes: 0 additions & 15 deletions ports/raspberrypi/common-hal/watchdog/WatchDogTimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

#include "py/runtime.h"

#include "shared/runtime/pyexec.h"

#include "shared-bindings/watchdog/__init__.h"
#include "shared-bindings/microcontroller/__init__.h"

Expand All @@ -49,19 +47,6 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
self->mode = WATCHDOGMODE_NONE;
}

void watchdog_reset(void) {
watchdog_watchdogtimer_obj_t *self = &common_hal_mcu_watchdogtimer_obj;
if (self->mode == WATCHDOGMODE_RESET) {
mp_obj_t exception = pyexec_result()->exception;
if (exception != MP_OBJ_NULL &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
return;
}
}
common_hal_watchdog_deinit(self);
}

mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {
return self->timeout;
}
Expand Down
6 changes: 3 additions & 3 deletions ports/raspberrypi/common-hal/watchdog/WatchDogTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H

#include "py/obj.h"

#include "shared-module/watchdog/__init__.h"

#include "shared-bindings/watchdog/WatchDogMode.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"

Expand All @@ -37,7 +40,4 @@ struct _watchdog_watchdogtimer_obj_t {
watchdog_watchdogmode_t mode;
};

// This needs to be called in order to disable the watchdog
void watchdog_reset(void);

#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H
4 changes: 0 additions & 4 deletions ports/silabs/common-hal/watchdog/WatchDogTimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
WDOG_Enable(false);
}

void watchdog_reset(void) {
common_hal_watchdog_deinit(&common_hal_mcu_watchdogtimer_obj);
}

mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {
return self->timeout;
}
Expand Down
6 changes: 3 additions & 3 deletions ports/silabs/common-hal/watchdog/WatchDogTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H

#include "py/obj.h"

#include "shared-module/watchdog/__init__.h"

#include "shared-bindings/watchdog/WatchDogMode.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"

Expand All @@ -37,7 +40,4 @@ struct _watchdog_watchdogtimer_obj_t {
watchdog_watchdogmode_t mode;
};

// This needs to be called in order to disable the watchdog
void watchdog_reset(void);

#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H
4 changes: 4 additions & 0 deletions ports/silabs/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ void reset_port(void) {
#if CIRCUITPY_RTC
rtc_reset();
#endif

#if CIRCUITPY_WATCHDOG
watchdog_reset();
#endif
}

void reset_to_bootloader(void) {
Expand Down
1 change: 1 addition & 0 deletions py/circuitpy_defns.mk
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ SRC_SHARED_MODULE_ALL = \
usb/core/__init__.c \
usb/core/Device.c \
ustack/__init__.c \
watchdog/__init__.c \
zlib/__init__.c \
vectorio/Circle.c \
vectorio/Polygon.c \
Expand Down
5 changes: 0 additions & 5 deletions shared-bindings/watchdog/WatchDogMode.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,19 @@

#include "shared-bindings/watchdog/WatchDogMode.h"

MAKE_ENUM_VALUE(watchdog_watchdogmode_type, watchdogmode, NONE, WATCHDOGMODE_NONE);
MAKE_ENUM_VALUE(watchdog_watchdogmode_type, watchdogmode, RAISE, WATCHDOGMODE_RAISE);
MAKE_ENUM_VALUE(watchdog_watchdogmode_type, watchdogmode, RESET, WATCHDOGMODE_RESET);

//| class WatchDogMode:
//| """Run state of the watchdog timer."""
//|
//| NONE: WatchDogMode
//| """The `WatchDogTimer` is disabled."""
//|
//| RAISE: WatchDogMode
//| """Raise an exception when the `WatchDogTimer` expires."""
//|
//| RESET: WatchDogMode
//| """Reset the system when the `WatchDogTimer` expires."""
//|
MAKE_ENUM_MAP(watchdog_watchdogmode) {
MAKE_ENUM_MAP_ENTRY(watchdogmode, NONE),
MAKE_ENUM_MAP_ENTRY(watchdogmode, RAISE),
MAKE_ENUM_MAP_ENTRY(watchdogmode, RESET),
};
Expand Down
18 changes: 10 additions & 8 deletions shared-bindings/watchdog/WatchDogTimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(watchdog_watchdogtimer_feed_obj, watchdog_watch
//|
//| :raises RuntimeError: if the watchdog timer cannot be disabled on this platform.
//|
//| .. note:: This is deprecated in ``8.1.0`` and will be removed in ``9.0.0``.
//| Set watchdog `mode` to `WatchDogMode.NONE` instead.
//| .. note:: This is deprecated in ``9.0.0`` and will be removed in ``10.0.0``.
//| Set watchdog `mode` to `None` instead.
//|
//| """
//| ...
Expand Down Expand Up @@ -107,16 +107,17 @@ MP_PROPERTY_GETSET(watchdog_watchdogtimer_timeout_obj,
(mp_obj_t)&watchdog_watchdogtimer_get_timeout_obj,
(mp_obj_t)&watchdog_watchdogtimer_set_timeout_obj);

//| mode: WatchDogMode
//| """The current operating mode of the WatchDogTimer `watchdog.WatchDogMode`.
//| mode: Optional[WatchDogMode]
//| """The current operating mode of the WatchDogTimer `watchdog.WatchDogMode` or `None` when
//| the timer is disabled.
//|
//| Setting a `WatchDogMode` activates the WatchDog::
//|
//| from microcontroller import watchdog as w
//| from microcontroller import watchdog
//| from watchdog import WatchDogMode
//|
//| w.timeout = 5
//| w.mode = WatchDogMode.RESET
//| watchdog.timeout = 5
//| watchdog.mode = WatchDogMode.RESET
//|
//|
//| Once set, the `WatchDogTimer` will perform the specified action if the timer expires."""
Expand All @@ -129,7 +130,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(watchdog_watchdogtimer_get_mode_obj, watchdog_watchdog

STATIC mp_obj_t watchdog_watchdogtimer_obj_set_mode(mp_obj_t self_in, mp_obj_t obj) {
watchdog_watchdogtimer_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_watchdog_set_mode(self, cp_enum_value(&watchdog_watchdogmode_type, obj, MP_QSTR_mode));
watchdog_watchdogmode_t mode = (obj == mp_const_none) ? WATCHDOGMODE_NONE : cp_enum_value(&watchdog_watchdogmode_type, obj, MP_QSTR_mode);
common_hal_watchdog_set_mode(self, mode);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(watchdog_watchdogtimer_set_mode_obj, watchdog_watchdogtimer_obj_set_mode);
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/watchdog/WatchDogTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WATCHDOG_WATCHDOGTIMER_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_WATCHDOG_WATCHDOGTIMER_H

#include <py/obj.h>
#include "py/obj.h"
#include "shared-bindings/watchdog/WatchDogMode.h"

typedef struct _watchdog_watchdogtimer_obj_t watchdog_watchdogtimer_obj_t;

extern void common_hal_watchdog_feed(watchdog_watchdogtimer_obj_t *self);

extern void common_hal_watchdog_set_mode(watchdog_watchdogtimer_obj_t *self, watchdog_watchdogmode_t);
extern void common_hal_watchdog_set_mode(watchdog_watchdogtimer_obj_t *self, watchdog_watchdogmode_t mode);
extern watchdog_watchdogmode_t common_hal_watchdog_get_mode(watchdog_watchdogtimer_obj_t *self);

extern void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self, mp_float_t timeout);
Expand Down

0 comments on commit 27fd60d

Please sign in to comment.