Skip to content

Commit 9d33d90

Browse files
Remove FreeRTOS wrapper functions
1 parent f943d2e commit 9d33d90

File tree

6 files changed

+47
-124
lines changed

6 files changed

+47
-124
lines changed

cores/rp2040/CoreMutex.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ CoreMutex::CoreMutex(mutex_t *mutex, uint8_t option) {
3232
_pxHigherPriorityTaskWoken = 0; // pdFALSE
3333
auto m = __get_freertos_mutex_for_ptr(mutex);
3434

35-
if (__freertos_check_if_in_isr()) {
36-
if (!__freertos_mutex_take_from_isr(m, &_pxHigherPriorityTaskWoken)) {
35+
if (portCHECK_IF_IN_ISR()) {
36+
if (!xSemaphoreTakeFromISR(m, &_pxHigherPriorityTaskWoken)) {
3737
return;
3838
}
3939
// At this point we have the mutex in ISR
4040
} else {
4141
// Grab the mutex normally, possibly waking other tasks to get it
42-
__freertos_mutex_take(m);
42+
xSemaphoreTake(m, portMAX_DELAY);
4343
}
4444
#else
4545
uint32_t owner;
@@ -60,10 +60,11 @@ CoreMutex::~CoreMutex() {
6060
if (_acquired) {
6161
#ifdef __FREERTOS
6262
auto m = __get_freertos_mutex_for_ptr(_mutex);
63-
if (__freertos_check_if_in_isr()) {
64-
__freertos_mutex_give_from_isr(m, &_pxHigherPriorityTaskWoken);
63+
if (portCHECK_IF_IN_ISR()) {
64+
xSemaphoreGiveFromISR(m, &_pxHigherPriorityTaskWoken);
65+
portYIELD_FROM_ISR(_pxHigherPriorityTaskWoken);
6566
} else {
66-
__freertos_mutex_give(m);
67+
xSemaphoreGive(m);
6768
}
6869
#else
6970
mutex_exit(_mutex);

cores/rp2040/_freertos.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ SemaphoreHandle_t __get_freertos_mutex_for_ptr(mutex_t *m, bool recursive) {
4747
// Make a new mutex
4848
SemaphoreHandle_t fm;
4949
if (recursive) {
50-
fm = _freertos_recursive_mutex_create();
50+
fm = xSemaphoreCreateRecursiveMutex();
5151
} else {
52-
fm = __freertos_mutex_create();
52+
fm = xSemaphoreCreateMutex();
5353
}
5454
if (fm == nullptr) {
5555
return nullptr;

cores/rp2040/_freertos.h

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,29 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21-
#ifdef __FREERTOS
22-
2321
#pragma once
24-
#include <pico/mutex.h>
25-
26-
// Cannot include refs to FreeRTOS's actual semaphore calls because they
27-
// are implemented as macros, so we have a wrapper in our variant hook
28-
// to handle it.
29-
30-
// FreeRTOS has been set up
31-
extern volatile bool __freeRTOSinitted;
3222

23+
#ifdef __FREERTOS
3324
#ifdef __cplusplus
3425
extern "C" {
3526
#endif // __cplusplus
36-
struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
37-
typedef struct QueueDefinition * QueueHandle_t;
38-
typedef QueueHandle_t SemaphoreHandle_t;
39-
typedef int32_t BaseType_t;
4027

41-
extern bool __freertos_check_if_in_isr() __attribute__((weak));
28+
#include <FreeRTOS.h>
29+
#include "semphr.h"
30+
#include "task.h"
4231

43-
extern SemaphoreHandle_t __freertos_mutex_create() __attribute__((weak));
44-
extern SemaphoreHandle_t _freertos_recursive_mutex_create() __attribute__((weak));
45-
46-
extern void __freertos_mutex_take(SemaphoreHandle_t mtx) __attribute__((weak));
47-
48-
extern int __freertos_mutex_take_from_isr(SemaphoreHandle_t mtx, BaseType_t* pxHigherPriorityTaskWoken) __attribute__((weak));
49-
extern int __freertos_mutex_try_take(SemaphoreHandle_t mtx) __attribute__((weak));
50-
extern void __freertos_mutex_give(SemaphoreHandle_t mtx) __attribute__((weak));
51-
extern void __freertos_mutex_give_from_isr(SemaphoreHandle_t mtx, BaseType_t* pxHigherPriorityTaskWoken) __attribute__((weak));
32+
#include <pico/mutex.h>
5233

53-
extern void __freertos_recursive_mutex_take(SemaphoreHandle_t mtx) __attribute__((weak));
54-
extern int __freertos_recursive_mutex_try_take(SemaphoreHandle_t mtx) __attribute__((weak));
55-
extern void __freertos_recursive_mutex_give(SemaphoreHandle_t mtx) __attribute__((weak));
34+
// FreeRTOS has been set up
35+
extern volatile bool __freeRTOSinitted;
5636

5737
extern void __freertos_idle_other_core() __attribute__((weak));
5838
extern void __freertos_resume_other_core() __attribute__((weak));
5939

60-
extern void __freertos_task_exit_critical() __attribute__((weak));
61-
extern void __freertos_task_enter_critical() __attribute__((weak));
40+
extern SemaphoreHandle_t __get_freertos_mutex_for_ptr(mutex_t *m, bool recursive = false);
41+
6242
#ifdef __cplusplus
6343
}
64-
extern SemaphoreHandle_t __get_freertos_mutex_for_ptr(mutex_t *m, bool recursive = false);
6544
#endif // __cplusplus
6645

6746
#endif // __FREERTOS

cores/rp2040/freertos/variantHooks.cpp

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -46,75 +46,6 @@
4646
#include <lwip_wrap.h>
4747
#include "freertos-lwip.h"
4848

49-
// Interfaces for the main core to use FreeRTOS mutexes
50-
extern "C" {
51-
extern volatile bool __otherCoreIdled;
52-
static UBaseType_t __savedIrqs[configNUMBER_OF_CORES];
53-
54-
SemaphoreHandle_t __freertos_mutex_create() {
55-
return xSemaphoreCreateMutex();
56-
}
57-
58-
SemaphoreHandle_t _freertos_recursive_mutex_create() {
59-
return xSemaphoreCreateRecursiveMutex();
60-
}
61-
62-
void __freertos_mutex_take(SemaphoreHandle_t mtx) {
63-
xSemaphoreTake(mtx, portMAX_DELAY);
64-
}
65-
66-
int __freertos_mutex_take_from_isr(SemaphoreHandle_t mtx, BaseType_t* pxHigherPriorityTaskWoken) {
67-
return xSemaphoreTakeFromISR(mtx, pxHigherPriorityTaskWoken);
68-
}
69-
70-
int __freertos_mutex_try_take(SemaphoreHandle_t mtx) {
71-
return xSemaphoreTake(mtx, 0);
72-
}
73-
74-
void __freertos_mutex_give(SemaphoreHandle_t mtx) {
75-
xSemaphoreGive(mtx);
76-
}
77-
78-
void __freertos_mutex_give_from_isr(SemaphoreHandle_t mtx, BaseType_t* pxHigherPriorityTaskWoken) {
79-
BaseType_t hiPrio = pxHigherPriorityTaskWoken ? *pxHigherPriorityTaskWoken : pdFALSE;
80-
xSemaphoreGiveFromISR(mtx, &hiPrio);
81-
portYIELD_FROM_ISR(hiPrio);
82-
}
83-
84-
void __freertos_recursive_mutex_take(SemaphoreHandle_t mtx) {
85-
xSemaphoreTakeRecursive(mtx, portMAX_DELAY);
86-
}
87-
88-
int __freertos_recursive_mutex_try_take(SemaphoreHandle_t mtx) {
89-
return xSemaphoreTakeRecursive(mtx, 0);
90-
}
91-
92-
void __freertos_recursive_mutex_give(SemaphoreHandle_t mtx) {
93-
xSemaphoreGiveRecursive(mtx);
94-
}
95-
96-
bool __freertos_check_if_in_isr() {
97-
return portCHECK_IF_IN_ISR();
98-
}
99-
100-
void __freertos_task_exit_critical() {
101-
if (portGET_CRITICAL_NESTING_COUNT() == 1U && portCHECK_IF_IN_ISR()) {
102-
taskEXIT_CRITICAL_FROM_ISR(__savedIrqs[portGET_CORE_ID()]);
103-
} else {
104-
taskEXIT_CRITICAL();
105-
}
106-
}
107-
108-
void __freertos_task_enter_critical() {
109-
if (portGET_CRITICAL_NESTING_COUNT() == 0U && portCHECK_IF_IN_ISR()) {
110-
__savedIrqs[portGET_CORE_ID()] = taskENTER_CRITICAL_FROM_ISR();
111-
} else {
112-
taskENTER_CRITICAL();
113-
}
114-
}
115-
}
116-
117-
11849
/*-----------------------------------------------------------*/
11950

12051
extern void __initFreeRTOSMutexes();

cores/rp2040/lock.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ SemaphoreHandle_t __lock___dd_hash_mutex_freertos;
6060
SemaphoreHandle_t __lock___arc4random_mutex_freertos;
6161

6262
void __initFreeRTOSMutexes() {
63-
__lock___sinit_recursive_mutex_freertos = _freertos_recursive_mutex_create();
64-
__lock___sfp_recursive_mutex_freertos = _freertos_recursive_mutex_create();
65-
__lock___atexit_recursive_mutex_freertos = _freertos_recursive_mutex_create();
66-
__lock___at_quick_exit_mutex_freertos = __freertos_mutex_create();
67-
__lock___malloc_recursive_mutex_freertos = _freertos_recursive_mutex_create();
68-
__lock___env_recursive_mutex_freertos = _freertos_recursive_mutex_create();
69-
__lock___tz_mutex_freertos = __freertos_mutex_create();
70-
__lock___dd_hash_mutex_freertos = __freertos_mutex_create();
71-
__lock___arc4random_mutex_freertos = __freertos_mutex_create();
63+
__lock___sinit_recursive_mutex_freertos = xSemaphoreCreateRecursiveMutex();
64+
__lock___sfp_recursive_mutex_freertos = xSemaphoreCreateRecursiveMutex();
65+
__lock___atexit_recursive_mutex_freertos = xSemaphoreCreateRecursiveMutex();
66+
__lock___at_quick_exit_mutex_freertos = xSemaphoreCreateMutex();
67+
__lock___malloc_recursive_mutex_freertos = xSemaphoreCreateRecursiveMutex();
68+
__lock___env_recursive_mutex_freertos = xSemaphoreCreateRecursiveMutex();
69+
__lock___tz_mutex_freertos = xSemaphoreCreateMutex();
70+
__lock___dd_hash_mutex_freertos = xSemaphoreCreateMutex();
71+
__lock___arc4random_mutex_freertos = xSemaphoreCreateMutex();
7272
}
7373

7474
static SemaphoreHandle_t __getFreeRTOSMutex(_LOCK_T lock) {
@@ -150,7 +150,7 @@ void __retarget_lock_acquire(_LOCK_T lock) {
150150
#ifdef __FREERTOS
151151
if (__freeRTOSinitted) {
152152
auto mtx = __getFreeRTOSMutex(lock);
153-
__freertos_mutex_take(mtx);
153+
xSemaphoreTake(mtx, portMAX_DELAY);
154154
} else {
155155
mutex_enter_blocking((mutex_t*)lock);
156156
}
@@ -163,7 +163,7 @@ void __retarget_lock_acquire_recursive(_LOCK_T lock) {
163163
#ifdef __FREERTOS
164164
if (__freeRTOSinitted) {
165165
auto mtx = __getFreeRTOSRecursiveMutex(lock);
166-
__freertos_recursive_mutex_take(mtx);
166+
xSemaphoreTakeRecursive(mtx, portMAX_DELAY);
167167
} else {
168168
recursive_mutex_enter_blocking((recursive_mutex_t*)lock);
169169
}
@@ -177,7 +177,7 @@ int __retarget_lock_try_acquire(_LOCK_T lock) {
177177
#ifdef __FREERTOS
178178
if (__freeRTOSinitted) {
179179
auto mtx = __getFreeRTOSMutex(lock);
180-
ret = __freertos_mutex_try_take(mtx);
180+
ret = xSemaphoreTake(mtx, 0);
181181
} else {
182182
ret = mutex_try_enter((mutex_t *)lock, nullptr);
183183
}
@@ -192,7 +192,7 @@ int __retarget_lock_try_acquire_recursive(_LOCK_T lock) {
192192
#ifdef __FREERTOS
193193
if (__freeRTOSinitted) {
194194
auto mtx = __getFreeRTOSRecursiveMutex(lock);
195-
ret = __freertos_recursive_mutex_try_take(mtx);
195+
ret = xSemaphoreTakeRecursive(mtx, 0);
196196
} else {
197197
ret = recursive_mutex_try_enter((recursive_mutex_t*)lock, nullptr);
198198
}
@@ -206,7 +206,7 @@ void __retarget_lock_release(_LOCK_T lock) {
206206
#ifdef __FREERTOS
207207
if (__freeRTOSinitted) {
208208
auto mtx = __getFreeRTOSMutex(lock);
209-
__freertos_mutex_give(mtx);
209+
xSemaphoreGive(mtx);
210210
} else {
211211
mutex_exit((mutex_t*)lock);
212212
}
@@ -219,7 +219,7 @@ void __retarget_lock_release_recursive(_LOCK_T lock) {
219219
#ifdef __FREERTOS
220220
if (__freeRTOSinitted) {
221221
auto mtx = __getFreeRTOSRecursiveMutex(lock);
222-
__freertos_recursive_mutex_give(mtx);
222+
xSemaphoreGiveRecursive(mtx);
223223
} else {
224224
recursive_mutex_exit((recursive_mutex_t*)lock);
225225
}

cores/rp2040/wiring_private.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,18 @@
3232
static uint32_t _irqStackTop[2] = { 0, 0 };
3333
static uint32_t _irqStack[2][maxIRQs];
3434

35+
#ifdef __FREERTOS
36+
static UBaseType_t __savedIrqs[configNUMBER_OF_CORES];
37+
#endif
38+
3539
extern "C" void interrupts() {
3640
#ifdef __FREERTOS
3741
if (__freeRTOSinitted) {
38-
__freertos_task_exit_critical();
42+
if (portGET_CRITICAL_NESTING_COUNT() == 1U && portCHECK_IF_IN_ISR()) {
43+
taskEXIT_CRITICAL_FROM_ISR(__savedIrqs[portGET_CORE_ID()]);
44+
} else {
45+
taskEXIT_CRITICAL();
46+
}
3947
return;
4048
}
4149
#endif
@@ -50,7 +58,11 @@ extern "C" void interrupts() {
5058
extern "C" void noInterrupts() {
5159
#ifdef __FREERTOS
5260
if (__freeRTOSinitted) {
53-
__freertos_task_enter_critical();
61+
if (portGET_CRITICAL_NESTING_COUNT() == 0U && portCHECK_IF_IN_ISR()) {
62+
__savedIrqs[portGET_CORE_ID()] = taskENTER_CRITICAL_FROM_ISR();
63+
} else {
64+
taskENTER_CRITICAL();
65+
}
5466
return;
5567
}
5668
#endif

0 commit comments

Comments
 (0)