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:
parent
80f8481feb
commit
6173fe7a73
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue