diff options
| author | danicampora | 2015-02-26 15:29:47 +0100 |
|---|---|---|
| committer | danicampora | 2015-03-11 16:54:05 +0100 |
| commit | 0475de1350726871eca827d637fd423dfd836ca2 (patch) | |
| tree | fbe59a2290d49ac14fe8f197df13c395b84cc49b /cc3200/mods | |
| parent | 55278dcc763e62513af02118e6bbd74707007e8d (diff) | |
cc3200: Make WDT and HeartBeat constant objects on their own right.
Diffstat (limited to 'cc3200/mods')
| -rw-r--r-- | cc3200/mods/modpyb.c | 46 | ||||
| -rw-r--r-- | cc3200/mods/pybwdt.c | 111 | ||||
| -rw-r--r-- | cc3200/mods/pybwdt.h | 10 |
3 files changed, 67 insertions, 100 deletions
diff --git a/cc3200/mods/modpyb.c b/cc3200/mods/modpyb.c index bca114a38..031590113 100644 --- a/cc3200/mods/modpyb.c +++ b/cc3200/mods/modpyb.c @@ -271,46 +271,6 @@ STATIC mp_obj_t pyb_mkdisk(mp_obj_t path_o) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_mkdisk_obj, pyb_mkdisk); -/// \function wdt_enable('msec') -/// Enabled the watchdog timer with msec timeout value -STATIC mp_obj_t pyb_enable_wdt(mp_obj_t msec_in) { - mp_int_t msec = mp_obj_get_int(msec_in); - pybwdt_ret_code_t ret; - ret = pybwdt_enable (msec); - if (ret == E_PYBWDT_IS_RUNNING) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible)); - } - else if (ret == E_PYBWDT_INVALID_TIMEOUT) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments)); - } - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_wdt_obj, pyb_enable_wdt); - -/// \function wdt_kick() -/// Kicks the watchdog timer -STATIC mp_obj_t pyb_kick_wdt(void) { - pybwdt_kick (); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_kick_wdt_obj, pyb_kick_wdt); - -/// \function enable_heartbeat() -/// Enables the heartbeat signal -STATIC mp_obj_t pyb_enable_heartbeat(void) { - mperror_enable_heartbeat (); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_enable_heartbeat_obj, pyb_enable_heartbeat); - -/// \function disable_heartbeat() -/// Disables the heartbeat signal -STATIC mp_obj_t pyb_disable_heartbeat(void) { - mperror_disable_heartbeat (); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_heartbeat_obj, pyb_disable_heartbeat); - MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c STATIC const mp_map_elem_t pyb_module_globals_table[] = { @@ -342,10 +302,6 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_udelay), (mp_obj_t)&pyb_udelay_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&pyb_sync_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mkdisk), (mp_obj_t)&pyb_mkdisk_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_enable_wdt), (mp_obj_t)&pyb_enable_wdt_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_kick_wdt), (mp_obj_t)&pyb_kick_wdt_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_enable_heartbeat), (mp_obj_t)&pyb_enable_heartbeat_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_disable_heartbeat), (mp_obj_t)&pyb_disable_heartbeat_obj }, #if MICROPY_HW_ENABLE_RNG { MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&pyb_rng_get_obj }, @@ -360,6 +316,8 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type }, + { MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_obj }, #if MICROPY_HW_HAS_SDCARD { MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type }, diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c index 9ed401f83..97d284d06 100644 --- a/cc3200/mods/pybwdt.c +++ b/cc3200/mods/pybwdt.c @@ -39,6 +39,8 @@ #include "prcm.h" #include "utils.h" #include "pybwdt.h" +#include "mpexception.h" +#include "mperror.h" /****************************************************************************** @@ -65,59 +67,11 @@ static pybwdt_data_t pybwdt_data; DEFINE PUBLIC FUNCTIONS ******************************************************************************/ // must be called in main.c just after initializing the hal +__attribute__ ((section (".boot"))) void pybwdt_init0 (void) { pybwdt_data.running = false; } -void pybwdt_check_reset_cause (void) { - // if we are recovering from a WDT reset, trigger - // a hibernate cycle for a clean boot - if (MAP_PRCMSysResetCauseGet() == PRCM_WDT_RESET) { - HWREG(0x400F70B8) = 1; - UtilsDelay(800000/5); - HWREG(0x400F70B0) = 1; - UtilsDelay(800000/5); - - HWREG(0x4402E16C) |= 0x2; - UtilsDelay(800); - HWREG(0x4402F024) &= 0xF7FFFFFF; - - MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR); - // set the sleep interval to 10ms - MAP_PRCMHibernateIntervalSet(330); - MAP_PRCMHibernateEnter(); - } -} - -// minimum timeout value is 500ms -pybwdt_ret_code_t pybwdt_enable (uint32_t timeout) { - if (timeout >= PYBWDT_MIN_TIMEOUT_MS) { - if (!pybwdt_data.running) { - // 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); - - // Make the WDT stall when the debugger stops on a breakpoint - MAP_WatchdogStallEnable (WDT_BASE); - - // Set the watchdog timer reload value - // the WDT trigger a system reset after the second timeout - // so, divide by the 2 timeout value received - MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(timeout / 2)); - - // Start the timer. Once the timer is started, it cannot be disabled. - MAP_WatchdogEnable(WDT_BASE); - pybwdt_data.running = true; - - return E_PYBWDT_OK; - } - return E_PYBWDT_IS_RUNNING; - } - return E_PYBWDT_INVALID_TIMEOUT; -} - void pybwdt_kick (void) { // check that the servers and simplelink are running fine if (pybwdt_data.servers && pybwdt_data.simplelink && pybwdt_data.running) { @@ -134,3 +88,62 @@ void pybwdt_srv_alive (void) { void pybwdt_sl_alive (void) { pybwdt_data.simplelink = true; } + +/******************************************************************************/ +// 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); + + 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); + + // make the WDT stall when the debugger stops on a breakpoint + MAP_WatchdogStallEnable (WDT_BASE); + + // set the watchdog timer reload value + // the WDT trigger a system reset after the second timeout + // so, divide by the 2 timeout value received + MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(msec / 2)); + + // start the timer. Once wdt is started, it cannot be disabled. + MAP_WatchdogEnable(WDT_BASE); + pybwdt_data.running = true; + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_enable_wdt_obj, pyb_enable_wdt); + +/// \function wdt_kick() +/// Kicks the watchdog timer +STATIC mp_obj_t pyb_kick_wdt(mp_obj_t self) { + pybwdt_kick (); + return mp_const_none; +} +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 = { + { &mp_type_type }, + .name = MP_QSTR_WDT, + .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 4ced61b68..e2e6d8d33 100644 --- a/cc3200/mods/pybwdt.h +++ b/cc3200/mods/pybwdt.h @@ -27,15 +27,11 @@ #ifndef PYBWDT_H_ #define PYBWDT_H_ -typedef enum { - E_PYBWDT_OK = 0, - E_PYBWDT_IS_RUNNING = -1, - E_PYBWDT_INVALID_TIMEOUT = -2 -}pybwdt_ret_code_t; +#include "py/obj.h" + +extern const mp_obj_base_t pyb_wdt_obj; void pybwdt_init0 (void); -void pybwdt_check_reset_cause (void); -pybwdt_ret_code_t pybwdt_enable (uint32_t timeout); void pybwdt_kick (void); void pybwdt_srv_alive (void); void pybwdt_sl_alive (void); |
