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

Function uart_sample_v1

bsp/hc32/tests/test_uart_v1.c:160–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160int uart_sample_v1(int argc, char *argv[])
161{
162 rt_thread_t thread;
163 rt_err_t ret = RT_EOK;
164 rt_size_t n;
165 rt_err_t open_flag = 0UL;
166 static char uart_name[RT_NAME_MAX];
167 static char comm_mode[RT_NAME_MAX];
168 const static char comm_mode_int[] = "int";
169 const static char comm_mode_dma[] = "dma";
170 const static char comm_info_dma[] = "\r\n drv_version: drv_usart_v1 \r\n communication: using DMA \r\n uart_ch: ";
171 const static char comm_info_int[] = "\r\n drv_version: drv_usart_v1 \r\n communication: using interrupt \r\n uart_ch: ";
172 static char comm_info[150];
173
174 rt_memset(uart_name, 0, sizeof(uart_name));
175 rt_memset(comm_mode, 0, sizeof(comm_mode));
176
177 if (argc == 1)
178 {
179 rt_strncpy(uart_name, SAMPLE_DEFAULT_UART_NAME, RT_NAME_MAX);
180 rt_strncpy(comm_mode, comm_mode_int, sizeof(comm_mode_int));
181 }
182 else if (argc == 2)
183 {
184 rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
185 rt_strncpy(comm_mode, comm_mode_int, sizeof(comm_mode_int));
186 }
187 else if (argc == 3)
188 {
189 rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
190 rt_strncpy(comm_mode, argv[2], RT_NAME_MAX);
191 }
192 else
193 {
194 rt_kprintf("argc error!\n");
195 return -RT_ERROR;
196 }
197
198 /* 查找系统中的串口设备 */
199 serial = rt_device_find(uart_name);
200 if (!serial)
201 {
202 rt_kprintf("find %s failed!\n", uart_name);
203 return -RT_ERROR;
204 }
205
206 /* modify configure */
207 config.baud_rate = BAUD_RATE_115200; //baudrate 115200
208 config.data_bits = DATA_BITS_8; //data bit 8
209 config.stop_bits = STOP_BITS_1; //stop bit 1
210 config.parity = PARITY_NONE;
211 rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
212
213 if (0 == rt_strncmp(comm_mode, comm_mode_dma, 3))
214 {
215 static char msg_pool[256U];
216 /* 初始化消息队列 */
217 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