| 192 | } |
| 193 | |
| 194 | static int serial_fops_poll(struct dfs_file *fd, struct rt_pollreq *req) |
| 195 | { |
| 196 | int mask = 0; |
| 197 | int flags = 0; |
| 198 | rt_device_t device; |
| 199 | struct rt_serial_device *serial; |
| 200 | |
| 201 | device = (rt_device_t)fd->vnode->data; |
| 202 | RT_ASSERT(device != RT_NULL); |
| 203 | |
| 204 | serial = (struct rt_serial_device *)device; |
| 205 | |
| 206 | /* only support POLLIN */ |
| 207 | flags = fd->flags & O_ACCMODE; |
| 208 | if (flags == O_RDONLY || flags == O_RDWR) |
| 209 | { |
| 210 | rt_base_t level; |
| 211 | struct rt_serial_rx_fifo* rx_fifo; |
| 212 | |
| 213 | rt_poll_add(&(device->wait_queue), req); |
| 214 | |
| 215 | rx_fifo = (struct rt_serial_rx_fifo*) serial->serial_rx; |
| 216 | |
| 217 | level = rt_spin_lock_irqsave(&(serial->spinlock)); |
| 218 | if ((rx_fifo->get_index != rx_fifo->put_index) || (rx_fifo->get_index == rx_fifo->put_index && rx_fifo->is_full == RT_TRUE)) |
| 219 | mask |= POLLIN; |
| 220 | rt_spin_unlock_irqrestore(&(serial->spinlock), level); |
| 221 | } |
| 222 | |
| 223 | return mask; |
| 224 | } |
| 225 | |
| 226 | static const struct dfs_file_ops _serial_fops = |
| 227 | { |
nothing calls this directly
no test coverage detected