Skip to content

Commit 1060008

Browse files
chirag-silabsrestyled-commits
authored andcommitted
[Silabs] Handling the garbage data on the uart and using Platform API's for 917 SoC (#30166)
* handling the garbage data on the uart * Using platform wrapper api's * Restyled by clang-format --------- Co-authored-by: Restyled.io <[email protected]>
1 parent c2bee12 commit 1060008

File tree

2 files changed

+43
-83
lines changed

2 files changed

+43
-83
lines changed

examples/platform/silabs/SiWx917/uart.cpp

+42-82
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "matter_shell.h"
2121
#include "rsi_rom_egpio.h"
2222
#include "silabs_utils.h"
23+
#include "sl_si91x_usart.h"
2324
#ifdef __cplusplus
2425
extern "C" {
2526
#endif
@@ -29,115 +30,73 @@ extern "C" {
2930
#include <stddef.h>
3031
#include <string.h>
3132

32-
extern ARM_DRIVER_USART Driver_USART0;
33-
static ARM_DRIVER_USART * UARTdrv = &Driver_USART0;
33+
#define USART_BAUDRATE 115200 // Baud rate <9600-7372800>
34+
#define UART_CONSOLE_ERR -1 // Negative value in case of UART Console action failed. Triggers a failure for PW_RPC
3435

35-
ARM_USART_CAPABILITIES drv_capabilities;
36+
sl_usart_handle_t usart_handle;
3637

37-
#define BAUD_VALUE 115200
38-
#define UART_CONSOLE_ERR -1 // Negative value in case of UART Console action failed. Triggers a failure for PW_RPC
38+
void callback_event(uint32_t event);
3939

40-
void ARM_USART_SignalEvent(uint32_t event);
41-
42-
void Read_Capabilities(void)
43-
{
44-
drv_capabilities = UARTdrv->GetCapabilities();
45-
}
46-
47-
void ARM_USART_SignalEvent(uint32_t event)
40+
/*******************************************************************************
41+
* Callback function triggered on data Transfer and reception
42+
******************************************************************************/
43+
void callback_event(uint32_t event)
4844
{
4945
switch (event)
5046
{
51-
case ARM_USART_EVENT_SEND_COMPLETE:
47+
case SL_USART_EVENT_SEND_COMPLETE:
5248
break;
53-
case ARM_USART_EVENT_RECEIVE_COMPLETE:
49+
case SL_USART_EVENT_RECEIVE_COMPLETE:
5450
#ifdef ENABLE_CHIP_SHELL
5551
chip::NotifyShellProcessFromISR();
56-
#endif
57-
case ARM_USART_EVENT_TRANSFER_COMPLETE:
58-
case ARM_USART_EVENT_TX_COMPLETE:
59-
case ARM_USART_EVENT_TX_UNDERFLOW:
60-
case ARM_USART_EVENT_RX_OVERFLOW:
61-
case ARM_USART_EVENT_RX_TIMEOUT:
62-
case ARM_USART_EVENT_RX_BREAK:
63-
case ARM_USART_EVENT_RX_FRAMING_ERROR:
64-
case ARM_USART_EVENT_RX_PARITY_ERROR:
65-
case ARM_USART_EVENT_CTS:
66-
case ARM_USART_EVENT_DSR:
67-
case ARM_USART_EVENT_DCD:
68-
case ARM_USART_EVENT_RI:
52+
#endif;
53+
case SL_USART_EVENT_TRANSFER_COMPLETE:
6954
break;
7055
}
7156
}
7257

7358
void uartConsoleInit(void)
7459
{
7560
int32_t status = 0;
76-
Read_Capabilities();
7761

78-
status = UARTdrv->Initialize(ARM_USART_SignalEvent);
79-
// Setting the GPIO 30 of the radio board (TX)
80-
// Setting the GPIO 29 of the radio board (RX)
81-
RSI_EGPIO_HostPadsGpioModeEnable(30);
82-
RSI_EGPIO_HostPadsGpioModeEnable(29);
62+
sl_si91x_usart_control_config_t usart_config;
63+
usart_config.baudrate = USART_BAUDRATE;
64+
usart_config.mode = SL_USART_MODE_ASYNCHRONOUS;
65+
usart_config.parity = SL_USART_NO_PARITY;
66+
usart_config.stopbits = SL_USART_STOP_BITS_1;
67+
usart_config.hwflowcontrol = SL_USART_FLOW_CONTROL_NONE;
68+
usart_config.databits = SL_USART_DATA_BITS_8;
69+
usart_config.misc_control = SL_USART_MISC_CONTROL_NONE;
70+
usart_config.usart_module = USART_0;
71+
usart_config.config_enable = ENABLE;
72+
usart_config.synch_mode = DISABLE;
73+
sl_si91x_usart_control_config_t get_config;
8374

8475
// Initialized board UART
8576
DEBUGINIT();
86-
if (status != ARM_DRIVER_OK)
87-
{
88-
DEBUGOUT("\r\n UART Initialization Failed, Error Code : %d\r\n", status);
89-
}
90-
else
91-
{
92-
DEBUGOUT("\r\n UART Initialization Success\r\n");
93-
}
94-
95-
// Power up the UART peripheral
96-
status = UARTdrv->PowerControl(ARM_POWER_FULL);
97-
if (status != ARM_DRIVER_OK)
98-
{
99-
DEBUGOUT("\r\n Failed to Set Power to UART, Error Code : %d\r\n", status);
100-
}
101-
else
102-
{
103-
DEBUGOUT("\r\n Configured Power to UART \r\n");
104-
}
10577

106-
// Enable Receiver and Transmitter lines
107-
status = UARTdrv->Control(ARM_USART_CONTROL_TX, 1);
108-
if (status != ARM_DRIVER_OK)
78+
// Initialize the UART
79+
status = sl_si91x_usart_init((usart_peripheral_t) usart_config.usart_module, &usart_handle);
80+
if (status != SL_STATUS_OK)
10981
{
110-
DEBUGOUT("\r\n Failed to Set Transmitter lines to UART, Error Code : %d\r\n", status);
111-
}
112-
else
113-
{
114-
DEBUGOUT("\r\n Set Transmitter lines to UART is sucess \r\n");
82+
DEBUGOUT("sl_si91x_usart_initialize: Error Code : %lu \n", status);
11583
}
11684

117-
status = UARTdrv->Control(ARM_USART_CONTROL_RX, 1);
118-
if (status != ARM_DRIVER_OK)
85+
// Configure the USART configurations
86+
status = sl_si91x_usart_set_configuration(usart_handle, &usart_config);
87+
if (status != SL_STATUS_OK)
11988
{
120-
DEBUGOUT("\r\n Failed to Set Receiver lines to UART, Error Code : %d \r\n", status);
121-
}
122-
else
123-
{
124-
DEBUGOUT("\r\n Set Receiver lines to UART\r\n");
89+
DEBUGOUT("sl_si91x_usart_set_configuration: Error Code : %lu \n", status);
12590
}
12691

127-
UARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 | ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 |
128-
ARM_USART_FLOW_CONTROL_NONE,
129-
BAUD_VALUE);
130-
if (status != ARM_DRIVER_OK)
131-
{
132-
DEBUGOUT("\r\n Failed to Receive data , Error Code : %d \r\n", status);
133-
}
134-
else
92+
// Register user callback function
93+
status = sl_si91x_usart_register_event_callback(callback_event);
94+
if (status != SL_STATUS_OK)
13595
{
136-
DEBUGOUT("\r\n Receives data success \r\n");
96+
DEBUGOUT("sl_si91x_usart_register_event_callback: Error Code : %lu \n", status);
13797
}
13898

13999
NVIC_EnableIRQ(USART0_IRQn);
140-
141100
NVIC_SetPriority(USART0_IRQn, 7);
142101
}
143102

@@ -154,8 +113,8 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength)
154113
return UART_CONSOLE_ERR;
155114
}
156115

157-
status = UARTdrv->Send(Buf, BufLength);
158-
if (status != ARM_DRIVER_OK)
116+
status = sl_si91x_usart_send_data(usart_handle, Buf, BufLength);
117+
if (status != SL_STATUS_OK)
159118
{
160119
return status;
161120
}
@@ -174,8 +133,9 @@ int16_t uartConsoleRead(char * Buf, uint16_t NbBytesToRead)
174133
{
175134
return UART_CONSOLE_ERR;
176135
}
177-
status = UARTdrv->Receive(Buf, NbBytesToRead);
178-
if (status != ARM_DRIVER_OK)
136+
137+
status = sl_si91x_usart_receive_data(usart_handle, Buf, NbBytesToRead);
138+
if (status != SL_STATUS_OK)
179139
{
180140
return status;
181141
}

src/lib/shell/MainLoopSilabs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ void ReadLine(char * buffer, size_t max)
118118
if (isprint(static_cast<int>(buffer[line_sz])) || buffer[line_sz] == '\t')
119119
{
120120
streamer_printf(streamer_get(), "%c", buffer[line_sz]);
121-
line_sz++;
122121
}
122+
line_sz++;
123123
break;
124124
}
125125
}

0 commit comments

Comments
 (0)