Skip to content

Commit d18ced9

Browse files
author
Daniel Campora
committed
cc3200: Use alternative HAL_Delay also when interrupts are disabled.
1 parent 7463442 commit d18ced9

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

cc3200/hal/cc3200_hal.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "telnet.h"
4747
#include "pybuart.h"
4848
#include "utils.h"
49+
#include "irq.h"
4950

5051
#ifdef USE_FREERTOS
5152
#include "FreeRTOS.h"
@@ -108,8 +109,8 @@ uint32_t HAL_GetTick(void) {
108109
}
109110

110111
void HAL_Delay(uint32_t delay) {
111-
// only if we are not within interrupt context
112-
if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0) {
112+
// only if we are not within interrupt context and interrupts are enabled
113+
if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) {
113114
#ifdef USE_FREERTOS
114115
vTaskDelay (delay / portTICK_PERIOD_MS);
115116
#else
@@ -121,8 +122,10 @@ void HAL_Delay(uint32_t delay) {
121122
}
122123
#endif
123124
} else {
124-
for (int ms = 1; ms <= delay; ms++) {
125-
UtilsDelay(UTILS_DELAY_US_TO_COUNT(ms * 1000));
125+
for (int ms = 0; ms < delay; ms++) {
126+
// 500 instead of 1000 us to compensate the overhead of the for loop
127+
// and the function call
128+
UtilsDelay(UTILS_DELAY_US_TO_COUNT(500));
126129
}
127130
}
128131
}

cc3200/misc/mpsystick.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "py/mpconfig.h"
2929
#include MICROPY_HAL_H
3030
#include "py/obj.h"
31-
#include "irq.h"
3231
#include "mpsystick.h"
3332
#include "systick.h"
3433
#include "inc/hw_types.h"

cc3200/telnet/telnet.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "mpexception.h"
3939
#include "serverstask.h"
4040
#include "genhdr/mpversion.h"
41+
#include "irq.h"
4142

4243
/******************************************************************************
4344
DEFINE PRIVATE CONSTANTS
@@ -492,8 +493,8 @@ static void telnet_parse_input (uint8_t *str, int16_t *len) {
492493

493494
static bool telnet_send_with_retries (int16_t sd, const void *pBuf, int16_t len) {
494495
int32_t retries = 0;
495-
// abort sending if we happen to be within interrupt context
496-
if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0) {
496+
// only if we are not within interrupt context and interrupts are enabled
497+
if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) {
497498
do {
498499
_i16 result = sl_Send(sd, pBuf, len, 0);
499500
if (result > 0) {

0 commit comments

Comments
 (0)