tree: d3858b64388c3ef1f56b3641663ffaa47c2ae037 [path history] [tgz]
  1. include/
  2. src/
  3. test/
  4. pkg.yml

Flash circular buffer


Storage of elements in flash in FIFO fashion. Elements are appended to the of the area until storage space is exhausted. Then the oldest sector should be erased and that can be used in storing new entries.



  • initialize fcb for a given array of flash sectors


  • reserve space to store an element fcb_append_finish()
  • storage of the element is finished; can calculate CRC for it

fcb_walk(cb, sector)

  • call cb for every element in the buffer. Or for every element in a particular flash sector, if sector is specified fcb_getnext(elem)
  • return element following elem


  • erase oldest used sector, and make it current


To add an element to circular buffer:

  1. call fcb_append() to get location; if this fails due to lack of space, call fcb_rotate()
  2. use flash_area_write() to write contents
  3. call fcb_append_finish() when done

To read contents of the circular buffer:

  1. call fcb_walk() with callback
  2. within callback: copy in data from the element using flash_area_read(), call fcb_rotate() when all elements from a given sector have been read