From d01060241a2102878a2b6ff270323e7d278f0af8 Mon Sep 17 00:00:00 2001 From: danicampora Date: Thu, 26 Feb 2015 15:03:52 +0100 Subject: cc3200: Add heartbeat signal on system led. --- cc3200/misc/FreeRTOSHooks.c | 4 +++- cc3200/misc/mperror.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ cc3200/misc/mperror.h | 4 ++++ 3 files changed, 54 insertions(+), 1 deletion(-) (limited to 'cc3200/misc') diff --git a/cc3200/misc/FreeRTOSHooks.c b/cc3200/misc/FreeRTOSHooks.c index 9383000b0..260cd84e0 100644 --- a/cc3200/misc/FreeRTOSHooks.c +++ b/cc3200/misc/FreeRTOSHooks.c @@ -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(); } diff --git a/cc3200/misc/mperror.c b/cc3200/misc/mperror.c index bfb17a2b4..bff581279 100644 --- a/cc3200/misc/mperror.c +++ b/cc3200/misc/mperror.c @@ -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) { diff --git a/cc3200/misc/mperror.h b/cc3200/misc/mperror.h index 827d00a9f..17a6d8833 100644 --- a/cc3200/misc/mperror.h +++ b/cc3200/misc/mperror.h @@ -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_ -- cgit v1.2.3