Skip to content

Commit 8096be0

Browse files
author
Daniel Campora
committed
cc3200: Add make_new method to the WDT.
1 parent fca3493 commit 8096be0

4 files changed

Lines changed: 40 additions & 38 deletions

File tree

cc3200/mods/modpyb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
275275
{ MP_OBJ_NEW_QSTR(MP_QSTR_SPI), (mp_obj_t)&pyb_spi_type },
276276
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
277277
{ MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
278-
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_obj },
278+
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type },
279279
{ MP_OBJ_NEW_QSTR(MP_QSTR_Sleep), (mp_obj_t)&pyb_sleep_obj },
280280
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_obj },
281281

cc3200/mods/pybwdt.c

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ typedef struct {
6363
DECLARE PRIVATE DATA
6464
******************************************************************************/
6565
static pybwdt_data_t pybwdt_data = {.servers = false, .servers_sleeping = false, .simplelink = false, .running = false};
66+
STATIC const mp_obj_base_t pyb_wdt_obj = {&pyb_wdt_type};
6667

6768
/******************************************************************************
6869
DEFINE PUBLIC FUNCTIONS
@@ -96,41 +97,44 @@ void pybwdt_sl_alive (void) {
9697
/******************************************************************************/
9798
// Micro Python bindings
9899

99-
/// \function wdt_enable('msec')
100-
/// Enabled the watchdog timer with msec timeout value
101-
STATIC mp_obj_t pyb_enable_wdt(mp_obj_t self, mp_obj_t msec_in) {
102-
mp_int_t msec = mp_obj_get_int(msec_in);
103-
104-
if (msec < PYBWDT_MIN_TIMEOUT_MS) {
105-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
106-
}
107-
if (pybwdt_data.running) {
108-
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible));
100+
/// \function constructor('msec')
101+
/// Enables the watchdog timer with msec timeout value
102+
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) {
103+
// check the arguments
104+
mp_arg_check_num(n_args, n_kw, 0, 1, false);
105+
106+
if (n_args > 0) {
107+
mp_int_t msec = mp_obj_get_int(args[0]);
108+
if (msec < PYBWDT_MIN_TIMEOUT_MS) {
109+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
110+
}
111+
if (pybwdt_data.running) {
112+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible));
113+
}
114+
115+
// Enable the WDT peripheral clock
116+
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
117+
118+
// Unlock to be able to configure the registers
119+
MAP_WatchdogUnlock(WDT_BASE);
120+
121+
#ifdef DEBUG
122+
// make the WDT stall when the debugger stops on a breakpoint
123+
MAP_WatchdogStallEnable (WDT_BASE);
124+
#endif
125+
126+
// set the watchdog timer reload value
127+
// the WDT trigger a system reset after the second timeout
128+
// so, divide by 2 the timeout value received
129+
MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(msec / 2));
130+
131+
// start the timer. Once it's started, it cannot be disabled.
132+
MAP_WatchdogEnable(WDT_BASE);
133+
pybwdt_data.running = true;
109134
}
110135

111-
// Enable the WDT peripheral clock
112-
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
113-
114-
// Unlock to be able to configure the registers
115-
MAP_WatchdogUnlock(WDT_BASE);
116-
117-
#ifdef DEBUG
118-
// make the WDT stall when the debugger stops on a breakpoint
119-
MAP_WatchdogStallEnable (WDT_BASE);
120-
#endif
121-
122-
// set the watchdog timer reload value
123-
// the WDT trigger a system reset after the second timeout
124-
// so, divide by 2 the timeout value received
125-
MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(msec / 2));
126-
127-
// start the timer. Once it's started, it cannot be disabled.
128-
MAP_WatchdogEnable(WDT_BASE);
129-
pybwdt_data.running = true;
130-
131-
return mp_const_none;
136+
return (mp_obj_t)&pyb_wdt_obj;
132137
}
133-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_enable_wdt_obj, pyb_enable_wdt);
134138

135139
/// \function wdt_kick()
136140
/// Kicks the watchdog timer
@@ -141,15 +145,14 @@ STATIC mp_obj_t pyb_kick_wdt(mp_obj_t self) {
141145
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_kick_wdt_obj, pyb_kick_wdt);
142146

143147
STATIC const mp_map_elem_t pybwdt_locals_dict_table[] = {
144-
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pyb_enable_wdt_obj },
145148
{ MP_OBJ_NEW_QSTR(MP_QSTR_kick), (mp_obj_t)&pyb_kick_wdt_obj },
146149
};
147150
STATIC MP_DEFINE_CONST_DICT(pybwdt_locals_dict, pybwdt_locals_dict_table);
148151

149-
static const mp_obj_type_t pybwdt_type = {
152+
const mp_obj_type_t pyb_wdt_type = {
150153
{ &mp_type_type },
151154
.name = MP_QSTR_WDT,
155+
.make_new = pyb_wdt_make_new,
152156
.locals_dict = (mp_obj_t)&pybwdt_locals_dict,
153157
};
154158

155-
const mp_obj_base_t pyb_wdt_obj = {&pybwdt_type};

cc3200/mods/pybwdt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include "py/obj.h"
3131

32-
extern const mp_obj_base_t pyb_wdt_obj;
32+
extern const mp_obj_type_t pyb_wdt_type;
3333

3434
void pybwdt_init0 (void);
3535
void pybwdt_kick (void);

cc3200/qstrdefsport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ Q(WPS_PIN)
275275

276276
// for WDT class
277277
Q(WDT)
278-
Q(enable)
279278
Q(kick)
280279

281280
// for HeartBeat class

0 commit comments

Comments
 (0)