Skip to content
Permalink
Browse files

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>
  • Loading branch information...
nordic-krch authored and nashif committed Feb 6, 2019
1 parent 80f8481 commit 6173fe7a73a8823cde971c5145dc59a504c39a86
Showing with 26 additions and 0 deletions.
  1. +26 −0 include/ring_buffer.h
@@ -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)
{

0 comments on commit 6173fe7

Please sign in to comment.
You can’t perform that action at this time.