1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 */ 9 #ifndef __AUDIO_PIPE_H__ 10 #define __AUDIO_PIPE_H__ 11 12 /** 13 * Pipe Device 14 */ 15 #include <rtthread.h> 16 #include <rtdevice.h> 17 18 #ifndef RT_PIPE_BUFSZ 19 #define PIPE_BUFSZ 512 20 #else 21 #define PIPE_BUFSZ RT_PIPE_BUFSZ 22 #endif 23 24 /* portal device */ 25 struct rt_audio_portal_device 26 { 27 struct rt_device parent; 28 struct rt_device *write_dev; 29 struct rt_device *read_dev; 30 }; 31 32 enum rt_audio_pipe_flag 33 { 34 /* both read and write won't block */ 35 RT_PIPE_FLAG_NONBLOCK_RDWR = 0x00, 36 /* read would block */ 37 RT_PIPE_FLAG_BLOCK_RD = 0x01, 38 /* write would block */ 39 RT_PIPE_FLAG_BLOCK_WR = 0x02, 40 /* write to this pipe will discard some data when the pipe is full. 41 * When this flag is set, RT_PIPE_FLAG_BLOCK_WR will be ignored since write 42 * operation will always be success. */ 43 RT_PIPE_FLAG_FORCE_WR = 0x04, 44 }; 45 46 struct rt_audio_pipe 47 { 48 struct rt_device parent; 49 50 /* ring buffer in pipe device */ 51 struct rt_ringbuffer ringbuffer; 52 53 rt_int32_t flag; 54 55 /* suspended list */ 56 rt_list_t suspended_read_list; 57 rt_list_t suspended_write_list; 58 59 struct rt_audio_portal_device *write_portal; 60 struct rt_audio_portal_device *read_portal; 61 }; 62 63 #define PIPE_CTRL_GET_SPACE 0x14 /**< get the remaining size of a pipe device */ 64 65 rt_err_t rt_audio_pipe_init(struct rt_audio_pipe *pipe, 66 const char *name, 67 rt_int32_t flag, 68 rt_uint8_t *buf, 69 rt_size_t size); 70 rt_err_t rt_audio_pipe_detach(struct rt_audio_pipe *pipe); 71 #ifdef RT_USING_HEAP 72 rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size); 73 void rt_audio_pipe_destroy(struct rt_audio_pipe *pipe); 74 #endif 75 #endif 76 77