Skip to content

Commit 5e4afa3

Browse files
committed
watchdog: move timeout exception to shared-bindings
Make this exception globally available to all platforms that have enabled the watchdog timer. Signed-off-by: Sean Cross <[email protected]>
1 parent 9138e35 commit 5e4afa3

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

ports/nrf/common-hal/watchdog/WatchDogTimer.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@ STATIC nrfx_timer_t *timer = NULL;
5050
STATIC nrfx_wdt_t wdt = NRFX_WDT_INSTANCE(0);
5151
STATIC nrfx_wdt_channel_id wdt_channel_id;
5252

53-
const mp_obj_type_t mp_type_WatchDogTimeout = {
54-
{ &mp_type_type },
55-
.name = MP_QSTR_WatchDogTimeout,
56-
.make_new = mp_obj_exception_make_new,
57-
.attr = mp_obj_exception_attr,
58-
.parent = &mp_type_Exception,
59-
};
60-
61-
mp_obj_exception_t mp_watchdog_timeout_exception = {
62-
.base.type = &mp_type_WatchDogTimeout,
63-
.traceback_alloc = 0,
64-
.traceback_len = 0,
65-
.traceback_data = NULL,
66-
.args = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj,
67-
};
68-
6953
STATIC void watchdogtimer_timer_event_handler(nrf_timer_event_t event_type, void *p_context) {
7054
watchdog_watchdogtimer_obj_t *self = MP_OBJ_TO_PTR(p_context);
7155
if (event_type != NRF_TIMER_EVENT_COMPARE0) {

shared-bindings/watchdog/__init__.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@
5555
//| w.feed()"""
5656
//|
5757

58+
const mp_obj_type_t mp_type_WatchDogTimeout = {
59+
{ &mp_type_type },
60+
.name = MP_QSTR_WatchDogTimeout,
61+
.make_new = mp_obj_exception_make_new,
62+
.attr = mp_obj_exception_attr,
63+
.parent = &mp_type_Exception,
64+
};
65+
66+
mp_obj_exception_t mp_watchdog_timeout_exception = {
67+
.base.type = &mp_type_WatchDogTimeout,
68+
.traceback_alloc = 0,
69+
.traceback_len = 0,
70+
.traceback_data = NULL,
71+
.args = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj,
72+
};
73+
5874
STATIC const mp_rom_map_elem_t watchdog_module_globals_table[] = {
5975
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_watchdog) },
6076
{ MP_ROM_QSTR(MP_QSTR_WatchDogMode), MP_ROM_PTR(&watchdog_watchdogmode_type) },

shared-bindings/watchdog/__init__.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@
2828
#define MICROPY_INCLUDED_SHARED_BINDINGS_WATCHDOG___INIT___H
2929

3030
extern const mp_obj_module_t watchdog_module;
31+
extern mp_obj_exception_t mp_watchdog_timeout_exception;
32+
extern const mp_obj_type_t mp_type_WatchDogTimeout;
3133

3234
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WATCHDOG___INIT___H

supervisor/shared/tick.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
4444

4545
#include "shared-bindings/microcontroller/__init__.h"
4646

47+
#ifdef CIRCUITPY_WATCHDOG
48+
#include "shared-bindings/watchdog/__init__.h"
49+
#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception)
50+
#else
51+
#define WATCHDOG_EXCEPTION_CHECK() 0
52+
#endif
53+
4754
void supervisor_tick(void) {
4855
#if CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS > 0
4956
filesystem_tick();
@@ -86,13 +93,6 @@ void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() {
8693
run_background_tasks();
8794
}
8895

89-
#ifdef CIRCUITPY_WATCHDOG
90-
extern mp_obj_exception_t mp_watchdog_timeout_exception;
91-
#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception)
92-
#else
93-
#define WATCHDOG_EXCEPTION_CHECK() 0
94-
#endif
95-
9696
void mp_hal_delay_ms(mp_uint_t delay) {
9797
uint64_t start_tick = port_get_raw_ticks(NULL);
9898
// Adjust the delay to ticks vs ms.

0 commit comments

Comments
 (0)