fci_ringbuffer.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*****************************************************************************
  2. Copyright(c) 2010 FCI Inc. All Rights Reserved
  3. File name : fci_ringbuffer.h
  4. Description :
  5. History :
  6. ----------------------------------------------------------------------
  7. 2010/11/25 aslan.cho initial
  8. *******************************************************************************/
  9. #ifndef __FCI_RINGBUFFER_H__
  10. #define __FCI_RINGBUFFER_H__
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #include <linux/spinlock.h>
  15. #include <linux/wait.h>
  16. struct fci_ringbuffer {
  17. u8 *data;
  18. ssize_t size;
  19. ssize_t pread;
  20. ssize_t pwrite;
  21. int error;
  22. wait_queue_head_t queue;
  23. spinlock_t lock;
  24. };
  25. #define FCI_RINGBUFFER_PKTHDRSIZE 3
  26. extern void fci_ringbuffer_init(struct fci_ringbuffer *rbuf
  27. , void *data, size_t len);
  28. extern int fci_ringbuffer_empty(struct fci_ringbuffer *rbuf);
  29. extern ssize_t fci_ringbuffer_free(struct fci_ringbuffer *rbuf);
  30. extern ssize_t fci_ringbuffer_avail(struct fci_ringbuffer *rbuf);
  31. extern void fci_ringbuffer_reset(struct fci_ringbuffer *rbuf);
  32. extern void fci_ringbuffer_flush(struct fci_ringbuffer *rbuf);
  33. extern void fci_ringbuffer_flush_spinlock_wakeup(struct fci_ringbuffer *rbuf);
  34. #define FCI_RINGBUFFER_PEEK(rbuf, offs) \
  35. ((rbuf)->data[((rbuf)->pread+(offs)) % (rbuf)->size])
  36. #define FCI_RINGBUFFER_SKIP(rbuf, num) \
  37. ((rbuf)->pread = ((rbuf)->pread+(num)) % (rbuf)->size)
  38. extern ssize_t fci_ringbuffer_read_user(struct fci_ringbuffer *rbuf
  39. , u8 __user *buf, size_t len);
  40. extern void fci_ringbuffer_read(struct fci_ringbuffer *rbuf
  41. , u8 *buf, size_t len);
  42. #define FCI_RINGBUFFER_WRITE_BYTE(rbuf, byte) \
  43. { (rbuf)->data[(rbuf)->pwrite] = (byte); \
  44. (rbuf)->pwrite = ((rbuf)->pwrite + 1) % (rbuf)->size; }
  45. extern ssize_t fci_ringbuffer_write(struct fci_ringbuffer *rbuf
  46. , const u8 *buf, size_t len);
  47. extern ssize_t fci_ringbuffer_pkt_write(struct fci_ringbuffer *rbuf
  48. , u8 *buf, size_t len);
  49. extern ssize_t fci_ringbuffer_pkt_read_user(struct fci_ringbuffer *rbuf
  50. , size_t idx, int offset, u8 __user *buf, size_t len);
  51. extern ssize_t fci_ringbuffer_pkt_read(struct fci_ringbuffer *rbuf
  52. , size_t idx, int offset, u8 *buf, size_t len);
  53. extern void fci_ringbuffer_pkt_dispose(struct fci_ringbuffer *rbuf, size_t idx);
  54. extern ssize_t fci_ringbuffer_pkt_next(struct fci_ringbuffer *rbuf
  55. , size_t idx, size_t *pktlen);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif