3030
3131#include " FreeRTOS.h"
3232#include " task.h"
33+ #include " pico/multicore.h"
34+ #include " hardware/irq.h"
35+ #include " semphr.h"
3336#include < stdio.h>
3437#include < algorithm>
3538#include " pico/stdio/driver.h"
@@ -140,7 +143,7 @@ static void core0( void *pvParameters )
140143{
141144 for ( ;; )
142145 {
143- if (sem_acquire_timeout_us (& base.receiverSemaphore , portMAX_DELAY))
146+ if (xSemaphoreTake ( base.receiverSemaphore , portMAX_DELAY) == pdTRUE )
144147 {
145148 int wanted, received;
146149 do
@@ -156,6 +159,8 @@ static void core0( void *pvParameters )
156159 if (statistics.printLogs .exchange (false ))
157160 {
158161 statistics.printToSerial (base.processDataHandle , base.processSerialHandle );
162+ stdio_flush ();
163+ vTaskDelay (pdMS_TO_TICKS (2 ));
159164 }
160165
161166 sem_release (&base.serialSemaphore );
@@ -165,7 +170,16 @@ static void core0( void *pvParameters )
165170
166171static void serialEvent (void *)
167172{
168- sem_release (&base.receiverSemaphore );
173+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
174+ xSemaphoreGiveFromISR (base.receiverSemaphore , &xHigherPriorityTaskWoken);
175+ portYIELD_FROM_ISR (xHigherPriorityTaskWoken);
176+ }
177+
178+ void on_fifo_irq ()
179+ {
180+ multicore_fifo_drain ();
181+
182+ serialEvent (nullptr );
169183}
170184
171185int main (void )
@@ -174,7 +188,11 @@ int main(void)
174188
175189 sem_init (&base.serialSemaphore , 0 , 1 );
176190
177- sem_init (&base.receiverSemaphore , 0 , 1 );
191+ base.receiverSemaphore = xSemaphoreCreateBinary ();
192+
193+ multicore_fifo_clear_irq ();
194+ irq_set_exclusive_handler (SIO_IRQ_FIFO, on_fifo_irq);
195+ irq_set_enabled (SIO_IRQ_FIFO, true );
178196
179197 multicore_launch_core1 (core1);
180198
0 commit comments