20
20
#include " matter_shell.h"
21
21
#include " rsi_rom_egpio.h"
22
22
#include " silabs_utils.h"
23
+ #include " sl_si91x_usart.h"
23
24
#ifdef __cplusplus
24
25
extern " C" {
25
26
#endif
@@ -29,115 +30,73 @@ extern "C" {
29
30
#include < stddef.h>
30
31
#include < string.h>
31
32
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
34
35
35
- ARM_USART_CAPABILITIES drv_capabilities ;
36
+ sl_usart_handle_t usart_handle ;
36
37
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);
39
39
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)
48
44
{
49
45
switch (event)
50
46
{
51
- case ARM_USART_EVENT_SEND_COMPLETE :
47
+ case SL_USART_EVENT_SEND_COMPLETE :
52
48
break ;
53
- case ARM_USART_EVENT_RECEIVE_COMPLETE :
49
+ case SL_USART_EVENT_RECEIVE_COMPLETE :
54
50
#ifdef ENABLE_CHIP_SHELL
55
51
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:
69
54
break ;
70
55
}
71
56
}
72
57
73
58
void uartConsoleInit (void )
74
59
{
75
60
int32_t status = 0 ;
76
- Read_Capabilities ();
77
61
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;
83
74
84
75
// Initialized board UART
85
76
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
- }
105
77
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 )
109
81
{
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);
115
83
}
116
84
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)
119
88
{
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);
125
90
}
126
91
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)
135
95
{
136
- DEBUGOUT (" \r\n Receives data success \r\n " );
96
+ DEBUGOUT (" sl_si91x_usart_register_event_callback: Error Code : %lu \n " , status );
137
97
}
138
98
139
99
NVIC_EnableIRQ (USART0_IRQn);
140
-
141
100
NVIC_SetPriority (USART0_IRQn, 7 );
142
101
}
143
102
@@ -154,8 +113,8 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength)
154
113
return UART_CONSOLE_ERR;
155
114
}
156
115
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 )
159
118
{
160
119
return status;
161
120
}
@@ -174,8 +133,9 @@ int16_t uartConsoleRead(char * Buf, uint16_t NbBytesToRead)
174
133
{
175
134
return UART_CONSOLE_ERR;
176
135
}
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)
179
139
{
180
140
return status;
181
141
}
0 commit comments