ring_buffer: Add functions for getting capacity and reseting

Extend ring_buffer with following functions:
- getting capacity of the ring buffer (which is smaller than
  buffer size)
- resetting ring buffer to initial state

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2019-02-06 16:47:29 +01:00 committed by Anas Nashif
parent 80f8481feb
commit 6173fe7a73
1 changed files with 26 additions and 0 deletions

View File

@ -195,6 +195,19 @@ static inline int ring_buf_is_empty(struct ring_buf *buf)
{
return (buf->head == buf->tail);
}
/**
* @brief Reset ring buffer state.
*
* @param buf Address of ring buffer.
*/
static inline void ring_buf_reset(struct ring_buf *buf)
{
buf->head = 0;
buf->tail = 0;
memset(&buf->misc, 0, sizeof(buf->misc));
}
/** @deprecated Renamed to ring_buf_is_empty. */
__deprecated static inline int sys_ring_buf_is_empty(struct ring_buf *buf)
{
@ -213,6 +226,19 @@ static inline int ring_buf_space_get(struct ring_buf *buf)
return z_ring_buf_custom_space_get(buf->size, buf->head, buf->tail);
}
/**
* @brief Return ring buffer capacity.
*
* @param buf Address of ring buffer.
*
* @return Ring buffer capacity (in 32-bit words or bytes).
*/
static inline int ring_buf_capacity_get(struct ring_buf *buf)
{
/* One element is used to distinguish between empty and full state. */
return buf->size - 1;
}
/** @deprecated Renamed to ring_buf_space_get. */
__deprecated static inline int sys_ring_buf_space_get(struct ring_buf *buf)
{