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

Function rt_serial_close

components/drivers/serial/dev_serial_v2.c:1151–1174  ·  view source on GitHub ↗

* @brief Close the serial device. * @param dev The pointer of device driver structure * @return Return the status of the operation. */

Source from the content-addressed store, hash-verified

1149 * @return Return the status of the operation.
1150 */
1151static rt_err_t rt_serial_close(struct rt_device *dev)
1152{
1153 struct rt_serial_device *serial;
1154
1155 RT_ASSERT(dev != RT_NULL);
1156 serial = (struct rt_serial_device *)dev;
1157
1158 /* Disable serial receive mode. */
1159 rt_serial_rx_disable(dev, dev->open_flag & (RT_SERIAL_RX_BLOCKING | RT_SERIAL_RX_NON_BLOCKING));
1160 /* Disable serial tranmit mode. */
1161 rt_serial_tx_disable(dev, dev->open_flag & (RT_SERIAL_TX_BLOCKING | RT_SERIAL_TX_NON_BLOCKING));
1162
1163 /* Clear the callback function */
1164 serial->parent.rx_indicate = RT_NULL;
1165 serial->parent.tx_complete = RT_NULL;
1166
1167 rt_memset(&serial->rx_notify, RT_NULL, sizeof(struct rt_device_notify));
1168
1169 /* Call the control() API to close the serial device. disable ignore return value */
1170 serial->ops->control(serial, RT_DEVICE_CTRL_CLOSE, RT_NULL);
1171 dev->flag &= ~RT_DEVICE_FLAG_ACTIVATED;
1172
1173 return RT_EOK;
1174}
1175
1176/**
1177 * @brief Open the serial device.

Callers 1

rt_serial_openFunction · 0.70

Calls 3

rt_serial_rx_disableFunction · 0.85
rt_serial_tx_disableFunction · 0.85
rt_memsetFunction · 0.85

Tested by

no test coverage detected