From 90d7c4ef3d82b49832168426d2e245db0d8a042f Mon Sep 17 00:00:00 2001 From: Daniel Campora Date: Sun, 24 May 2015 15:06:50 +0200 Subject: [PATCH] cc3200: Make HeartBeat.disable() thread safe. --- cc3200/misc/mperror.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cc3200/misc/mperror.c b/cc3200/misc/mperror.c index 3927b21220..7f5964daff 100644 --- a/cc3200/misc/mperror.c +++ b/cc3200/misc/mperror.c @@ -68,7 +68,8 @@ struct mperror_heart_beat { uint32_t on_time; bool beating; bool enabled; -} mperror_heart_beat = {.off_time = 0, .on_time = 0, .beating = false, .enabled = false}; + bool do_disable; +} mperror_heart_beat = {.off_time = 0, .on_time = 0, .beating = false, .enabled = false, .do_disable = false}; /****************************************************************************** DEFINE PUBLIC FUNCTIONS @@ -142,12 +143,16 @@ void mperror_heartbeat_switch_off (void) { } void mperror_disable_heartbeat (void) { - mperror_heart_beat.enabled = false; - mperror_heartbeat_switch_off(); + mperror_heart_beat.do_disable = true; } void mperror_heartbeat_signal (void) { - if (mperror_heart_beat.enabled) { + if (mperror_heart_beat.do_disable) { + mperror_heart_beat.enabled = false; + mperror_heart_beat.do_disable = false; + mperror_heartbeat_switch_off(); + } + else if (mperror_heart_beat.enabled) { if (!mperror_heart_beat.beating) { if ((mperror_heart_beat.on_time = HAL_GetTick()) - mperror_heart_beat.off_time > MPERROR_HEARTBEAT_OFF_MS) { MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, MICROPY_SYS_LED_PORT_PIN);