diff options
| author | Grissiom <[email protected]> | 2013-08-19 15:35:56 +0800 |
|---|---|---|
| committer | Grissiom <[email protected]> | 2013-08-19 15:35:56 +0800 |
| commit | d683d32bd5502c15be600145966400a41710a7f4 (patch) | |
| tree | a3ca87a5102cd8686fe90bfe54589398a79f04c6 /components/drivers/include/rtdevice.h | |
| parent | 4919d29d693491e8eae9697deed7b808c7bcbb93 (diff) | |
device/pipe: add nonblocking read/write and force write mode
The previous implementation will always blocks the reader/writer.
However, at least FinSh would expect the device to be nonblocking ---
read should return 0 when there is no data in it.
Diffstat (limited to 'components/drivers/include/rtdevice.h')
| -rw-r--r-- | components/drivers/include/rtdevice.h | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h index bd6e243b0a..734839e69e 100644 --- a/components/drivers/include/rtdevice.h +++ b/components/drivers/include/rtdevice.h @@ -75,6 +75,20 @@ struct rt_ringbuffer /* pipe device */ #define PIPE_DEVICE(device) ((struct rt_pipe_device*)(device)) +enum rt_pipe_flag +{ + /* both read and write won't block */ + RT_PIPE_FLAG_NONBLOCK_RDWR = 0x00, + /* read would block */ + RT_PIPE_FLAG_BLOCK_RD = 0x01, + /* write would block */ + RT_PIPE_FLAG_BLOCK_WR = 0x02, + /* write to this pipe will discard some data when the pipe is full. + * When this flag is set, RT_PIPE_FLAG_BLOCK_WR will be ignored since write + * operation will always be success. */ + RT_PIPE_FLAG_FORCE_WR = 0x04, +}; + struct rt_pipe_device { struct rt_device parent; @@ -82,6 +96,8 @@ struct rt_pipe_device /* ring buffer in pipe device */ struct rt_ringbuffer ringbuffer; + enum rt_pipe_flag flag; + /* suspended list */ rt_list_t suspended_read_list; rt_list_t suspended_write_list; @@ -199,11 +215,12 @@ rt_inline rt_uint16_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb) */ rt_err_t rt_pipe_init(struct rt_pipe_device *pipe, const char *name, + enum rt_pipe_flag flag, rt_uint8_t *buf, rt_size_t size); rt_err_t rt_pipe_detach(struct rt_pipe_device *pipe); #ifdef RT_USING_HEAP -rt_err_t rt_pipe_create(const char *name, rt_size_t size); +rt_err_t rt_pipe_create(const char *name, enum rt_pipe_flag flag, rt_size_t size); void rt_pipe_destroy(struct rt_pipe_device *pipe); #endif |
