1 /* 2 * Copyright (c) 2006-2023, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 */ 9 10 #ifndef PIPE_H__ 11 #define PIPE_H__ 12 13 #include <rtdef.h> 14 #include <rtconfig.h> 15 #include "condvar.h" 16 17 /** 18 * Pipe Device 19 */ 20 21 struct rt_pipe_device 22 { 23 struct rt_device parent; 24 rt_bool_t is_named; 25 #ifdef RT_USING_POSIX_DEVIO 26 int pipeno; /* for unamed pipe */ 27 #endif 28 29 /* ring buffer in pipe device */ 30 struct rt_ringbuffer *fifo; 31 rt_uint16_t bufsz; 32 33 rt_wqueue_t reader_queue; 34 rt_wqueue_t writer_queue; 35 int writer; 36 int reader; 37 38 struct rt_condvar waitfor_parter; 39 struct rt_mutex lock; 40 }; 41 typedef struct rt_pipe_device rt_pipe_t; 42 43 rt_pipe_t *rt_pipe_create(const char *name, int bufsz); 44 rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag); 45 rt_ssize_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count); 46 rt_ssize_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count); 47 rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args); 48 rt_err_t rt_pipe_close(rt_device_t device); 49 int rt_pipe_delete(const char *name); 50 51 #endif /* PIPE_H__ */ 52