@@ -47,23 +47,6 @@ STATIC uint8_t timer_refcount = 0;
4747#define WATCHDOG_RELOAD_COUNT 2
4848STATIC nrfx_timer_t * timer = NULL ;
4949
50- const mp_obj_type_t mp_type_WatchDogTimeout = {
51- { & mp_type_type },
52- .name = MP_QSTR_WatchDogTimeout ,
53- .make_new = mp_obj_exception_make_new ,
54- .attr = mp_obj_exception_attr ,
55- .parent = & mp_type_Exception ,
56- };
57-
58- static mp_obj_exception_t mp_watchdog_timeout_exception = {
59- .base .type = & mp_type_WatchDogTimeout ,
60- .traceback_alloc = 0 ,
61- .traceback_len = 0 ,
62- .traceback_data = NULL ,
63- .args = (mp_obj_tuple_t * )& mp_const_empty_tuple_obj ,
64- };
65-
66-
6750STATIC void watchdogtimer_hardware_init (mp_float_t duration , bool pause_during_sleep ) {
6851 unsigned int channel ;
6952 nrf_wdt_behaviour_t behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP_HALT ;
@@ -93,6 +76,10 @@ STATIC void watchdogtimer_hardware_feed(void) {
9376 }
9477}
9578
79+ NORETURN void mp_raise_WatchDogTimeout (void ) {
80+ nlr_raise (MP_OBJ_FROM_PTR (& MP_STATE_VM (mp_watchdog_exception )));
81+ }
82+
9683STATIC void watchdogtimer_event_handler (nrf_timer_event_t event_type , void * p_context ) {
9784 (void )p_context ;
9885 if (event_type != NRF_TIMER_EVENT_COMPARE0 ) {
@@ -102,8 +89,7 @@ STATIC void watchdogtimer_event_handler(nrf_timer_event_t event_type, void *p_co
10289
10390 // If the timer hits without being cleared, pause the timer and raise an exception.
10491 nrfx_timer_pause (timer );
105- mp_obj_exception_clear_traceback (MP_OBJ_FROM_PTR (& mp_watchdog_timeout_exception ));
106- MP_STATE_VM (mp_pending_exception ) = & mp_watchdog_timeout_exception ;
92+ MP_STATE_VM (mp_pending_exception ) = MP_OBJ_FROM_PTR (& MP_STATE_VM (mp_watchdog_exception ));
10793#if MICROPY_ENABLE_SCHEDULER
10894 if (MP_STATE_VM (sched_state ) == MP_SCHED_IDLE ) {
10995 MP_STATE_VM (sched_state ) = MP_SCHED_PENDING ;
@@ -139,6 +125,7 @@ STATIC mp_obj_t watchdog_watchdogtimer_make_new(const mp_obj_type_t *type, size_
139125 {MP_QSTR_hardware , MP_ARG_BOOL , {.u_bool = false}},
140126 };
141127 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
128+ mp_obj_exception_clear_traceback (MP_OBJ_FROM_PTR (& MP_STATE_VM (mp_watchdog_exception )));
142129
143130 mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ),
144131 allowed_args , args );
0 commit comments