RingBuffer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: RingBuffer.h
  4. * Description: Ring buffer to connect the SDF to audio sources and sinks
  5. *
  6. * $Date: 30 July 2021
  7. * $Revision: V1.10.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #ifndef _RINGBUFFER_H_
  29. #define _RINGBUFFER_H_
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. typedef enum {
  35. kErrorOverflowUnderflow=-1,
  36. kTimeout=-2,
  37. kErrorHWOverlowUnderflow=-3,
  38. kNoError=0
  39. } ring_error_t;
  40. typedef struct {
  41. uint8_t *buffer;
  42. uint32_t userBufferStatus;
  43. uint32_t intBufferStatus;
  44. int32_t nbBuffers;
  45. uint32_t bufferSize;
  46. int32_t interruptBufferIDStart;
  47. int32_t interruptBufferIDStop;
  48. int32_t userBufferIDStart;
  49. int32_t userBufferIDStop;
  50. int32_t waiting;
  51. int timeout;
  52. ring_error_t error;
  53. int interruptID;
  54. } ring_config_t;
  55. /**
  56. * @brief Ring buffer initialization
  57. * @param[in, out] buf ring buffer configuration.
  58. * @param[in] nbBuffers number of buffers (max 32)
  59. * @param[in] bufferSize size of each buffer in bytes
  60. * @param[in] buffer array for the buffer storage (bufferSize*nbBuffers)
  61. * @param[in] interruptID interrupt ID
  62. * @param[in] timeout timeout (meaning is RTOS dependent)
  63. * @return Nothing
  64. */
  65. void ringInit(ring_config_t *buf,
  66. uint32_t nbBuffers,
  67. uint32_t bufferSize,
  68. uint8_t *buffer,
  69. int interruptID,
  70. int timeout);
  71. void ringClean(ring_config_t *buf);
  72. /*
  73. Try to reserve a buffer from a user thread.
  74. */
  75. int ringUserReserveBuffer(ring_config_t *buf);
  76. /*
  77. Release a buffer from user htread
  78. */
  79. void ringUserReleaseBuffer(ring_config_t *buf);
  80. /*
  81. Reserve a buffer from interrupt
  82. */
  83. int ringInterruptReserveBuffer(ring_config_t *buf);
  84. /*
  85. Release a buffer from interrupt
  86. */
  87. void ringInterruptReleaseBuffer(ring_config_t *buf,void *threadId);
  88. /*
  89. Get address of buffer
  90. */
  91. uint8_t *ringGetBufferAddress(ring_config_t *buf,int id);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* #ifndef _RINGBUFFER_H_*/