aboutsummaryrefslogtreecommitdiff
path: root/cc3200/hal
diff options
context:
space:
mode:
authorDaniel Campora2015-07-05 22:26:12 +0200
committerDaniel Campora2015-07-07 16:11:05 +0200
commitfa655ce196ad82e3b8664dcd0ba78328ecaa9a58 (patch)
tree9ff312814008236e29f8d141f8416b324c4707b5 /cc3200/hal
parent194c8c761e853cb200d5aab885b6d62ec87cf4b2 (diff)
cc3200: Improve interrupt handling and fix bug in HAL_Delay().
Diffstat (limited to 'cc3200/hal')
-rw-r--r--cc3200/hal/cc3200_hal.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c
index 386064116..671af3cf9 100644
--- a/cc3200/hal/cc3200_hal.c
+++ b/cc3200/hal/cc3200_hal.c
@@ -45,6 +45,7 @@
#include "mpexception.h"
#include "telnet.h"
#include "pybuart.h"
+#include "utils.h"
#ifdef USE_FREERTOS
#include "FreeRTOS.h"
@@ -107,16 +108,23 @@ uint32_t HAL_GetTick(void) {
}
void HAL_Delay(uint32_t delay) {
-#ifdef USE_FREERTOS
- vTaskDelay (delay / portTICK_PERIOD_MS);
-#else
- uint32_t start = HAL_tickCount;
- // Wraparound of tick is taken care of by 2's complement arithmetic.
- while (HAL_tickCount - start < delay) {
- // Enter sleep mode, waiting for (at least) the SysTick interrupt.
- __WFI();
+ // only if we are not within interrupt context
+ if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0) {
+ #ifdef USE_FREERTOS
+ vTaskDelay (delay / portTICK_PERIOD_MS);
+ #else
+ uint32_t start = HAL_tickCount;
+ // wraparound of tick is taken care of by 2's complement arithmetic.
+ while (HAL_tickCount - start < delay) {
+ // enter sleep mode, waiting for (at least) the SysTick interrupt.
+ __WFI();
+ }
+ #endif
+ } else {
+ for (int ms = 1; ms <= delay; ms++) {
+ UtilsDelay(UTILS_DELAY_US_TO_COUNT(ms * 1000));
+ }
}
-#endif
}
void mp_hal_set_interrupt_char (int c) {