Hi, I'm using Atomic_FIFO library and for my application I need to know the number of elements currently in the fifo, the library itself doesn't provide any functionality that tells the fifo size so I made some changes to it. I added following two lines in the header file.
static nrf_atomic_u32_t fifo_size; uint32_t get_fifo_size();
And added some lines in the c file, shown below.
bool nrf_atfifo_item_put(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context)
{
if ((p_context->last_tail.pos.wr) == (p_context->last_tail.pos.rd))
{
nrf_atfifo_wspace_close(p_fifo);
nrf_atomic_u32_add(&fifo_size, 1); //my addition
return true;
}
return false;
}
bool nrf_atfifo_item_free(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context)
{
if ((p_context->last_head.pos.wr) == (p_context->last_head.pos.rd))
{
nrf_atfifo_rspace_close(p_fifo);
nrf_atomic_u32_sub(&fifo_size, 1); // my addition
return true;
}
return false;
}
// my addition
uint32_t get_fifo_size()
{ return fifo_size;
}
So i declared a variable and increment and decrement it on successful push/pop operations. It works fine(well, at least it seems to work fine). But now I need another fifo, and as you might have noticed, my implementation of getSize(), will count all the push/pop operations across all the fifos created. So my question is how to add getSize() function that gives the current size of the respective fifos ?
Also, how to peek at an element at the front of fifo without actually removing it ?