40
40
#include < pico.h>
41
41
#include < pico/time.h>
42
42
43
- #include " _freertos.h"
43
+ #include < _freertos.h>
44
+
45
+ // Interfaces for the main core to use FreeRTOS mutexes
46
+ extern " C" {
47
+ extern volatile bool __otherCoreIdled;
48
+ int __holdUpPendSV = 0 ; // TOTO - remove from FreeRTOS lib
49
+
50
+ SemaphoreHandle_t __freertos_mutex_create () {
51
+ return xSemaphoreCreateMutex ();
52
+ }
53
+
54
+ SemaphoreHandle_t _freertos_recursive_mutex_create () {
55
+ return xSemaphoreCreateRecursiveMutex ();
56
+ }
57
+
58
+ void __freertos_mutex_take (SemaphoreHandle_t mtx) {
59
+ xSemaphoreTake (mtx, portMAX_DELAY);
60
+ }
61
+
62
+ void __freertos_mutex_take_from_isr (SemaphoreHandle_t mtx) {
63
+ xSemaphoreTakeFromISR (mtx, NULL );
64
+ }
65
+
66
+ int __freertos_mutex_try_take (SemaphoreHandle_t mtx) {
67
+ return xSemaphoreTake (mtx, 0 );
68
+ }
69
+
70
+ void __freertos_mutex_give (SemaphoreHandle_t mtx) {
71
+ xSemaphoreGive (mtx);
72
+ }
73
+
74
+ void __freertos_mutex_give_from_isr (SemaphoreHandle_t mtx) {
75
+ xSemaphoreGiveFromISR (mtx, NULL );
76
+ }
77
+
78
+ void __freertos_recursive_mutex_take (SemaphoreHandle_t mtx) {
79
+ xSemaphoreTakeRecursive (mtx, portMAX_DELAY);
80
+ }
81
+
82
+ int __freertos_recursive_mutex_try_take (SemaphoreHandle_t mtx) {
83
+ return xSemaphoreTakeRecursive (mtx, 0 );
84
+ }
85
+
86
+ void __freertos_recursive_mutex_give (SemaphoreHandle_t mtx) {
87
+ xSemaphoreGiveRecursive (mtx);
88
+ }
89
+ }
90
+
44
91
45
92
/* -----------------------------------------------------------*/
46
93
@@ -108,6 +155,40 @@ extern "C" void yield() {
108
155
taskYIELD ();
109
156
}
110
157
158
+ static TaskHandle_t __idleCoreTask[2 ];
159
+ static void __no_inline_not_in_flash_func (IdleThisCore)(void *param) {
160
+ (void ) param;
161
+ while (true ) {
162
+ ulTaskNotifyTake (pdTRUE, portMAX_DELAY);
163
+ vTaskPreemptionDisable (nullptr );
164
+ portDISABLE_INTERRUPTS ();
165
+ __otherCoreIdled = true ;
166
+ while (__otherCoreIdled) {
167
+ /* noop */
168
+ }
169
+ portENABLE_INTERRUPTS ();
170
+ vTaskPreemptionEnable (nullptr );
171
+ }
172
+ }
173
+
174
+ extern " C" void __no_inline_not_in_flash_func (__freertos_idle_other_core)() {
175
+ vTaskPreemptionDisable (nullptr );
176
+ xTaskNotifyGive (__idleCoreTask[ 1 ^ sio_hw->cpuid ]);
177
+ while (!__otherCoreIdled) {
178
+ /* noop */
179
+ }
180
+ portDISABLE_INTERRUPTS ();
181
+ vTaskSuspendAll ();
182
+ }
183
+
184
+ extern " C" void __no_inline_not_in_flash_func (__freertos_resume_other_core)() {
185
+ __otherCoreIdled = false ;
186
+ portENABLE_INTERRUPTS ();
187
+ xTaskResumeAll ();
188
+ vTaskPreemptionEnable (nullptr );
189
+ }
190
+
191
+
111
192
extern mutex_t __usb_mutex;
112
193
static TaskHandle_t __usbTask;
113
194
static void __usb (void *param);
@@ -124,6 +205,12 @@ void startFreeRTOS(void) {
124
205
vTaskCoreAffinitySet (c1, 1 << 1 );
125
206
}
126
207
208
+ // Create the idle-other-core tasks (for when flash is being written)
209
+ xTaskCreate (IdleThisCore, " IdleCore0" , 128 , 0 , configMAX_PRIORITIES - 1 , __idleCoreTask + 0 );
210
+ vTaskCoreAffinitySet (__idleCoreTask[0 ], 1 << 0 );
211
+ xTaskCreate (IdleThisCore, " IdleCore1" , 128 , 0 , configMAX_PRIORITIES - 1 , __idleCoreTask + 1 );
212
+ vTaskCoreAffinitySet (__idleCoreTask[1 ], 1 << 1 );
213
+
127
214
// Initialise and run the freeRTOS scheduler. Execution should never return here.
128
215
__freeRTOSinitted = true ;
129
216
vTaskStartScheduler ();
@@ -398,54 +485,9 @@ void __USBStart() {
398
485
__SetupDescHIDReport ();
399
486
__SetupUSBDescriptor ();
400
487
401
- // Make highest prio and locked to core 0
402
- xTaskCreate (__usb, " USB" , 256 , 0 , configMAX_PRIORITIES - 1 , &__usbTask);
488
+ // Make high prio and locked to core 0
489
+ xTaskCreate (__usb, " USB" , 256 , 0 , configMAX_PRIORITIES - 2 , &__usbTask);
403
490
vTaskCoreAffinitySet (__usbTask, 1 << 0 );
404
491
}
405
492
406
493
407
- // Interfaces for the main core to use FreeRTOS mutexes
408
- extern " C" {
409
-
410
- SemaphoreHandle_t __freertos_mutex_create () {
411
- return xSemaphoreCreateMutex ();
412
- }
413
-
414
- SemaphoreHandle_t _freertos_recursive_mutex_create () {
415
- return xSemaphoreCreateRecursiveMutex ();
416
- }
417
-
418
- void __freertos_mutex_take (SemaphoreHandle_t mtx) {
419
- xSemaphoreTake (mtx, portMAX_DELAY);
420
- }
421
-
422
- void __freertos_mutex_take_from_isr (SemaphoreHandle_t mtx) {
423
- xSemaphoreTakeFromISR (mtx, NULL );
424
- }
425
-
426
- int __freertos_mutex_try_take (SemaphoreHandle_t mtx) {
427
- return xSemaphoreTake (mtx, 0 );
428
- }
429
-
430
- void __freertos_mutex_give (SemaphoreHandle_t mtx) {
431
- xSemaphoreGive (mtx);
432
- }
433
-
434
- void __freertos_mutex_give_from_isr (SemaphoreHandle_t mtx) {
435
- xSemaphoreGiveFromISR (mtx, NULL );
436
- }
437
-
438
- void __freertos_recursive_mutex_take (SemaphoreHandle_t mtx) {
439
- xSemaphoreTakeRecursive (mtx, portMAX_DELAY);
440
- }
441
-
442
- int __freertos_recursive_mutex_try_take (SemaphoreHandle_t mtx) {
443
- return xSemaphoreTakeRecursive (mtx, 0 );
444
- }
445
-
446
- void __freertos_recursive_mutex_give (SemaphoreHandle_t mtx) {
447
- xSemaphoreGiveRecursive (mtx);
448
- }
449
-
450
- }
451
-
0 commit comments