Skip to content

Commit 80517c4

Browse files
committed
First try at critical section support
1 parent 49090d1 commit 80517c4

File tree

1 file changed

+8
-1
lines changed
  • ports/esp32s2/common-hal/microcontroller

1 file changed

+8
-1
lines changed

ports/esp32s2/common-hal/microcontroller/__init__.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,31 @@
3939
#include "supervisor/filesystem.h"
4040
#include "supervisor/shared/safe_mode.h"
4141

42+
#include "freertos/FreeRTOS.h"
43+
4244
void common_hal_mcu_delay_us(uint32_t delay) {
4345

4446
}
4547

4648
volatile uint32_t nesting_count = 0;
49+
static portMUX_TYPE cp_mutex = portMUX_INITIALIZER_UNLOCKED;
4750

4851
void common_hal_mcu_disable_interrupts(void) {
52+
if (nesting_count == 0) {
53+
portENTER_CRITICAL(&cp_mutex);
54+
}
4955
nesting_count++;
5056
}
5157

5258
void common_hal_mcu_enable_interrupts(void) {
5359
if (nesting_count == 0) {
54-
60+
// Maybe log here because it's very bad.
5561
}
5662
nesting_count--;
5763
if (nesting_count > 0) {
5864
return;
5965
}
66+
portEXIT_CRITICAL(&cp_mutex);
6067
}
6168

6269
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {

0 commit comments

Comments
 (0)