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 <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-05-22 18:52:21 +08:00
parent c5c13a8ba1
commit c7efc94a33
4 changed files with 25 additions and 23 deletions

View File

@ -50,22 +50,6 @@ STATIC nrfx_timer_t *timer = NULL;
STATIC nrfx_wdt_t wdt = NRFX_WDT_INSTANCE(0);
STATIC nrfx_wdt_channel_id wdt_channel_id;
const mp_obj_type_t mp_type_WatchDogTimeout = {
{ &mp_type_type },
.name = MP_QSTR_WatchDogTimeout,
.make_new = mp_obj_exception_make_new,
.attr = mp_obj_exception_attr,
.parent = &mp_type_Exception,
};
mp_obj_exception_t mp_watchdog_timeout_exception = {
.base.type = &mp_type_WatchDogTimeout,
.traceback_alloc = 0,
.traceback_len = 0,
.traceback_data = NULL,
.args = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj,
};
STATIC void watchdogtimer_timer_event_handler(nrf_timer_event_t event_type, void *p_context) {
watchdog_watchdogtimer_obj_t *self = MP_OBJ_TO_PTR(p_context);
if (event_type != NRF_TIMER_EVENT_COMPARE0) {

View File

@ -55,6 +55,22 @@
//| w.feed()"""
//|
const mp_obj_type_t mp_type_WatchDogTimeout = {
{ &mp_type_type },
.name = MP_QSTR_WatchDogTimeout,
.make_new = mp_obj_exception_make_new,
.attr = mp_obj_exception_attr,
.parent = &mp_type_Exception,
};
mp_obj_exception_t mp_watchdog_timeout_exception = {
.base.type = &mp_type_WatchDogTimeout,
.traceback_alloc = 0,
.traceback_len = 0,
.traceback_data = NULL,
.args = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj,
};
STATIC const mp_rom_map_elem_t watchdog_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_watchdog) },
{ MP_ROM_QSTR(MP_QSTR_WatchDogMode), MP_ROM_PTR(&watchdog_watchdogmode_type) },

View File

@ -28,5 +28,7 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_WATCHDOG___INIT___H
extern const mp_obj_module_t watchdog_module;
extern mp_obj_exception_t mp_watchdog_timeout_exception;
extern const mp_obj_type_t mp_type_WatchDogTimeout;
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WATCHDOG___INIT___H

View File

@ -44,6 +44,13 @@ static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
#include "shared-bindings/microcontroller/__init__.h"
#if CIRCUITPY_WATCHDOG
#include "shared-bindings/watchdog/__init__.h"
#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception)
#else
#define WATCHDOG_EXCEPTION_CHECK() 0
#endif
void supervisor_tick(void) {
#if CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS > 0
filesystem_tick();
@ -86,13 +93,6 @@ void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() {
run_background_tasks();
}
#ifdef CIRCUITPY_WATCHDOG
extern mp_obj_exception_t mp_watchdog_timeout_exception;
#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception)
#else
#define WATCHDOG_EXCEPTION_CHECK() 0
#endif
void mp_hal_delay_ms(mp_uint_t delay) {
uint64_t start_tick = port_get_raw_ticks(NULL);
// Adjust the delay to ticks vs ms.