aboutsummaryrefslogtreecommitdiff
path: root/cc3200
diff options
context:
space:
mode:
authorDaniel Campora2015-09-13 17:06:12 +0200
committerDaniel Campora2015-09-16 10:10:29 +0200
commit41f6948545c8f5909413badbef2dcd5794598bf0 (patch)
tree312b4f2024d943560844c1ca0fc5c59a6c588155 /cc3200
parent8332044f754aa0743fb38404dae55508a0550e6a (diff)
cc3200: New WDT API.
Diffstat (limited to 'cc3200')
-rw-r--r--cc3200/mods/pybwdt.c80
-rw-r--r--cc3200/qstrdefsport.h3
2 files changed, 44 insertions, 39 deletions
diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c
index 3ea2719f5..b1f9086ce 100644
--- a/cc3200/mods/pybwdt.c
+++ b/cc3200/mods/pybwdt.c
@@ -88,48 +88,52 @@ void pybwdt_sl_alive (void) {
/******************************************************************************/
// Micro Python bindings
-/// \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) {
+STATIC const mp_arg_t pyb_wdt_init_args[] = {
+ { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} },
+ { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 5000} }, // 5 s
+};
+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) {
// check the arguments
- mp_arg_check_num(n_args, n_kw, 0, 1, false);
-
- 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;
+ mp_map_t kw_args;
+ mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
+ mp_arg_val_t args[MP_ARRAY_SIZE(pyb_wdt_init_args)];
+ mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), pyb_wdt_init_args, args);
+
+ if (args[0].u_obj != mp_const_none && mp_obj_get_int(args[0].u_obj) > 0) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable));
+ }
+ uint timeout_ms = args[1].u_int;
+ if (timeout_ms < 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(timeout_ms / 2));
+
+ // start the timer. Once it's started, it cannot be disabled.
+ MAP_WatchdogEnable(WDT_BASE);
+ pybwdt_data.running = true;
return (mp_obj_t)&pyb_wdt_obj;
}
-/// \function wdt.kick()
-/// Kicks the watchdog timer
-STATIC mp_obj_t pyb_wdt_kick(mp_obj_t self) {
+STATIC mp_obj_t pyb_wdt_feed(mp_obj_t self) {
if ((pybwdt_data.servers || pybwdt_data.servers_sleeping) && pybwdt_data.simplelink && pybwdt_data.running) {
pybwdt_data.servers = false;
pybwdt_data.simplelink = false;
@@ -137,10 +141,10 @@ STATIC mp_obj_t pyb_wdt_kick(mp_obj_t self) {
}
return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_wdt_kick_obj, pyb_wdt_kick);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_wdt_feed_obj, pyb_wdt_feed);
STATIC const mp_map_elem_t pybwdt_locals_dict_table[] = {
- { MP_OBJ_NEW_QSTR(MP_QSTR_kick), (mp_obj_t)&pyb_wdt_kick_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&pyb_wdt_feed_obj },
};
STATIC MP_DEFINE_CONST_DICT(pybwdt_locals_dict, pybwdt_locals_dict_table);
diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h
index 337ea9b06..485ff4ec5 100644
--- a/cc3200/qstrdefsport.h
+++ b/cc3200/qstrdefsport.h
@@ -299,7 +299,8 @@ Q(EXTERNAL)
// for WDT class
Q(WDT)
-Q(kick)
+Q(feed)
+Q(timeout)
// for HeartBeat class
Q(HeartBeat)