fops for serial */
| 60 | |
| 61 | /* fops for serial */ |
| 62 | static 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 | |
| 105 | static int serial_fops_close(struct dfs_file *fd) |
| 106 | { |
nothing calls this directly
no test coverage detected