Manage FIFO implemented in a non-volatile flash NOR memory

37 views Asked by At

I want to implement a circular FIFO in an external NOR flash memory. Implementing the FIFO per se is not a problem, and by making it circular I make sure not to write/erase always on the same sector.

However, I don't see how to manage the storage in the flash memory of the pointers to the head and tail of the FIFO without having to write/erase the same sector (the one that would store those pointers) all the time. For me it is important to be able to store in flash memory the location of the head and tail of the FIFO in order to be able to restore the FIFO after a reset or a power reset.

Any ideas or hints on how to manage the pointers storage?

Thanks in advance.

1

There are 1 answers

0
Clifford On

One solution is store an index with each record in the flash, and on start-up, scan the memory to find the lowest and highest index value and then initialise and maintain the head/tail pointers in RAM.

An alternative to using an index is to use a timestamp (which you may already have in the data) - so long as it is a monotonically increasing value.

For this to work, the erased value of the flash (normally 0xFFFFFFFF, but 0x00000000 on some devices) cannot be a valid index. If using a 32-bit value this may not be a problem but smaller types may require specific handling.