diff --git a/cc3200/mods/modpyb.c b/cc3200/mods/modpyb.c index 05645a47aa..dbf14241a5 100644 --- a/cc3200/mods/modpyb.c +++ b/cc3200/mods/modpyb.c @@ -275,7 +275,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_SPI), (mp_obj_t)&pyb_spi_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type }, - { MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_Sleep), (mp_obj_t)&pyb_sleep_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_obj }, diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c index c6c5cae683..b1a6145c20 100644 --- a/cc3200/mods/pybwdt.c +++ b/cc3200/mods/pybwdt.c @@ -63,6 +63,7 @@ typedef struct { DECLARE PRIVATE DATA ******************************************************************************/ static pybwdt_data_t pybwdt_data = {.servers = false, .servers_sleeping = false, .simplelink = false, .running = false}; +STATIC const mp_obj_base_t pyb_wdt_obj = {&pyb_wdt_type}; /****************************************************************************** DEFINE PUBLIC FUNCTIONS @@ -96,41 +97,44 @@ void pybwdt_sl_alive (void) { /******************************************************************************/ // Micro Python bindings -/// \function wdt_enable('msec') -/// Enabled the watchdog timer with msec timeout value -STATIC mp_obj_t pyb_enable_wdt(mp_obj_t self, mp_obj_t msec_in) { - mp_int_t msec = mp_obj_get_int(msec_in); +/// \function constructor('msec') +/// Enables the watchdog timer with msec timeout value +STATIC mp_obj_t pyb_wdt_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { + // check the arguments + mp_arg_check_num(n_args, n_kw, 0, 1, false); - if (msec < PYBWDT_MIN_TIMEOUT_MS) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments)); - } - if (pybwdt_data.running) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible)); + if (n_args > 0) { + mp_int_t msec = mp_obj_get_int(args[0]); + if (msec < PYBWDT_MIN_TIMEOUT_MS) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments)); + } + if (pybwdt_data.running) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible)); + } + + // Enable the WDT peripheral clock + MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); + + // Unlock to be able to configure the registers + MAP_WatchdogUnlock(WDT_BASE); + + #ifdef DEBUG + // make the WDT stall when the debugger stops on a breakpoint + MAP_WatchdogStallEnable (WDT_BASE); + #endif + + // set the watchdog timer reload value + // the WDT trigger a system reset after the second timeout + // so, divide by 2 the timeout value received + MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(msec / 2)); + + // start the timer. Once it's started, it cannot be disabled. + MAP_WatchdogEnable(WDT_BASE); + pybwdt_data.running = true; } - // Enable the WDT peripheral clock - MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); - - // Unlock to be able to configure the registers - MAP_WatchdogUnlock(WDT_BASE); - -#ifdef DEBUG - // make the WDT stall when the debugger stops on a breakpoint - MAP_WatchdogStallEnable (WDT_BASE); -#endif - - // set the watchdog timer reload value - // the WDT trigger a system reset after the second timeout - // so, divide by 2 the timeout value received - MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(msec / 2)); - - // start the timer. Once it's started, it cannot be disabled. - MAP_WatchdogEnable(WDT_BASE); - pybwdt_data.running = true; - - return mp_const_none; + return (mp_obj_t)&pyb_wdt_obj; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_enable_wdt_obj, pyb_enable_wdt); /// \function wdt_kick() /// Kicks the watchdog timer @@ -141,15 +145,14 @@ STATIC mp_obj_t pyb_kick_wdt(mp_obj_t self) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_kick_wdt_obj, pyb_kick_wdt); STATIC const mp_map_elem_t pybwdt_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pyb_enable_wdt_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_kick), (mp_obj_t)&pyb_kick_wdt_obj }, }; STATIC MP_DEFINE_CONST_DICT(pybwdt_locals_dict, pybwdt_locals_dict_table); -static const mp_obj_type_t pybwdt_type = { +const mp_obj_type_t pyb_wdt_type = { { &mp_type_type }, .name = MP_QSTR_WDT, + .make_new = pyb_wdt_make_new, .locals_dict = (mp_obj_t)&pybwdt_locals_dict, }; -const mp_obj_base_t pyb_wdt_obj = {&pybwdt_type}; diff --git a/cc3200/mods/pybwdt.h b/cc3200/mods/pybwdt.h index 9687101c3a..9b96e09222 100644 --- a/cc3200/mods/pybwdt.h +++ b/cc3200/mods/pybwdt.h @@ -29,7 +29,7 @@ #include "py/obj.h" -extern const mp_obj_base_t pyb_wdt_obj; +extern const mp_obj_type_t pyb_wdt_type; void pybwdt_init0 (void); void pybwdt_kick (void); diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h index 30bf4b9cf5..76b3fd5150 100644 --- a/cc3200/qstrdefsport.h +++ b/cc3200/qstrdefsport.h @@ -275,7 +275,6 @@ Q(WPS_PIN) // for WDT class Q(WDT) -Q(enable) Q(kick) // for HeartBeat class