Hi, I implemented this and want to know what you guys think of the interface.
FCB is a facility that allows you to store blobs of data in flash a bit like a FIFO. You always append things in the end, and you start reading things from beginning. This is to be used when you want to e.g. keep a log of events and have them persist over a system reset. Data always gets added in the end; you would start by calling fcb_append() with the amount of data you’ll want to add. That function reserves space in the flash, and would return you info about where in the flash data would be. After that, you would write the data element to that location, and finish by calling fcb_append_finish(). This function finalizes the write by computing a checksum over the data, and appending the checkup to the end. That is how user is protected against partial writes (system reset before all data gets in). For inspecting the data in flash, there’s 2 options: either fcb_walk(), or fcb_getnext(). fcb_walk() walks over the data elements in the flash, calling user specified callback for every (completed) element it encounters. If you want to stop the walk, you can tell it using non-zero return code from your callback. fcb_getnext() can be used similarly to fcb_walk(), it takes as a parameter the location of previous element, and gives you in return the location of next element in the circular buffer. Flash sectors fill up eventually. The way you’d deal with this is by erasing data a sector at a time, calling fcb_rotate() erases the data in the oldest sector you’ve been using. So for a rolling log you would keep appending data until you can fit no more, then erase the oldest one and add some more. For places where you download/upload the data periodically, you would erase the sector once data from it has been stored somewhere safe. Any comments, suggestions? — M
