Commit d0106024 authored by danicampora's avatar danicampora
Browse files

cc3200: Add heartbeat signal on system led.

parent 6a41bf99
......@@ -34,6 +34,7 @@
#include "simplelink.h"
#include "pybwdt.h"
#include "debug.h"
#include "mperror.h"
/******************************************************************************
DECLARE PRIVATE CONSTANTS
......
......@@ -51,7 +51,9 @@ void vApplicationIdleHook (void)
{
// kick the watchdog
pybwdt_kick();
// gate the processor clock to save power
// signal that we are alive and kicking
mperror_heartbeat_signal();
// gate the processor's clock to save power
__WFI();
}
......
......@@ -45,14 +45,27 @@
#include "prcm.h"
#include "pybuart.h"
#include "utils.h"
#include "mperror.h"
/******************************************************************************
DEFINE CONSTANTS
******************************************************************************/
#define MPERROR_TOOGLE_MS (200)
#define MPERROR_SIGNAL_ERROR_MS (2000)
#define MPERROR_HEARTBEAT_ON_MS (80)
#define MPERROR_HEARTBEAT_OFF_MS (2920)
#define MPERROR_SAFE_BOOT_REG_IDX (0)
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
static bool mperror_heartbeat_enabled;
/******************************************************************************
DEFINE PUBLIC FUNCTIONS
******************************************************************************/
void mperror_init0 (void) {
// Enable SYS GPIOs peripheral clocks
MAP_PRCMPeripheralClkEnable(MICROPY_SYS_LED_PRCM, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
......@@ -102,6 +115,40 @@ bool mperror_safe_boot_requested (void) {
return ret;
}
void mperror_enable_heartbeat (void) {
mperror_heartbeat_enabled = true;
}
void mperror_disable_heartbeat (void) {
mperror_heartbeat_enabled = false;
mperror_heartbeat_off();
}
void mperror_heartbeat_signal (void) {
static uint off_start = 0;
static uint on_start = 0;
static bool beat = false;
if (mperror_heartbeat_enabled) {
if (!beat) {
if ((on_start = HAL_GetTick()) - off_start > MPERROR_HEARTBEAT_OFF_MS) {
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, MICROPY_SYS_LED_PORT_PIN);
beat = true;
}
}
else {
if ((off_start = HAL_GetTick()) - on_start > MPERROR_HEARTBEAT_ON_MS) {
mperror_heartbeat_off();
beat = false;
}
}
}
}
void mperror_heartbeat_off (void) {
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0);
}
void NORETURN __fatal_error(const char *msg) {
#ifdef DEBUG
if (msg != NULL) {
......
......@@ -36,5 +36,9 @@ void mperror_signal_error (void);
void mperror_request_safe_boot (void);
void mperror_clear_safe_boot (void);
bool mperror_safe_boot_requested (void);
void mperror_enable_heartbeat (void);
void mperror_disable_heartbeat (void);
void mperror_heartbeat_signal (void);
void mperror_heartbeat_off (void);
#endif // MPERROR_H_
......@@ -61,6 +61,7 @@
#include "pybwdt.h"
#include "utils.h"
#include "gccollect.h"
#include "mperror.h"
#ifdef DEBUG
......@@ -294,6 +295,22 @@ STATIC mp_obj_t pyb_kick_wdt(void) {
}
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[] = {
......@@ -327,6 +344,8 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ 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 },
......
......@@ -104,7 +104,6 @@ void TASK_Micropython (void *pvParameters) {
#endif
#ifdef DEBUG
mperror_init0();
safeboot = false;
#else
safeboot = mperror_safe_boot_requested();
......@@ -140,6 +139,7 @@ soft_reset:
mp_obj_list_init(mp_sys_argv, 0);
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
mperror_init0();
mpexception_init0();
uart_init0();
pin_init0();
......@@ -163,6 +163,8 @@ soft_reset:
rng_init0();
#endif
mperror_enable_heartbeat();
main_enter_ap_mode();
// enable telnet and ftp servers
......
......@@ -38,6 +38,8 @@ Q(FileIO)
Q(mkdisk)
Q(enable_wdt)
Q(kick_wdt)
Q(enable_heartbeat)
Q(disable_heartbeat)
// Entries for sys.path
Q(/SFLASH)
Q(/SFLASH/LIB)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment