MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / uart_sample_v2

Function uart_sample_v2

bsp/hc32/tests/test_uart_v2.c:187–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187int uart_sample_v2(int argc, char *argv[])
188{
189 rt_thread_t thread;
190 rt_err_t ret = RT_EOK;
191 rt_size_t n;
192 rt_err_t open_flag = 0UL;
193 static char uart_name[RT_NAME_MAX];
194 static char comm_mode[RT_NAME_MAX];
195 const static char comm_mode_int[] = "int";
196 const static char comm_mode_dma[] = "dma";
197 const static char comm_info_dma[] = "\r\n drv_version: drv_usart_v2 \r\n communication: using DMA \r\n uart_ch: ";
198 const static char comm_info_int[] = "\r\n drv_version: drv_usart_v2 \r\n communication: using interrupt \r\n uart_ch: ";
199 static char comm_info[150];
200
201 rt_memset(uart_name, 0, sizeof(uart_name));
202 rt_memset(comm_mode, 0, sizeof(comm_mode));
203
204 if (argc == 1)
205 {
206 rt_strncpy(uart_name, SAMPLE_DEFAULT_UART_NAME, RT_NAME_MAX);
207 rt_strncpy(comm_mode, comm_mode_int, sizeof(comm_mode_int));
208 }
209 else if (argc == 2)
210 {
211 rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
212 rt_strncpy(comm_mode, comm_mode_int, sizeof(comm_mode_int));
213 }
214 else if (argc == 3)
215 {
216 rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
217 rt_strncpy(comm_mode, argv[2], RT_NAME_MAX);
218 }
219 else
220 {
221 rt_kprintf("argc error!\n");
222 return -RT_ERROR;
223 }
224
225 /* 查找串口设备 */
226 serial = rt_device_find(uart_name);
227 if (!serial)
228 {
229 rt_kprintf("find %s failed!\n", uart_name);
230 return -RT_ERROR;
231 }
232
233 /* modify configure */
234 config.baud_rate = BAUD_RATE_115200; //baudrate 115200
235 config.data_bits = DATA_BITS_8; //data bit 8
236 config.stop_bits = STOP_BITS_1; //stop bit 1
237 config.parity = PARITY_NONE;
238 rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
239
240 if (0 == rt_strncmp(comm_mode, comm_mode_dma, 3))
241 {
242 static char msg_pool[256U];
243 /* 初始化消息队列 */
244 rt_mq_init(&rx_mq, "rx_mq",

Callers

nothing calls this directly

Calls 15

rt_memsetFunction · 0.85
rt_strncpyFunction · 0.85
rt_kprintfFunction · 0.85
rt_device_findFunction · 0.85
rt_device_controlFunction · 0.85
rt_strncmpFunction · 0.85
rt_mq_initFunction · 0.85
rt_device_openFunction · 0.85
rt_strlenFunction · 0.85
rt_device_writeFunction · 0.85

Tested by

no test coverage detected