cc3200: Make WDT and HeartBeat constant objects on their own right.

pull/1137/merge
danicampora 2015-02-26 15:29:47 +01:00
rodzic 55278dcc76
commit 0475de1350
8 zmienionych plików z 140 dodań i 118 usunięć

Wyświetl plik

@ -44,10 +44,6 @@ BOOT_MISC_SRC_C = $(addprefix misc/,\
mperror.c \
)
BOOT_MODS_SRC_C = $(addprefix mods/,\
pybwdt.c \
)
BOOT_SL_SRC_C = $(addprefix simplelink/,\
cc_pal.c \
)
@ -72,8 +68,8 @@ BOOT_STM_SRC_C = $(addprefix stmhal/,\
string0.c \
)
OBJ = $(addprefix $(BUILD)/, $(BOOT_HAL_SRC_C:.c=.o) $(BOOT_MODS_SRC_C:.c=.o) $(BOOT_SL_SRC_C:.c=.o) $(BOOT_CC3100_SRC_C:.c=.o) $(BOOT_UTIL_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(BOOT_MISC_SRC_C:.c=.o) $(BOOT_MAIN_SRC_C:.c=.o) $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o))
OBJ = $(addprefix $(BUILD)/, $(BOOT_HAL_SRC_C:.c=.o) $(BOOT_SL_SRC_C:.c=.o) $(BOOT_CC3100_SRC_C:.c=.o) $(BOOT_UTIL_SRC_C:.c=.o) $(BOOT_MISC_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(BOOT_MAIN_SRC_C:.c=.o) $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o))
# Add the linker script
LINKER_SCRIPT = bootmgr/bootmgr.lds

Wyświetl plik

@ -51,7 +51,6 @@
#include "utils.h"
#include "cc3200_hal.h"
#include "debug.h"
#include "pybwdt.h"
#include "mperror.h"
@ -149,7 +148,7 @@ static void bootmgr_board_init(void) {
// Mandatory MCU Initialization
PRCMCC3200MCUInit();
pybwdt_check_reset_cause();
mperror_check_reset_cause();
// Enable the Data Hashing Engine
HASH_Init();

Wyświetl plik

@ -86,6 +86,26 @@ void mperror_init0 (void) {
#endif
}
void mperror_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();
}
}
void mperror_deinit_sfe_pin (void) {
// disable the pull-down
MAP_PinConfigSet(MICROPY_SAFE_BOOT_PIN_NUM, PIN_STRENGTH_4MA, PIN_TYPE_STD);
@ -179,3 +199,38 @@ void nlr_jump_fail(void *val) {
__fatal_error(NULL);
#endif
}
#ifndef BOOTLOADER
/******************************************************************************/
// Micro Python bindings
/// \function enable()
/// Enables the heartbeat signal
STATIC mp_obj_t pyb_enable_heartbeat(mp_obj_t self) {
mperror_enable_heartbeat ();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_heartbeat_obj, pyb_enable_heartbeat);
/// \function disable()
/// Disables the heartbeat signal
STATIC mp_obj_t pyb_disable_heartbeat(mp_obj_t self) {
mperror_disable_heartbeat ();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_disable_heartbeat_obj, pyb_disable_heartbeat);
STATIC const mp_map_elem_t pyb_heartbeat_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pyb_enable_heartbeat_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&pyb_disable_heartbeat_obj },
};
STATIC MP_DEFINE_CONST_DICT(pyb_heartbeat_locals_dict, pyb_heartbeat_locals_dict_table);
static const mp_obj_type_t pyb_heartbeat_type = {
{ &mp_type_type },
.name = MP_QSTR_HeartBeat,
.locals_dict = (mp_obj_t)&pyb_heartbeat_locals_dict,
};
const mp_obj_base_t pyb_heartbeat_obj = {&pyb_heartbeat_type};
#endif

Wyświetl plik

@ -28,9 +28,14 @@
#ifndef MPERROR_H_
#define MPERROR_H_
#ifndef BOOTLOADER
extern const mp_obj_base_t pyb_heartbeat_obj;
#endif
extern void NORETURN __fatal_error(const char *msg);
void mperror_init0 (void);
void mperror_check_reset_cause (void);
void mperror_deinit_sfe_pin (void);
void mperror_signal_error (void);
void mperror_request_safe_boot (void);

Wyświetl plik

@ -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 },

Wyświetl plik

@ -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};

Wyświetl plik

@ -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);

Wyświetl plik

@ -36,10 +36,8 @@ Q(udelay)
Q(flush)
Q(FileIO)
Q(mkdisk)
Q(enable_wdt)
Q(kick_wdt)
Q(enable_heartbeat)
Q(disable_heartbeat)
Q(enable)
Q(disable)
// Entries for sys.path
Q(/SFLASH)
Q(/SFLASH/LIB)
@ -105,8 +103,6 @@ Q(pin)
Q(mode)
Q(pull)
Q(callback)
Q(enable)
Q(disable)
Q(swint)
Q(IRQ_RISING)
Q(IRQ_FALLING)
@ -159,13 +155,9 @@ Q(SLAVE)
// for ADC class
Q(ADC)
Q(read)
Q(enable)
Q(disable)
// for SD class
Q(SD)
Q(enable)
Q(disable)
// for RTC class
Q(RTC)
@ -250,3 +242,11 @@ Q(LOW_LATENCY_PM)
Q(LOW_POWER_PM)
Q(ALWAYS_ON_PM)
Q(LONG_SLEEP_PM)
// for WDT class
Q(WDT)
Q(kick)
// for HeartBeat class
Q(HeartBeat)