@@ -32,7 +32,11 @@ extern "C" {
32
32
#include < string.h>
33
33
34
34
#define UART_CONSOLE_ERR -1 // Negative value in case of UART Console action failed. Triggers a failure for PW_RPC
35
+ #ifdef CHIP_SHELL_MAX_LINE_SIZE
36
+ #define MAX_BUFFER_SIZE CHIP_SHELL_MAX_LINE_SIZE
37
+ #else
35
38
#define MAX_BUFFER_SIZE 256
39
+ #endif
36
40
#define MAX_DMA_BUFFER_SIZE (MAX_BUFFER_SIZE / 2 )
37
41
38
42
#if SLI_SI91X_MCU_INTERFACE
@@ -92,7 +96,7 @@ extern "C" {
92
96
#define EUSART_INT_ENABLE EUSART_IntEnable
93
97
#define EUSART_INT_DISABLE EUSART_IntDisable
94
98
#define EUSART_INT_CLEAR EUSART_IntClear
95
- #define EUSART_CLEAR_RX
99
+ #define EUSART_CLEAR_RX ( x ) ( void ) x
96
100
#define EUSART_GET_PENDING_INT EUSART_IntGet
97
101
#define EUSART_ENABLE (eusart ) EUSART_Enable(eusart, eusartEnable)
98
102
#else
@@ -189,7 +193,7 @@ static Fifo_t sReceiveFifo;
189
193
#if SLI_SI91X_MCU_INTERFACE == 0
190
194
static void UART_rx_callback (UARTDRV_Handle_t handle, Ecode_t transferStatus, uint8_t * data, UARTDRV_Count_t transferCount);
191
195
#endif // SLI_SI91X_MCU_INTERFACE == 0
192
- static void uartSendBytes (uint8_t * buffer, uint16_t nbOfBytes );
196
+ static void uartSendBytes (UartTxStruct_t & bufferStruct );
193
197
194
198
static bool InitFifo (Fifo_t * fifo, uint8_t * pDataBuffer, uint16_t bufferSize)
195
199
{
@@ -523,11 +527,10 @@ void uartMainLoop(void * args)
523
527
524
528
while (1 )
525
529
{
526
-
527
530
osStatus_t eventReceived = osMessageQueueGet (sUartTxQueue , &workBuffer, nullptr , osWaitForever);
528
531
while (eventReceived == osOK)
529
532
{
530
- uartSendBytes (workBuffer. data , workBuffer. length );
533
+ uartSendBytes (workBuffer);
531
534
eventReceived = osMessageQueueGet (sUartTxQueue , &workBuffer, nullptr , 0 );
532
535
}
533
536
}
@@ -536,18 +539,21 @@ void uartMainLoop(void * args)
536
539
/* *
537
540
* @brief Send Bytes to UART. This blocks the UART task.
538
541
*
539
- * @param buffer pointer to the buffer containing the data
540
- * @param nbOfBytes number of bytes to send
542
+ * @param bufferStruct reference to the UartTxStruct_t containing the data
541
543
*/
542
- void uartSendBytes (uint8_t * buffer, uint16_t nbOfBytes )
544
+ void uartSendBytes (UartTxStruct_t & bufferStruct )
543
545
{
544
546
#if SLI_SI91X_MCU_INTERFACE
545
547
// ensuring null termination of buffer
546
- if (nbOfBytes != CHIP_SHELL_MAX_LINE_SIZE && buffer[nbOfBytes - 1 ] != ' \0 ' )
548
+ if (bufferStruct.length < ArraySize (bufferStruct.data ) && bufferStruct.data [bufferStruct.length - 1 ] != ' \0 ' )
549
+ {
550
+ bufferStruct.data [bufferStruct.length ] = ' \0 ' ;
551
+ }
552
+ else
547
553
{
548
- buffer[nbOfBytes ] = ' \0 ' ;
554
+ bufferStruct. data [ ArraySize (bufferStruct. data ) - 1 ] = ' \0 ' ;
549
555
}
550
- Board_UARTPutSTR (reinterpret_cast < uint8_t *>(buffer) );
556
+ Board_UARTPutSTR (bufferStruct. data );
551
557
#else
552
558
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
553
559
sl_power_manager_add_em_requirement (SL_POWER_MANAGER_EM1);
@@ -560,10 +566,10 @@ void uartSendBytes(uint8_t * buffer, uint16_t nbOfBytes)
560
566
#if (defined(EFR32MG24) && defined(WF200_WIFI))
561
567
// Blocking transmit for the MG24 + WF200 since UART TX is multiplexed with
562
568
// WF200 SPI IRQ
563
- UARTDRV_ForceTransmit (vcom_handle, ( uint8_t *) buffer, nbOfBytes );
569
+ UARTDRV_ForceTransmit (vcom_handle, bufferStruct. data , bufferStruct. length );
564
570
#else
565
571
// Non Blocking Transmit
566
- UARTDRV_Transmit (vcom_handle, ( uint8_t *) buffer, nbOfBytes , UART_tx_callback);
572
+ UARTDRV_Transmit (vcom_handle, bufferStruct. data , bufferStruct. length , UART_tx_callback);
567
573
osThreadFlagsWait (kUartTxCompleteFlag , osFlagsWaitAny, osWaitForever);
568
574
#endif /* EFR32MG24 && WF200_WIFI */
569
575
@@ -577,6 +583,32 @@ void uartSendBytes(uint8_t * buffer, uint16_t nbOfBytes)
577
583
#endif // SLI_SI91X_MCU_INTERFACE
578
584
}
579
585
586
+ /* *
587
+ * @brief Flush the UART TX queue in a blocking manner.
588
+ */
589
+ void uartFlushTxQueue (void )
590
+ {
591
+ UartTxStruct_t workBuffer;
592
+
593
+ while (osMessageQueueGet (sUartTxQueue , &workBuffer, nullptr , 0 ) == osOK)
594
+ {
595
+ #if SLI_SI91X_MCU_INTERFACE
596
+ // ensuring null termination of buffer
597
+ if (workBuffer.length < ArraySize (workBuffer.data ) && workBuffer.data [workBuffer.length - 1 ] != ' \0 ' )
598
+ {
599
+ workBuffer.data [workBuffer.length ] = ' \0 ' ;
600
+ }
601
+ else
602
+ {
603
+ workBuffer.data [ArraySize (workBuffer.data ) - 1 ] = ' \0 ' ;
604
+ }
605
+ Board_UARTPutSTR (workBuffer.data );
606
+ #else
607
+ UARTDRV_ForceTransmit (vcom_handle, workBuffer.data , workBuffer.length );
608
+ #endif
609
+ }
610
+ }
611
+
580
612
#ifdef __cplusplus
581
613
}
582
614
#endif
0 commit comments