File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
110111void 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}
Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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
493494static 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 ) {
You can’t perform that action at this time.
0 commit comments