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

Function serial_fops_read

components/drivers/serial/dev_serial_v2.c:145–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143static ssize_t serial_fops_read(struct dfs_file *fd, void *buf, size_t count, off_t *pos)
144#else
145static ssize_t serial_fops_read(struct dfs_file *fd, void *buf, size_t count)
146#endif
147{
148 ssize_t size = 0;
149 rt_device_t device;
150 rt_int32_t rx_timout;
151
152 if (count == 0) return 0;
153 RT_ASSERT(fd != RT_NULL && buf != RT_NULL);
154
155 device = (rt_device_t)fd->vnode->data;
156 RT_ASSERT(device != RT_NULL);
157
158 /* nonblock mode */
159 if (fd->flags & O_NONBLOCK)
160 {
161 rx_timout = RT_WAITING_NO;
162 rt_device_control(device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timout);
163 size = rt_device_read(device, -1, buf, count);
164 if (size <= 0)
165 {
166 size = -1;
167 rt_set_errno(EAGAIN);
168 }
169 }
170 else
171 {
172 rx_timout = RT_WAITING_FOREVER;
173 rt_device_control(device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timout);
174 size = rt_device_read(device, -1, buf, count);
175 }
176
177
178 return size;
179}
180
181#ifdef RT_USING_DFS_V2
182static ssize_t serial_fops_write(struct dfs_file *fd, const void *buf, size_t count, off_t *pos)

Callers

nothing calls this directly

Calls 3

rt_device_controlFunction · 0.85
rt_device_readFunction · 0.85
rt_set_errnoFunction · 0.85

Tested by

no test coverage detected