From d18ced9cddb4123ba793824bf7370a6593c9a3ae Mon Sep 17 00:00:00 2001 From: Daniel Campora Date: Wed, 8 Jul 2015 12:46:47 +0200 Subject: [PATCH] cc3200: Use alternative HAL_Delay also when interrupts are disabled. --- cc3200/hal/cc3200_hal.c | 11 +++++++---- cc3200/misc/mpsystick.c | 1 - cc3200/telnet/telnet.c | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c index 671af3cf9c..afc5fb7241 100644 --- a/cc3200/hal/cc3200_hal.c +++ b/cc3200/hal/cc3200_hal.c @@ -46,6 +46,7 @@ #include "telnet.h" #include "pybuart.h" #include "utils.h" +#include "irq.h" #ifdef USE_FREERTOS #include "FreeRTOS.h" @@ -108,8 +109,8 @@ uint32_t HAL_GetTick(void) { } void HAL_Delay(uint32_t delay) { - // only if we are not within interrupt context - if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0) { + // only if we are not within interrupt context and interrupts are enabled + if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) { #ifdef USE_FREERTOS vTaskDelay (delay / portTICK_PERIOD_MS); #else @@ -121,8 +122,10 @@ void HAL_Delay(uint32_t delay) { } #endif } else { - for (int ms = 1; ms <= delay; ms++) { - UtilsDelay(UTILS_DELAY_US_TO_COUNT(ms * 1000)); + for (int ms = 0; ms < delay; ms++) { + // 500 instead of 1000 us to compensate the overhead of the for loop + // and the function call + UtilsDelay(UTILS_DELAY_US_TO_COUNT(500)); } } } diff --git a/cc3200/misc/mpsystick.c b/cc3200/misc/mpsystick.c index 5eeeae21ea..7e1cff6ff7 100644 --- a/cc3200/misc/mpsystick.c +++ b/cc3200/misc/mpsystick.c @@ -28,7 +28,6 @@ #include "py/mpconfig.h" #include MICROPY_HAL_H #include "py/obj.h" -#include "irq.h" #include "mpsystick.h" #include "systick.h" #include "inc/hw_types.h" diff --git a/cc3200/telnet/telnet.c b/cc3200/telnet/telnet.c index 485ed522cb..3a3b9f1664 100644 --- a/cc3200/telnet/telnet.c +++ b/cc3200/telnet/telnet.c @@ -38,6 +38,7 @@ #include "mpexception.h" #include "serverstask.h" #include "genhdr/mpversion.h" +#include "irq.h" /****************************************************************************** DEFINE PRIVATE CONSTANTS @@ -492,8 +493,8 @@ static void telnet_parse_input (uint8_t *str, int16_t *len) { static bool telnet_send_with_retries (int16_t sd, const void *pBuf, int16_t len) { int32_t retries = 0; - // abort sending if we happen to be within interrupt context - if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0) { + // only if we are not within interrupt context and interrupts are enabled + if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) { do { _i16 result = sl_Send(sd, pBuf, len, 0); if (result > 0) {