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

Function serial_fops_open

components/drivers/serial/dev_serial_v2.c:62–103  ·  view source on GitHub ↗

fops for serial */

Source from the content-addressed store, hash-verified

60
61/* fops for serial */
62static int serial_fops_open(struct dfs_file *fd)
63{
64 rt_err_t ret = 0;
65 rt_uint16_t flags = 0;
66 rt_device_t device;
67 struct rt_serial_device *serial;
68
69 device = (rt_device_t)fd->vnode->data;
70 RT_ASSERT(device != RT_NULL);
71
72 switch (fd->flags & O_ACCMODE)
73 {
74 case O_RDONLY:
75 LOG_D("fops open: O_RDONLY!");
76 flags = RT_DEVICE_FLAG_RDONLY;
77 break;
78 case O_WRONLY:
79 LOG_D("fops open: O_WRONLY!");
80 flags = RT_DEVICE_FLAG_WRONLY;
81 break;
82 case O_RDWR:
83 LOG_D("fops open: O_RDWR!");
84 flags = RT_DEVICE_FLAG_RDWR;
85 break;
86 default:
87 LOG_E("fops open: unknown mode - %d!", fd->flags & O_ACCMODE);
88 break;
89 }
90
91 if ((fd->flags & O_ACCMODE) != O_WRONLY)
92 rt_device_set_rx_indicate(device, serial_fops_rx_ind);
93
94 rt_device_close(device);
95 ret = rt_device_open(device, flags | RT_SERIAL_RX_BLOCKING | RT_SERIAL_TX_BLOCKING);
96 if (ret == RT_EOK)
97 {
98 serial = (struct rt_serial_device *)device;
99 serial->is_posix_mode = RT_TRUE;
100 }
101
102 return ret;
103}
104
105static int serial_fops_close(struct dfs_file *fd)
106{

Callers

nothing calls this directly

Calls 3

rt_device_closeFunction · 0.85
rt_device_openFunction · 0.85

Tested by

no test coverage detected