diff --git a/include/ring_buffer.h b/include/ring_buffer.h index d54e29a8d28..a953fafc63f 100644 --- a/include/ring_buffer.h +++ b/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) {