pipe.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #ifndef PIPE_H__
  10. #define PIPE_H__
  11. #include <rtdef.h>
  12. #include <rtconfig.h>
  13. /**
  14. * Pipe Device
  15. */
  16. struct rt_pipe_device
  17. {
  18. struct rt_device parent;
  19. rt_bool_t is_named;
  20. #ifdef RT_USING_POSIX_DEVIO
  21. int pipeno; /* for unamed pipe */
  22. #endif
  23. /* ring buffer in pipe device */
  24. struct rt_ringbuffer *fifo;
  25. rt_uint16_t bufsz;
  26. rt_wqueue_t reader_queue;
  27. rt_wqueue_t writer_queue;
  28. int writer;
  29. int reader;
  30. struct rt_mutex lock;
  31. };
  32. typedef struct rt_pipe_device rt_pipe_t;
  33. rt_pipe_t *rt_pipe_create(const char *name, int bufsz);
  34. rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag);
  35. rt_ssize_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count);
  36. rt_ssize_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count);
  37. rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args);
  38. rt_err_t rt_pipe_close(rt_device_t device);
  39. int rt_pipe_delete(const char *name);
  40. #endif /* PIPE_H__ */