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

Function rt_serial_control

components/drivers/serial/dev_serial_v2.c:1378–1779  ·  view source on GitHub ↗

* @brief Control the serial device. * @param dev The pointer of device driver structure * @param cmd The command value that controls the serial device * @param args The parameter value that controls the serial device * @return Return the status of the operation. */

Source from the content-addressed store, hash-verified

1376 * @return Return the status of the operation.
1377 */
1378static rt_err_t rt_serial_control(struct rt_device *dev,
1379 int cmd,
1380 void *args)
1381{
1382 rt_err_t ret = RT_EOK;
1383 struct rt_serial_device *serial;
1384
1385 RT_ASSERT(dev != RT_NULL);
1386 serial = (struct rt_serial_device *)dev;
1387
1388 switch ((rt_ubase_t)cmd)
1389 {
1390 case RT_DEVICE_CTRL_SUSPEND:
1391 /* suspend device */
1392 dev->flag |= RT_DEVICE_FLAG_SUSPENDED;
1393 break;
1394
1395 case RT_DEVICE_CTRL_RESUME:
1396 /* resume device */
1397 dev->flag &= ~RT_DEVICE_FLAG_SUSPENDED;
1398 break;
1399
1400 case RT_DEVICE_CTRL_CONFIG:
1401 if (args == RT_NULL)
1402 {
1403 ret = -RT_EINVAL;
1404 }
1405 else
1406 {
1407 struct serial_configure *pconfig = (struct serial_configure *)args;
1408 if (((pconfig->rx_bufsz != serial->config.rx_bufsz)
1409 || (pconfig->tx_bufsz != serial->config.tx_bufsz)
1410#ifdef RT_SERIAL_USING_DMA
1411 || (pconfig->dma_ping_bufsz != serial->config.dma_ping_bufsz)
1412#endif
1413 )
1414 && serial->parent.ref_count != 0)
1415 {
1416 /*can not change buffer size*/
1417 ret = -RT_EBUSY;
1418 break;
1419 }
1420 /* set serial configure */
1421 serial->config = *pconfig;
1422 serial->ops->configure(serial, (struct serial_configure *)args);
1423 }
1424 break;
1425 case RT_SERIAL_CTRL_GET_CONFIG:
1426 if (args == RT_NULL)
1427 {
1428 ret = -RT_EINVAL;
1429 }
1430 else
1431 {
1432 struct serial_configure *pconfig = (struct serial_configure *)args;
1433 *pconfig = serial->config;
1434 }
1435 break;

Callers

nothing calls this directly

Calls 15

rt_memcpyFunction · 0.85
_serial_rx_flushFunction · 0.85
_serial_tx_flushFunction · 0.85
rt_console_get_deviceFunction · 0.85
cfsetospeedFunction · 0.85
cfgetospeedFunction · 0.85
rt_kprintfFunction · 0.85
rt_thread_selfFunction · 0.85
rt_thread_findFunction · 0.85
rt_memsetFunction · 0.85
finsh_getcharFunction · 0.85

Tested by

no test coverage detected