ringbuf.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "freertos/FreeRTOS.h"
  8. #include "freertos/queue.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /**
  13. * Type by which ring buffers are referenced. For example, a call to xRingbufferCreate()
  14. * returns a RingbufHandle_t variable that can then be used as a parameter to
  15. * xRingbufferSend(), xRingbufferReceive(), etc.
  16. */
  17. typedef void * RingbufHandle_t;
  18. typedef enum {
  19. /**
  20. * No-split buffers will only store an item in contiguous memory and will
  21. * never split an item. Each item requires an 8 byte overhead for a header
  22. * and will always internally occupy a 32-bit aligned size of space.
  23. */
  24. RINGBUF_TYPE_NOSPLIT = 0,
  25. /**
  26. * Allow-split buffers will split an item into two parts if necessary in
  27. * order to store it. Each item requires an 8 byte overhead for a header,
  28. * splitting incurs an extra header. Each item will always internally occupy
  29. * a 32-bit aligned size of space.
  30. */
  31. RINGBUF_TYPE_ALLOWSPLIT,
  32. /**
  33. * Byte buffers store data as a sequence of bytes and do not maintain separate
  34. * items, therefore byte buffers have no overhead. All data is stored as a
  35. * sequence of byte and any number of bytes can be sent or retrieved each
  36. * time.
  37. */
  38. RINGBUF_TYPE_BYTEBUF,
  39. RINGBUF_TYPE_MAX,
  40. } RingbufferType_t;
  41. /**
  42. * @brief Struct that is equivalent in size to the ring buffer's data structure
  43. *
  44. * The contents of this struct are not meant to be used directly. This
  45. * structure is meant to be used when creating a statically allocated ring
  46. * buffer where this struct is of the exact size required to store a ring
  47. * buffer's control data structure.
  48. *
  49. */
  50. typedef struct xSTATIC_RINGBUFFER {
  51. /** @cond */ //Doxygen command to hide this structure from API Reference
  52. size_t xDummy1[2];
  53. UBaseType_t uxDummy2;
  54. void *pvDummy3[11];
  55. BaseType_t xDummy4;
  56. StaticList_t xDummy5[2];
  57. void * pvDummy6;
  58. portMUX_TYPE muxDummy;
  59. /** @endcond */
  60. } StaticRingbuffer_t;
  61. /**
  62. * @brief Create a ring buffer
  63. *
  64. * @param[in] xBufferSize Size of the buffer in bytes. Note that items require
  65. * space for a header in no-split/allow-split buffers
  66. * @param[in] xBufferType Type of ring buffer, see documentation.
  67. *
  68. * @note xBufferSize of no-split/allow-split buffers will be rounded up to the nearest 32-bit aligned size.
  69. *
  70. * @return A handle to the created ring buffer, or NULL in case of error.
  71. */
  72. RingbufHandle_t xRingbufferCreate(size_t xBufferSize, RingbufferType_t xBufferType);
  73. /**
  74. * @brief Create a ring buffer of type RINGBUF_TYPE_NOSPLIT for a fixed item_size
  75. *
  76. * This API is similar to xRingbufferCreate(), but it will internally allocate
  77. * additional space for the headers.
  78. *
  79. * @param[in] xItemSize Size of each item to be put into the ring buffer
  80. * @param[in] xItemNum Maximum number of items the buffer needs to hold simultaneously
  81. *
  82. * @return A RingbufHandle_t handle to the created ring buffer, or NULL in case of error.
  83. */
  84. RingbufHandle_t xRingbufferCreateNoSplit(size_t xItemSize, size_t xItemNum);
  85. /**
  86. * @brief Create a ring buffer but manually provide the required memory
  87. *
  88. * @param[in] xBufferSize Size of the buffer in bytes.
  89. * @param[in] xBufferType Type of ring buffer, see documentation
  90. * @param[in] pucRingbufferStorage Pointer to the ring buffer's storage area.
  91. * Storage area must have the same size as specified by xBufferSize
  92. * @param[in] pxStaticRingbuffer Pointed to a struct of type StaticRingbuffer_t
  93. * which will be used to hold the ring buffer's data structure
  94. *
  95. * @note xBufferSize of no-split/allow-split buffers MUST be 32-bit aligned.
  96. *
  97. * @return A handle to the created ring buffer
  98. */
  99. RingbufHandle_t xRingbufferCreateStatic(size_t xBufferSize,
  100. RingbufferType_t xBufferType,
  101. uint8_t *pucRingbufferStorage,
  102. StaticRingbuffer_t *pxStaticRingbuffer);
  103. /**
  104. * @brief Insert an item into the ring buffer
  105. *
  106. * Attempt to insert an item into the ring buffer. This function will block until
  107. * enough free space is available or until it times out.
  108. *
  109. * @param[in] xRingbuffer Ring buffer to insert the item into
  110. * @param[in] pvItem Pointer to data to insert. NULL is allowed if xItemSize is 0.
  111. * @param[in] xItemSize Size of data to insert.
  112. * @param[in] xTicksToWait Ticks to wait for room in the ring buffer.
  113. *
  114. * @note For no-split/allow-split ring buffers, the actual size of memory that
  115. * the item will occupy will be rounded up to the nearest 32-bit aligned
  116. * size. This is done to ensure all items are always stored in 32-bit
  117. * aligned fashion.
  118. * @note For no-split/allow-split buffers, an xItemSize of 0 will result in
  119. * an item with no data being set (i.e., item only contains the header).
  120. * For byte buffers, an xItemSize of 0 will simply return pdTRUE without
  121. * copying any data.
  122. *
  123. * @return
  124. * - pdTRUE if succeeded
  125. * - pdFALSE on time-out or when the data is larger than the maximum permissible size of the buffer
  126. */
  127. BaseType_t xRingbufferSend(RingbufHandle_t xRingbuffer,
  128. const void *pvItem,
  129. size_t xItemSize,
  130. TickType_t xTicksToWait);
  131. /**
  132. * @brief Insert an item into the ring buffer in an ISR
  133. *
  134. * Attempt to insert an item into the ring buffer from an ISR. This function
  135. * will return immediately if there is insufficient free space in the buffer.
  136. *
  137. * @param[in] xRingbuffer Ring buffer to insert the item into
  138. * @param[in] pvItem Pointer to data to insert. NULL is allowed if xItemSize is 0.
  139. * @param[in] xItemSize Size of data to insert.
  140. * @param[out] pxHigherPriorityTaskWoken Value pointed to will be set to pdTRUE if the function woke up a higher priority task.
  141. *
  142. * @note For no-split/allow-split ring buffers, the actual size of memory that
  143. * the item will occupy will be rounded up to the nearest 32-bit aligned
  144. * size. This is done to ensure all items are always stored in 32-bit
  145. * aligned fashion.
  146. * @note For no-split/allow-split buffers, an xItemSize of 0 will result in
  147. * an item with no data being set (i.e., item only contains the header).
  148. * For byte buffers, an xItemSize of 0 will simply return pdTRUE without
  149. * copying any data.
  150. *
  151. * @return
  152. * - pdTRUE if succeeded
  153. * - pdFALSE when the ring buffer does not have space.
  154. */
  155. BaseType_t xRingbufferSendFromISR(RingbufHandle_t xRingbuffer,
  156. const void *pvItem,
  157. size_t xItemSize,
  158. BaseType_t *pxHigherPriorityTaskWoken);
  159. /**
  160. * @brief Acquire memory from the ring buffer to be written to by an external
  161. * source and to be sent later.
  162. *
  163. * Attempt to allocate buffer for an item to be sent into the ring buffer. This
  164. * function will block until enough free space is available or until it
  165. * times out.
  166. *
  167. * The item, as well as the following items ``SendAcquire`` or ``Send`` after it,
  168. * will not be able to be read from the ring buffer until this item is actually
  169. * sent into the ring buffer.
  170. *
  171. * @param[in] xRingbuffer Ring buffer to allocate the memory
  172. * @param[out] ppvItem Double pointer to memory acquired (set to NULL if no memory were retrieved)
  173. * @param[in] xItemSize Size of item to acquire.
  174. * @param[in] xTicksToWait Ticks to wait for room in the ring buffer.
  175. *
  176. * @note Only applicable for no-split ring buffers now, the actual size of
  177. * memory that the item will occupy will be rounded up to the nearest 32-bit
  178. * aligned size. This is done to ensure all items are always stored in 32-bit
  179. * aligned fashion.
  180. * @note An xItemSize of 0 will result in a buffer being acquired, but the buffer
  181. * will have a size of 0.
  182. *
  183. * @return
  184. * - pdTRUE if succeeded
  185. * - pdFALSE on time-out or when the data is larger than the maximum permissible size of the buffer
  186. */
  187. BaseType_t xRingbufferSendAcquire(RingbufHandle_t xRingbuffer, void **ppvItem, size_t xItemSize, TickType_t xTicksToWait);
  188. /**
  189. * @brief Actually send an item into the ring buffer allocated before by
  190. * ``xRingbufferSendAcquire``.
  191. *
  192. * @param[in] xRingbuffer Ring buffer to insert the item into
  193. * @param[in] pvItem Pointer to item in allocated memory to insert.
  194. *
  195. * @note Only applicable for no-split ring buffers. Only call for items
  196. * allocated by ``xRingbufferSendAcquire``.
  197. *
  198. * @return
  199. * - pdTRUE if succeeded
  200. * - pdFALSE if fail for some reason.
  201. */
  202. BaseType_t xRingbufferSendComplete(RingbufHandle_t xRingbuffer, void *pvItem);
  203. /**
  204. * @brief Retrieve an item from the ring buffer
  205. *
  206. * Attempt to retrieve an item from the ring buffer. This function will block
  207. * until an item is available or until it times out.
  208. *
  209. * @param[in] xRingbuffer Ring buffer to retrieve the item from
  210. * @param[out] pxItemSize Pointer to a variable to which the size of the retrieved item will be written.
  211. * @param[in] xTicksToWait Ticks to wait for items in the ring buffer.
  212. *
  213. * @note A call to vRingbufferReturnItem() is required after this to free the item retrieved.
  214. * @note It is possible to receive items with a pxItemSize of 0 on no-split/allow split buffers.
  215. *
  216. * @return
  217. * - Pointer to the retrieved item on success; *pxItemSize filled with the length of the item.
  218. * - NULL on timeout, *pxItemSize is untouched in that case.
  219. */
  220. void *xRingbufferReceive(RingbufHandle_t xRingbuffer, size_t *pxItemSize, TickType_t xTicksToWait);
  221. /**
  222. * @brief Retrieve an item from the ring buffer in an ISR
  223. *
  224. * Attempt to retrieve an item from the ring buffer. This function returns immediately
  225. * if there are no items available for retrieval
  226. *
  227. * @param[in] xRingbuffer Ring buffer to retrieve the item from
  228. * @param[out] pxItemSize Pointer to a variable to which the size of the
  229. * retrieved item will be written.
  230. *
  231. * @note A call to vRingbufferReturnItemFromISR() is required after this to free the item retrieved.
  232. * @note Byte buffers do not allow multiple retrievals before returning an item
  233. * @note Two calls to RingbufferReceiveFromISR() are required if the bytes wrap around the end of the ring buffer.
  234. * @note It is possible to receive items with a pxItemSize of 0 on no-split/allow split buffers.
  235. *
  236. * @return
  237. * - Pointer to the retrieved item on success; *pxItemSize filled with the length of the item.
  238. * - NULL when the ring buffer is empty, *pxItemSize is untouched in that case.
  239. */
  240. void *xRingbufferReceiveFromISR(RingbufHandle_t xRingbuffer, size_t *pxItemSize);
  241. /**
  242. * @brief Retrieve a split item from an allow-split ring buffer
  243. *
  244. * Attempt to retrieve a split item from an allow-split ring buffer. If the item
  245. * is not split, only a single item is retried. If the item is split, both parts
  246. * will be retrieved. This function will block until an item is available or
  247. * until it times out.
  248. *
  249. * @param[in] xRingbuffer Ring buffer to retrieve the item from
  250. * @param[out] ppvHeadItem Double pointer to first part (set to NULL if no items were retrieved)
  251. * @param[out] ppvTailItem Double pointer to second part (set to NULL if item is not split)
  252. * @param[out] pxHeadItemSize Pointer to size of first part (unmodified if no items were retrieved)
  253. * @param[out] pxTailItemSize Pointer to size of second part (unmodified if item is not split)
  254. * @param[in] xTicksToWait Ticks to wait for items in the ring buffer.
  255. *
  256. * @note Call(s) to vRingbufferReturnItem() is required after this to free up the item(s) retrieved.
  257. * @note This function should only be called on allow-split buffers
  258. * @note It is possible to receive items with a pxItemSize of 0 on allow split buffers.
  259. *
  260. * @return
  261. * - pdTRUE if an item (split or unsplit) was retrieved
  262. * - pdFALSE when no item was retrieved
  263. */
  264. BaseType_t xRingbufferReceiveSplit(RingbufHandle_t xRingbuffer,
  265. void **ppvHeadItem,
  266. void **ppvTailItem,
  267. size_t *pxHeadItemSize,
  268. size_t *pxTailItemSize,
  269. TickType_t xTicksToWait);
  270. /**
  271. * @brief Retrieve a split item from an allow-split ring buffer in an ISR
  272. *
  273. * Attempt to retrieve a split item from an allow-split ring buffer. If the item
  274. * is not split, only a single item is retried. If the item is split, both parts
  275. * will be retrieved. This function returns immediately if there are no items
  276. * available for retrieval
  277. *
  278. * @param[in] xRingbuffer Ring buffer to retrieve the item from
  279. * @param[out] ppvHeadItem Double pointer to first part (set to NULL if no items were retrieved)
  280. * @param[out] ppvTailItem Double pointer to second part (set to NULL if item is not split)
  281. * @param[out] pxHeadItemSize Pointer to size of first part (unmodified if no items were retrieved)
  282. * @param[out] pxTailItemSize Pointer to size of second part (unmodified if item is not split)
  283. *
  284. * @note Calls to vRingbufferReturnItemFromISR() is required after this to free up the item(s) retrieved.
  285. * @note This function should only be called on allow-split buffers
  286. * @note It is possible to receive items with a pxItemSize of 0 on allow split buffers.
  287. *
  288. * @return
  289. * - pdTRUE if an item (split or unsplit) was retrieved
  290. * - pdFALSE when no item was retrieved
  291. */
  292. BaseType_t xRingbufferReceiveSplitFromISR(RingbufHandle_t xRingbuffer,
  293. void **ppvHeadItem,
  294. void **ppvTailItem,
  295. size_t *pxHeadItemSize,
  296. size_t *pxTailItemSize);
  297. /**
  298. * @brief Retrieve bytes from a byte buffer, specifying the maximum amount of bytes to retrieve
  299. *
  300. * Attempt to retrieve data from a byte buffer whilst specifying a maximum number
  301. * of bytes to retrieve. This function will block until there is data available
  302. * for retrieval or until it times out.
  303. *
  304. * @param[in] xRingbuffer Ring buffer to retrieve the item from
  305. * @param[out] pxItemSize Pointer to a variable to which the size of the retrieved item will be written.
  306. * @param[in] xTicksToWait Ticks to wait for items in the ring buffer.
  307. * @param[in] xMaxSize Maximum number of bytes to return.
  308. *
  309. * @note A call to vRingbufferReturnItem() is required after this to free up the data retrieved.
  310. * @note This function should only be called on byte buffers
  311. * @note Byte buffers do not allow multiple retrievals before returning an item
  312. * @note Two calls to RingbufferReceiveUpTo() are required if the bytes wrap around the end of the ring buffer.
  313. *
  314. * @return
  315. * - Pointer to the retrieved item on success; *pxItemSize filled with
  316. * the length of the item.
  317. * - NULL on timeout, *pxItemSize is untouched in that case.
  318. */
  319. void *xRingbufferReceiveUpTo(RingbufHandle_t xRingbuffer,
  320. size_t *pxItemSize,
  321. TickType_t xTicksToWait,
  322. size_t xMaxSize);
  323. /**
  324. * @brief Retrieve bytes from a byte buffer, specifying the maximum amount of
  325. * bytes to retrieve. Call this from an ISR.
  326. *
  327. * Attempt to retrieve bytes from a byte buffer whilst specifying a maximum number
  328. * of bytes to retrieve. This function will return immediately if there is no data
  329. * available for retrieval.
  330. *
  331. * @param[in] xRingbuffer Ring buffer to retrieve the item from
  332. * @param[out] pxItemSize Pointer to a variable to which the size of the retrieved item will be written.
  333. * @param[in] xMaxSize Maximum number of bytes to return. Size of 0 simply returns NULL.
  334. *
  335. * @note A call to vRingbufferReturnItemFromISR() is required after this to free up the data received.
  336. * @note This function should only be called on byte buffers
  337. * @note Byte buffers do not allow multiple retrievals before returning an item
  338. *
  339. * @return
  340. * - Pointer to the retrieved item on success; *pxItemSize filled with
  341. * the length of the item.
  342. * - NULL when the ring buffer is empty, *pxItemSize is untouched in that case.
  343. */
  344. void *xRingbufferReceiveUpToFromISR(RingbufHandle_t xRingbuffer, size_t *pxItemSize, size_t xMaxSize);
  345. /**
  346. * @brief Return a previously-retrieved item to the ring buffer
  347. *
  348. * @param[in] xRingbuffer Ring buffer the item was retrieved from
  349. * @param[in] pvItem Item that was received earlier
  350. *
  351. * @note If a split item is retrieved, both parts should be returned by calling this function twice
  352. */
  353. void vRingbufferReturnItem(RingbufHandle_t xRingbuffer, void *pvItem);
  354. /**
  355. * @brief Return a previously-retrieved item to the ring buffer from an ISR
  356. *
  357. * @param[in] xRingbuffer Ring buffer the item was retrieved from
  358. * @param[in] pvItem Item that was received earlier
  359. * @param[out] pxHigherPriorityTaskWoken Value pointed to will be set to pdTRUE
  360. * if the function woke up a higher priority task.
  361. *
  362. * @note If a split item is retrieved, both parts should be returned by calling this function twice
  363. */
  364. void vRingbufferReturnItemFromISR(RingbufHandle_t xRingbuffer, void *pvItem, BaseType_t *pxHigherPriorityTaskWoken);
  365. /**
  366. * @brief Delete a ring buffer
  367. *
  368. * @param[in] xRingbuffer Ring buffer to delete
  369. *
  370. * @note This function will not deallocate any memory if the ring buffer was
  371. * created using xRingbufferCreateStatic(). Deallocation must be done
  372. * manually be the user.
  373. */
  374. void vRingbufferDelete(RingbufHandle_t xRingbuffer);
  375. /**
  376. * @brief Get maximum size of an item that can be placed in the ring buffer
  377. *
  378. * This function returns the maximum size an item can have if it was placed in
  379. * an empty ring buffer.
  380. *
  381. * @param[in] xRingbuffer Ring buffer to query
  382. *
  383. * @note The max item size for a no-split buffer is limited to
  384. * ((buffer_size/2)-header_size). This limit is imposed so that an item
  385. * of max item size can always be sent to an empty no-split buffer
  386. * regardless of the internal positions of the buffer's read/write/free
  387. * pointers.
  388. *
  389. * @return Maximum size, in bytes, of an item that can be placed in a ring buffer.
  390. */
  391. size_t xRingbufferGetMaxItemSize(RingbufHandle_t xRingbuffer);
  392. /**
  393. * @brief Get current free size available for an item/data in the buffer
  394. *
  395. * This gives the real time free space available for an item/data in the ring
  396. * buffer. This represents the maximum size an item/data can have if it was
  397. * currently sent to the ring buffer.
  398. *
  399. * @warning This API is not thread safe. So, if multiple threads are accessing
  400. * the same ring buffer, it is the application's responsibility to
  401. * ensure atomic access to this API and the subsequent Send
  402. *
  403. * @note An empty no-split buffer has a max current free size for an item
  404. * that is limited to ((buffer_size/2)-header_size). See API reference
  405. * for xRingbufferGetMaxItemSize().
  406. *
  407. * @param[in] xRingbuffer Ring buffer to query
  408. *
  409. * @return Current free size, in bytes, available for an entry
  410. */
  411. size_t xRingbufferGetCurFreeSize(RingbufHandle_t xRingbuffer);
  412. /**
  413. * @brief Add the ring buffer to a queue set. Notified when data has been written to the ring buffer
  414. *
  415. * This function adds the ring buffer to a queue set, thus allowing a task to
  416. * block on multiple queues/ring buffers. The queue set is notified when the new
  417. * data becomes available to read on the ring buffer.
  418. *
  419. * @param[in] xRingbuffer Ring buffer to add to the queue set
  420. * @param[in] xQueueSet Queue set to add the ring buffer to
  421. *
  422. * @return
  423. * - pdTRUE on success, pdFALSE otherwise
  424. */
  425. BaseType_t xRingbufferAddToQueueSetRead(RingbufHandle_t xRingbuffer, QueueSetHandle_t xQueueSet);
  426. /**
  427. * @brief Check if the selected queue set member is a particular ring buffer
  428. *
  429. * This API checks if queue set member returned from xQueueSelectFromSet() is
  430. * a particular ring buffer. If so, this indicates the ring buffer has items
  431. * waiting to be retrieved.
  432. *
  433. * @param[in] xRingbuffer Ring buffer to check
  434. * @param[in] xMember Member returned from xQueueSelectFromSet
  435. *
  436. * @return
  437. * - pdTRUE when selected queue set member is the ring buffer
  438. * - pdFALSE otherwise.
  439. */
  440. static inline BaseType_t xRingbufferCanRead(RingbufHandle_t xRingbuffer, QueueSetMemberHandle_t xMember)
  441. {
  442. return (xMember == (QueueSetMemberHandle_t)xRingbuffer) ? pdTRUE : pdFALSE;
  443. }
  444. /**
  445. * @brief Remove the ring buffer from a queue set
  446. *
  447. * This function removes a ring buffer from a queue set. The ring buffer must have been previously added to the queue
  448. * set using xRingbufferAddToQueueSetRead().
  449. *
  450. * @param[in] xRingbuffer Ring buffer to remove from the queue set
  451. * @param[in] xQueueSet Queue set to remove the ring buffer from
  452. *
  453. * @return
  454. * - pdTRUE on success
  455. * - pdFALSE otherwise
  456. */
  457. BaseType_t xRingbufferRemoveFromQueueSetRead(RingbufHandle_t xRingbuffer, QueueSetHandle_t xQueueSet);
  458. /**
  459. * @brief Get information about ring buffer status
  460. *
  461. * Get information of a ring buffer's current status such as
  462. * free/read/write/acquire pointer positions, and number of items waiting to be retrieved.
  463. * Arguments can be set to NULL if they are not required.
  464. *
  465. * @param[in] xRingbuffer Ring buffer to remove from the queue set
  466. * @param[out] uxFree Pointer use to store free pointer position
  467. * @param[out] uxRead Pointer use to store read pointer position
  468. * @param[out] uxWrite Pointer use to store write pointer position
  469. * @param[out] uxAcquire Pointer use to store acquire pointer position
  470. * @param[out] uxItemsWaiting Pointer use to store number of items (bytes for byte buffer) waiting to be retrieved
  471. */
  472. void vRingbufferGetInfo(RingbufHandle_t xRingbuffer,
  473. UBaseType_t *uxFree,
  474. UBaseType_t *uxRead,
  475. UBaseType_t *uxWrite,
  476. UBaseType_t *uxAcquire,
  477. UBaseType_t *uxItemsWaiting);
  478. /**
  479. * @brief Debugging function to print the internal pointers in the ring buffer
  480. *
  481. * @param xRingbuffer Ring buffer to show
  482. */
  483. void xRingbufferPrintInfo(RingbufHandle_t xRingbuffer);
  484. /**
  485. * @brief Retrieve the pointers to a statically created ring buffer
  486. *
  487. * @param[in] xRingbuffer Ring buffer
  488. * @param[out] ppucRingbufferStorage Used to return a pointer to the queue's storage area buffer
  489. * @param[out] ppxStaticRingbuffer Used to return a pointer to the queue's data structure buffer
  490. * @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
  491. */
  492. BaseType_t xRingbufferGetStaticBuffer(RingbufHandle_t xRingbuffer, uint8_t **ppucRingbufferStorage, StaticRingbuffer_t **ppxStaticRingbuffer);
  493. /**
  494. * @brief Creates a ring buffer with specific memory capabilities
  495. *
  496. * This function is similar to xRingbufferCreate(), except that it allows the
  497. * memory allocated for the ring buffer to have specific capabilities (e.g.,
  498. * MALLOC_CAP_INTERNAL).
  499. *
  500. * @note A queue created using this function must only be deleted using
  501. * vRingbufferDeleteWithCaps()
  502. * @param[in] xBufferSize Size of the buffer in bytes
  503. * @param[in] xBufferType Type of ring buffer, see documentation.
  504. * @param[in] uxMemoryCaps Memory capabilities of the queue's memory (see
  505. * esp_heap_caps.h)
  506. * @return Handle to the created ring buffer or NULL on failure.
  507. */
  508. RingbufHandle_t xRingbufferCreateWithCaps(size_t xBufferSize, RingbufferType_t xBufferType, UBaseType_t uxMemoryCaps);
  509. /**
  510. * @brief Deletes a ring buffer previously created using xRingbufferCreateWithCaps()
  511. *
  512. * @param xRingbuffer Ring buffer
  513. */
  514. void vRingbufferDeleteWithCaps(RingbufHandle_t xRingbuffer);
  515. #ifdef __cplusplus
  516. }
  517. #endif