summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authordanicampora <danicampora@gmail.com>2015-02-26 15:03:52 +0100
committerdanicampora <danicampora@gmail.com>2015-02-28 19:03:21 +0100
commitd01060241a2102878a2b6ff270323e7d278f0af8 (patch)
tree08ab66e810ac650cc990f3413f3d1f9f035bacd9
parent6a41bf99bdd2e19d6922864bf6845a91b3ab6b99 (diff)
downloadmicropython-d01060241a2102878a2b6ff270323e7d278f0af8.tar.gz
micropython-d01060241a2102878a2b6ff270323e7d278f0af8.zip
cc3200: Add heartbeat signal on system led.
-rw-r--r--cc3200/main.c1
-rw-r--r--cc3200/misc/FreeRTOSHooks.c4
-rw-r--r--cc3200/misc/mperror.c47
-rw-r--r--cc3200/misc/mperror.h4
-rw-r--r--cc3200/mods/modpyb.c19
-rw-r--r--cc3200/mptask.c4
-rw-r--r--cc3200/qstrdefsport.h2
7 files changed, 79 insertions, 2 deletions
diff --git a/cc3200/main.c b/cc3200/main.c
index 24a42c5247..d65fc240fc 100644
--- a/cc3200/main.c
+++ b/cc3200/main.c
@@ -34,6 +34,7 @@
#include "simplelink.h"
#include "pybwdt.h"
#include "debug.h"
+#include "mperror.h"
/******************************************************************************
DECLARE PRIVATE CONSTANTS
diff --git a/cc3200/misc/FreeRTOSHooks.c b/cc3200/misc/FreeRTOSHooks.c
index 9383000b0e..260cd84e07 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 bfb17a2b41..bff5812794 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 827d00a9f0..17a6d88333 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_
diff --git a/cc3200/mods/modpyb.c b/cc3200/mods/modpyb.c
index 5c1a4c0e22..bca114a38f 100644
--- a/cc3200/mods/modpyb.c
+++ b/cc3200/mods/modpyb.c
@@ -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 },
diff --git a/cc3200/mptask.c b/cc3200/mptask.c
index f97c07b50f..f760b641d8 100644
--- a/cc3200/mptask.c
+++ b/cc3200/mptask.c
@@ -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
diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h
index 3ab9fdb379..2eec328bb0 100644
--- a/cc3200/qstrdefsport.h
+++ b/cc3200/qstrdefsport.h
@@ -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)