fci_ringbuffer.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*****************************************************************************
  2. Copyright(c) 2013 FCI Inc. All Rights Reserved
  3. File name : fci_ringbuffer.h
  4. Description : Header of Data Buffer control file
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. History :
  17. ----------------------------------------------------------------------
  18. 2010/11/25 aslan.cho initial
  19. *******************************************************************************/
  20. #ifndef __FCI_RINGBUFFER_H__
  21. #define __FCI_RINGBUFFER_H__
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #include <linux/spinlock.h>
  26. #include <linux/wait.h>
  27. struct fci_ringbuffer {
  28. u8 *data;
  29. ssize_t size;
  30. ssize_t pread;
  31. ssize_t pwrite;
  32. int error;
  33. wait_queue_head_t queue;
  34. spinlock_t lock;
  35. };
  36. #define FCI_RINGBUFFER_PKTHDRSIZE 3
  37. extern void fci_ringbuffer_init(struct fci_ringbuffer *rbuf
  38. , void *data, size_t len);
  39. extern int fci_ringbuffer_empty(struct fci_ringbuffer *rbuf);
  40. extern ssize_t fci_ringbuffer_free(struct fci_ringbuffer *rbuf);
  41. extern ssize_t fci_ringbuffer_avail(struct fci_ringbuffer *rbuf);
  42. extern void fci_ringbuffer_reset(struct fci_ringbuffer *rbuf);
  43. extern void fci_ringbuffer_flush(struct fci_ringbuffer *rbuf);
  44. extern void fci_ringbuffer_flush_spinlock_wakeup(struct fci_ringbuffer *rbuf);
  45. #define FCI_RINGBUFFER_PEEK(rbuf, offs) \
  46. ((rbuf)->data[((rbuf)->pread+(offs)) % (rbuf)->size])
  47. #define FCI_RINGBUFFER_SKIP(rbuf, num) \
  48. ((rbuf)->pread = ((rbuf)->pread+(num)) % (rbuf)->size)
  49. extern ssize_t fci_ringbuffer_read_user(struct fci_ringbuffer *rbuf
  50. , u8 __user *buf, size_t len);
  51. extern void fci_ringbuffer_read(struct fci_ringbuffer *rbuf
  52. , u8 *buf, size_t len);
  53. #define FCI_RINGBUFFER_WRITE_BYTE(rbuf, byte) \
  54. { (rbuf)->data[(rbuf)->pwrite] = (byte); \
  55. (rbuf)->pwrite = ((rbuf)->pwrite + 1) % (rbuf)->size; }
  56. extern ssize_t fci_ringbuffer_write(struct fci_ringbuffer *rbuf
  57. , const u8 *buf, size_t len);
  58. extern ssize_t fci_ringbuffer_pkt_write(struct fci_ringbuffer *rbuf
  59. , u8 *buf, size_t len);
  60. extern ssize_t fci_ringbuffer_pkt_read_user(struct fci_ringbuffer *rbuf
  61. , size_t idx, int offset, u8 __user *buf, size_t len);
  62. extern ssize_t fci_ringbuffer_pkt_read(struct fci_ringbuffer *rbuf
  63. , size_t idx, int offset, u8 *buf, size_t len);
  64. extern void fci_ringbuffer_pkt_dispose(struct fci_ringbuffer *rbuf, size_t idx);
  65. extern ssize_t fci_ringbuffer_pkt_next(struct fci_ringbuffer *rbuf
  66. , size_t idx, size_t *pktlen);
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif