@@ -88,59 +88,63 @@ void pybwdt_sl_alive (void) {
8888/******************************************************************************/
8989// Micro Python bindings
9090
91- /// \function constructor('msec')
92- /// Enables the watchdog timer with msec timeout value
93- 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 ) {
91+ STATIC const mp_arg_t pyb_wdt_init_args [] = {
92+ { MP_QSTR_id , MP_ARG_OBJ , {.u_obj = mp_const_none } },
93+ { MP_QSTR_timeout , MP_ARG_INT , {.u_int = 5000 } }, // 5 s
94+ };
95+ 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 * all_args ) {
9496 // check the arguments
95- mp_arg_check_num (n_args , n_kw , 0 , 1 , false);
96-
97- if (n_args > 0 ) {
98- mp_int_t msec = mp_obj_get_int (args [0 ]);
99- if (msec < PYBWDT_MIN_TIMEOUT_MS ) {
100- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , mpexception_value_invalid_arguments ));
101- }
102- if (pybwdt_data .running ) {
103- nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , mpexception_os_request_not_possible ));
104- }
105-
106- // Enable the WDT peripheral clock
107- MAP_PRCMPeripheralClkEnable (PRCM_WDT , PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK );
108-
109- // Unlock to be able to configure the registers
110- MAP_WatchdogUnlock (WDT_BASE );
111-
112- #ifdef DEBUG
113- // make the WDT stall when the debugger stops on a breakpoint
114- MAP_WatchdogStallEnable (WDT_BASE );
115- #endif
116-
117- // set the watchdog timer reload value
118- // the WDT trigger a system reset after the second timeout
119- // so, divide by 2 the timeout value received
120- MAP_WatchdogReloadSet (WDT_BASE , PYBWDT_MILLISECONDS_TO_TICKS (msec / 2 ));
121-
122- // start the timer. Once it's started, it cannot be disabled.
123- MAP_WatchdogEnable (WDT_BASE );
124- pybwdt_data .running = true;
97+ mp_map_t kw_args ;
98+ mp_map_init_fixed_table (& kw_args , n_kw , all_args + n_args );
99+ mp_arg_val_t args [MP_ARRAY_SIZE (pyb_wdt_init_args )];
100+ mp_arg_parse_all (n_args , all_args , & kw_args , MP_ARRAY_SIZE (args ), pyb_wdt_init_args , args );
101+
102+ if (args [0 ].u_obj != mp_const_none && mp_obj_get_int (args [0 ].u_obj ) > 0 ) {
103+ nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , mpexception_os_resource_not_avaliable ));
104+ }
105+ uint timeout_ms = args [1 ].u_int ;
106+ if (timeout_ms < PYBWDT_MIN_TIMEOUT_MS ) {
107+ nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , mpexception_value_invalid_arguments ));
125108 }
109+ if (pybwdt_data .running ) {
110+ nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , mpexception_os_request_not_possible ));
111+ }
112+
113+ // Enable the WDT peripheral clock
114+ MAP_PRCMPeripheralClkEnable (PRCM_WDT , PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK );
115+
116+ // Unlock to be able to configure the registers
117+ MAP_WatchdogUnlock (WDT_BASE );
118+
119+ #ifdef DEBUG
120+ // make the WDT stall when the debugger stops on a breakpoint
121+ MAP_WatchdogStallEnable (WDT_BASE );
122+ #endif
123+
124+ // set the watchdog timer reload value
125+ // the WDT trigger a system reset after the second timeout
126+ // so, divide by 2 the timeout value received
127+ MAP_WatchdogReloadSet (WDT_BASE , PYBWDT_MILLISECONDS_TO_TICKS (timeout_ms / 2 ));
128+
129+ // start the timer. Once it's started, it cannot be disabled.
130+ MAP_WatchdogEnable (WDT_BASE );
131+ pybwdt_data .running = true;
126132
127133 return (mp_obj_t )& pyb_wdt_obj ;
128134}
129135
130- /// \function wdt.kick()
131- /// Kicks the watchdog timer
132- STATIC mp_obj_t pyb_wdt_kick (mp_obj_t self ) {
136+ STATIC mp_obj_t pyb_wdt_feed (mp_obj_t self ) {
133137 if ((pybwdt_data .servers || pybwdt_data .servers_sleeping ) && pybwdt_data .simplelink && pybwdt_data .running ) {
134138 pybwdt_data .servers = false;
135139 pybwdt_data .simplelink = false;
136140 MAP_WatchdogIntClear (WDT_BASE );
137141 }
138142 return mp_const_none ;
139143}
140- STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_wdt_kick_obj , pyb_wdt_kick );
144+ STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_wdt_feed_obj , pyb_wdt_feed );
141145
142146STATIC const mp_map_elem_t pybwdt_locals_dict_table [] = {
143- { MP_OBJ_NEW_QSTR (MP_QSTR_kick ), (mp_obj_t )& pyb_wdt_kick_obj },
147+ { MP_OBJ_NEW_QSTR (MP_QSTR_feed ), (mp_obj_t )& pyb_wdt_feed_obj },
144148};
145149STATIC MP_DEFINE_CONST_DICT (pybwdt_locals_dict , pybwdt_locals_dict_table );
146150
0 commit comments