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