From 4a2122fa9e0e851ad5115a5cb0f5383b038b4b0c Mon Sep 17 00:00:00 2001 From: Cristian Carreras Date: Wed, 3 Nov 2021 23:09:33 -0300 Subject: [PATCH] add function fifo_count --- FIFO.c | 6 ++++++ FIFO.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/FIFO.c b/FIFO.c index 89b50c5..99e664d 100644 --- a/FIFO.c +++ b/FIFO.c @@ -146,3 +146,9 @@ static void fifo_copy_to(fifo_t fifo, const void *item) fifo->writeoffset = 0; } } + +int fifo_count(fifo_t fifo){ + uint8_t fifo_len; + fifo_len = fifo->storedbytes/fifo->itemsize; + return fifo_len; +} \ No newline at end of file diff --git a/FIFO.h b/FIFO.h index 90b52f0..7d96ad2 100644 --- a/FIFO.h +++ b/FIFO.h @@ -209,6 +209,13 @@ extern "C" { */ bool fifo_discard(fifo_t fifo, uint16_t count, enum fifo_side side); + /*! + * @brief this function returns the number of elements in the FIFO + * @param fifo pointer to the FIFO + * @return the number of elements in the FIFO + */ + int fifo_count(fifo_t fifo); + #ifdef __cplusplus } #endif