16
16
* limitations under the License.
17
17
*/
18
18
#include " AppConfig.h"
19
- #include " FreeRTOS.h"
20
- #include " event_groups.h"
21
19
#include " matter_shell.h"
22
- #include " semphr.h "
23
- #include " task.h "
20
+ #include < cmsis_os2.h >
21
+ #include < sl_cmsis_os2_common.h >
24
22
25
23
#ifdef __cplusplus
26
24
extern " C" {
@@ -108,28 +106,39 @@ static uint16_t lastCount; // Nb of bytes already processed from the active dmaB
108
106
#else
109
107
#define UART_MAX_QUEUE_SIZE 25
110
108
#endif
111
- #define UART_TASK_SIZE 256
112
- #define UART_TASK_NAME " UART"
113
109
114
110
#ifdef CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE
115
111
#define UART_TX_MAX_BUF_LEN (CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE + 2 ) // \r\n
116
112
#else
117
113
#define UART_TX_MAX_BUF_LEN (258 )
118
114
#endif
119
115
120
- static TaskHandle_t sUartTaskHandle ;
121
- static StackType_t uartStack[UART_TASK_SIZE * sizeof (StackType_t)];
122
- static StaticTask_t uartTaskStruct;
116
+ static constexpr uint32_t kUartTxCompleteFlag = 1 ;
117
+ static osThreadId_t sUartTaskHandle ;
118
+ constexpr uint32_t kUartTaskSize = 1024 ;
119
+ static uint8_t uartStack[kUartTaskSize ];
120
+ static osThread_t sUartTaskControlBlock ;
121
+ constexpr osThreadAttr_t kUartTaskAttr = { .name = " UART" ,
122
+ .attr_bits = osThreadDetached,
123
+ .cb_mem = &sUartTaskControlBlock ,
124
+ .cb_size = osThreadCbSize,
125
+ .stack_mem = uartStack,
126
+ .stack_size = kUartTaskSize ,
127
+ .priority = osPriorityRealtime };
123
128
124
129
typedef struct
125
130
{
126
131
uint8_t data[UART_TX_MAX_BUF_LEN];
127
132
uint16_t length = 0 ;
128
133
} UartTxStruct_t;
129
134
135
+ static osMessageQueueId_t sUartTxQueue ;
136
+ static osMessageQueue_t sUartTxQueueStruct ;
130
137
uint8_t sUartTxQueueBuffer [UART_MAX_QUEUE_SIZE * sizeof (UartTxStruct_t)];
131
- static StaticQueue_t sUartTxQueueStruct ;
132
- static QueueHandle_t sUartTxQueue ;
138
+ constexpr osMessageQueueAttr_t kUartTxQueueAttr = { .cb_mem = &sUartTxQueueStruct ,
139
+ .cb_size = osMessageQueueCbSize,
140
+ .mq_mem = sUartTxQueueBuffer ,
141
+ .mq_size = sizeof (sUartTxQueueBuffer ) };
133
142
134
143
// Rx buffer for the receive Fifo
135
144
static uint8_t sRxFifoBuffer [MAX_BUFFER_SIZE];
@@ -264,8 +273,8 @@ void uartConsoleInit(void)
264
273
UARTDRV_Receive (vcom_handle, sRxDmaBuffer , MAX_DMA_BUFFER_SIZE, UART_rx_callback);
265
274
UARTDRV_Receive (vcom_handle, sRxDmaBuffer2 , MAX_DMA_BUFFER_SIZE, UART_rx_callback);
266
275
267
- sUartTxQueue = xQueueCreateStatic (UART_MAX_QUEUE_SIZE, sizeof (UartTxStruct_t), sUartTxQueueBuffer , & sUartTxQueueStruct );
268
- sUartTaskHandle = xTaskCreateStatic (uartMainLoop, UART_TASK_NAME, UART_TASK_SIZE, nullptr , 30 , uartStack, &uartTaskStruct );
276
+ sUartTxQueue = osMessageQueueNew (UART_MAX_QUEUE_SIZE, sizeof (UartTxStruct_t), & kUartTxQueueAttr );
277
+ sUartTaskHandle = osThreadNew (uartMainLoop, nullptr , & kUartTaskAttr );
269
278
270
279
assert (sUartTaskHandle );
271
280
assert (sUartTxQueue );
@@ -311,9 +320,8 @@ void USART_IRQHandler(void)
311
320
*/
312
321
void UART_tx_callback (struct UARTDRV_HandleData * handle, Ecode_t transferStatus, uint8_t * data, UARTDRV_Count_t transferCount)
313
322
{
314
- BaseType_t xHigherPriorityTaskWoken;
315
-
316
- vTaskNotifyGiveFromISR (sUartTaskHandle , &xHigherPriorityTaskWoken) portYIELD_FROM_ISR (xHigherPriorityTaskWoken);
323
+ // This function may be called from Interrupt Service Routines.
324
+ osThreadFlagsSet (sUartTaskHandle , kUartTxCompleteFlag );
317
325
}
318
326
319
327
/*
@@ -363,20 +371,10 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength)
363
371
memcpy (workBuffer.data , Buf, BufLength);
364
372
workBuffer.length = BufLength;
365
373
366
- if (xPortIsInsideInterrupt () )
374
+ if (osMessageQueuePut ( sUartTxQueue , &workBuffer, osPriorityNormal, 0 ) == osOK )
367
375
{
368
- BaseType_t xHigherPriorityTaskWoken;
369
- xQueueSendFromISR (sUartTxQueue , &workBuffer, &xHigherPriorityTaskWoken);
370
- portYIELD_FROM_ISR (xHigherPriorityTaskWoken);
371
376
return BufLength;
372
377
}
373
- else
374
- {
375
- if (pdTRUE == xQueueSend (sUartTxQueue , &workBuffer, portMAX_DELAY))
376
- {
377
- return BufLength;
378
- }
379
- }
380
378
381
379
return UART_CONSOLE_ERR;
382
380
}
@@ -400,20 +398,10 @@ int16_t uartLogWrite(const char * log, uint16_t length)
400
398
memcpy (workBuffer.data + length, " \r\n " , 2 );
401
399
workBuffer.length = length + 2 ;
402
400
403
- if (xPortIsInsideInterrupt () )
401
+ if (osMessageQueuePut ( sUartTxQueue , &workBuffer, osPriorityNormal, 0 ) == osOK )
404
402
{
405
- BaseType_t xHigherPriorityTaskWoken;
406
- xQueueSendFromISR (sUartTxQueue , &workBuffer, &xHigherPriorityTaskWoken);
407
- portYIELD_FROM_ISR (xHigherPriorityTaskWoken);
408
403
return length;
409
404
}
410
- else
411
- {
412
- if (pdTRUE == xQueueSend (sUartTxQueue , &workBuffer, 0 ))
413
- {
414
- return length;
415
- }
416
- }
417
405
418
406
return UART_CONSOLE_ERR;
419
407
}
@@ -453,11 +441,11 @@ void uartMainLoop(void * args)
453
441
while (1 )
454
442
{
455
443
456
- BaseType_t eventReceived = xQueueReceive (sUartTxQueue , &workBuffer, portMAX_DELAY );
444
+ osStatus_t eventReceived = osMessageQueueGet (sUartTxQueue , &workBuffer, nullptr , osWaitForever );
457
445
while (eventReceived == pdTRUE)
458
446
{
459
447
uartSendBytes (workBuffer.data , workBuffer.length );
460
- eventReceived = xQueueReceive (sUartTxQueue , &workBuffer, 0 );
448
+ eventReceived = osMessageQueueGet (sUartTxQueue , &workBuffer, nullptr , 0 );
461
449
}
462
450
}
463
451
}
@@ -470,29 +458,31 @@ void uartMainLoop(void * args)
470
458
*/
471
459
void uartSendBytes (uint8_t * buffer, uint16_t nbOfBytes)
472
460
{
473
-
474
461
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
475
462
sl_power_manager_add_em_requirement (SL_POWER_MANAGER_EM1);
476
- #endif
463
+ #endif // SL_CATALOG_POWER_MANAGER_PRESENT
464
+
477
465
#if SL_UARTCTRL_MUX
478
466
sl_wfx_host_pre_uart_transfer ();
479
467
#endif // SL_UARTCTRL_MUX
468
+
480
469
#if (defined(EFR32MG24) && defined(WF200_WIFI))
481
470
// Blocking transmit for the MG24 + WF200 since UART TX is multiplexed with
482
471
// WF200 SPI IRQ
483
472
UARTDRV_ForceTransmit (vcom_handle, (uint8_t *) buffer, nbOfBytes);
484
473
#else
485
474
// Non Blocking Transmit
486
475
UARTDRV_Transmit (vcom_handle, (uint8_t *) buffer, nbOfBytes, UART_tx_callback);
487
- ulTaskNotifyTake (pdTRUE, portMAX_DELAY );
476
+ osThreadFlagsWait ( kUartTxCompleteFlag , osFlagsWaitAny, osWaitForever );
488
477
#endif /* EFR32MG24 && WF200_WIFI */
478
+
489
479
#if SL_UARTCTRL_MUX
490
480
sl_wfx_host_post_uart_transfer ();
491
481
#endif // SL_UARTCTRL_MUX
492
482
493
483
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
494
484
sl_power_manager_remove_em_requirement (SL_POWER_MANAGER_EM1);
495
- #endif
485
+ #endif // SL_CATALOG_POWER_MANAGER_PRESENT
496
486
}
497
487
498
488
#ifdef __cplusplus
0 commit comments