First try at critical section support

This commit is contained in:
Scott Shawcroft 2020-05-19 17:49:17 -07:00
parent 49090d1378
commit 80517c4cf6
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
1 changed files with 8 additions and 1 deletions

View File

@ -39,24 +39,31 @@
#include "supervisor/filesystem.h" #include "supervisor/filesystem.h"
#include "supervisor/shared/safe_mode.h" #include "supervisor/shared/safe_mode.h"
#include "freertos/FreeRTOS.h"
void common_hal_mcu_delay_us(uint32_t delay) { void common_hal_mcu_delay_us(uint32_t delay) {
} }
volatile uint32_t nesting_count = 0; volatile uint32_t nesting_count = 0;
static portMUX_TYPE cp_mutex = portMUX_INITIALIZER_UNLOCKED;
void common_hal_mcu_disable_interrupts(void) { void common_hal_mcu_disable_interrupts(void) {
if (nesting_count == 0) {
portENTER_CRITICAL(&cp_mutex);
}
nesting_count++; nesting_count++;
} }
void common_hal_mcu_enable_interrupts(void) { void common_hal_mcu_enable_interrupts(void) {
if (nesting_count == 0) { if (nesting_count == 0) {
// Maybe log here because it's very bad.
} }
nesting_count--; nesting_count--;
if (nesting_count > 0) { if (nesting_count > 0) {
return; return;
} }
portEXIT_CRITICAL(&cp_mutex);
} }
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {