Skip to content

Commit 9c217b1

Browse files
authored
FreeRTOS: Add ISR check to critical section (earlephilhower#2559)
1 parent d96c0e6 commit 9c217b1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

libraries/FreeRTOS/src/variantHooks.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
// Interfaces for the main core to use FreeRTOS mutexes
4646
extern "C" {
4747
extern volatile bool __otherCoreIdled;
48+
static UBaseType_t __savedIrqs[configNUMBER_OF_CORES];
4849

4950
SemaphoreHandle_t __freertos_mutex_create() {
5051
return xSemaphoreCreateMutex();
@@ -93,11 +94,19 @@ extern "C" {
9394
}
9495

9596
void __freertos_task_exit_critical() {
96-
taskEXIT_CRITICAL();
97+
if (portGET_CRITICAL_NESTING_COUNT() == 1U && portCHECK_IF_IN_ISR()) {
98+
taskEXIT_CRITICAL_FROM_ISR(__savedIrqs[portGET_CORE_ID()]);
99+
} else {
100+
taskEXIT_CRITICAL();
101+
}
97102
}
98103

99104
void __freertos_task_enter_critical() {
100-
taskENTER_CRITICAL();
105+
if (portGET_CRITICAL_NESTING_COUNT() == 0U && portCHECK_IF_IN_ISR()) {
106+
__savedIrqs[portGET_CORE_ID()] = taskENTER_CRITICAL_FROM_ISR();
107+
} else {
108+
taskENTER_CRITICAL();
109+
}
101110
}
102111
}
103112

0 commit comments

Comments
 (0)