cc3200: New WDT API.
This commit is contained in:
parent
8332044f75
commit
41f6948545
|
@ -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);
|
||||
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 (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;
|
||||
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);
|
||||
|
||||
|
|
|
@ -299,7 +299,8 @@ Q(EXTERNAL)
|
|||
|
||||
// for WDT class
|
||||
Q(WDT)
|
||||
Q(kick)
|
||||
Q(feed)
|
||||
Q(timeout)
|
||||
|
||||
// for HeartBeat class
|
||||
Q(HeartBeat)
|
||||
|
|
|
@ -10,24 +10,23 @@ watchdog periodically to prevent it from expiring and resetting the system.
|
|||
|
||||
Example usage::
|
||||
|
||||
wdt = pyb.WDT(5000) # enable with a timeout of 5s
|
||||
wdt.kick()
|
||||
wdt = pyb.WDT(timeout=2000) # enable with a timeout of 2s
|
||||
wdt.feed()
|
||||
|
||||
Constructors
|
||||
------------
|
||||
|
||||
.. class:: pyb.WDT([timeout])
|
||||
.. class:: pyb.WDT(id=0, timeout=5000)
|
||||
|
||||
Create a WDT object. If the timeout is specified the WDT is started.
|
||||
The timeout must be given in seconds and 1s the minimum value that
|
||||
is accepted. Once it is running the timeout cannot be changed and
|
||||
the WDT cannot be stopped either.
|
||||
Create a WDT object and start it. The timeout must be given in seconds and
|
||||
the minimum value that is accepted is 1 second. Once it is running the timeout
|
||||
cannot be changed and the WDT cannot be stopped either.
|
||||
|
||||
Methods
|
||||
-------
|
||||
|
||||
.. method:: wdt.kick()
|
||||
.. method:: wdt.feed()
|
||||
|
||||
Kick the WDT to prevent it from resetting the system. The application
|
||||
Feed the WDT to prevent it from resetting the system. The application
|
||||
should place this call in a sensible place ensuring that the WDT is
|
||||
only kicked after verifying that everything is functioning correctly.
|
||||
only fed after verifying that everything is functioning correctly.
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
'''
|
||||
WDT test for the CC3200 based boards
|
||||
'''
|
||||
|
||||
from pyb import WDT
|
||||
|
||||
# test the invalid cases first
|
||||
try:
|
||||
wdt = WDT(1)
|
||||
except Exception:
|
||||
print("Exception")
|
||||
|
||||
try:
|
||||
wdt = WDT(0, 500)
|
||||
except Exception:
|
||||
print("Exception")
|
||||
|
||||
try:
|
||||
wdt = WDT(1, timeout=2000)
|
||||
except Exception:
|
||||
print("Exception")
|
||||
|
||||
wdt = WDT(timeout=1000)
|
||||
print(wdt)
|
||||
|
||||
try:
|
||||
wdt = WDT(0, timeout=2000)
|
||||
except Exception:
|
||||
print("Exception")
|
||||
|
||||
pyb.delay(500)
|
||||
wdt.feed()
|
||||
print(wdt)
|
||||
pyb.delay(900)
|
||||
wdt.feed()
|
||||
print(wdt)
|
||||
pyb.delay(950)
|
|
@ -0,0 +1,7 @@
|
|||
Exception
|
||||
Exception
|
||||
Exception
|
||||
<WDT>
|
||||
Exception
|
||||
<WDT>
|
||||
<WDT>
|
Loading…
Reference in New Issue