Skip to content

Commit f9ba639

Browse files
authored
Freertosrp2350: use FreeRTOS macros in noInterrupts/interrupts when applicable. (#2456)
* Use FreeRTOS macros in noInterrupts/interrupts when applicable. * Fixed calling taskEXIT_CRITICAL and taskENTER_CRITICAL
1 parent 64adae9 commit f9ba639

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

cores/rp2040/_freertos.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ extern "C" {
5454

5555
extern void __freertos_idle_other_core() __attribute__((weak));
5656
extern void __freertos_resume_other_core() __attribute__((weak));
57+
58+
extern void __freertos_task_exit_critical() __attribute__((weak));
59+
extern void __freertos_task_enter_critical() __attribute__((weak));
5760
}
5861
extern SemaphoreHandle_t __get_freertos_mutex_for_ptr(mutex_t *m, bool recursive = false);

cores/rp2040/wiring_private.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <hardware/gpio.h>
2424
#include <hardware/sync.h>
2525
#include <map>
26+
#include "_freertos.h"
27+
2628

2729
// Support nested IRQ disable/re-enable
2830
#ifndef maxIRQs
@@ -32,22 +34,29 @@ static uint32_t _irqStackTop[2] = { 0, 0 };
3234
static uint32_t _irqStack[2][maxIRQs];
3335

3436
extern "C" void interrupts() {
35-
auto core = get_core_num();
36-
if (!_irqStackTop[core]) {
37-
// ERROR
38-
return;
37+
if (__freeRTOSinitted) {
38+
__freertos_task_exit_critical();
39+
} else {
40+
auto core = get_core_num();
41+
if (!_irqStackTop[core]) {
42+
// ERROR
43+
return;
44+
}
45+
restore_interrupts(_irqStack[core][--_irqStackTop[core]]);
3946
}
40-
restore_interrupts(_irqStack[core][--_irqStackTop[core]]);
4147
}
4248

4349
extern "C" void noInterrupts() {
44-
auto core = get_core_num();
45-
if (_irqStackTop[core] == maxIRQs) {
46-
// ERROR
47-
panic("IRQ stack overflow");
50+
if (__freeRTOSinitted) {
51+
__freertos_task_enter_critical();
52+
} else {
53+
auto core = get_core_num();
54+
if (_irqStackTop[core] == maxIRQs) {
55+
// ERROR
56+
panic("IRQ stack overflow");
57+
}
58+
_irqStack[core][_irqStackTop[core]++] = save_and_disable_interrupts();
4859
}
49-
50-
_irqStack[core][_irqStackTop[core]++] = save_and_disable_interrupts();
5160
}
5261

5362
// Only 1 GPIO IRQ callback for all pins, so we need to look at the pin it's for and

libraries/FreeRTOS/src/variantHooks.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ extern "C" {
9191
bool __freertos_check_if_in_isr() {
9292
return portCHECK_IF_IN_ISR();
9393
}
94+
95+
void __freertos_task_exit_critical() {
96+
taskEXIT_CRITICAL();
97+
}
98+
99+
void __freertos_task_enter_critical() {
100+
taskENTER_CRITICAL();
101+
}
94102
}
95103

96104

0 commit comments

Comments
 (0)