Giovanni wrote:I will look into it, I have some questions, I would make some adjustments, for example size_t instead of uint16_t and few other things like that.
I wondered about using size_t; felt it was best to have a defined size (since I'm sure I've come across size_t being a uint8_t, but that was a little while ago). No strong views.
Giovanni wrote:About external devices, if the idea is to make an abstract non volatile storage driver then probably it should be decoupled from the RTC, ideally you could have NVM and not an RTC. Wouldn't it make sense to have a specific nvm driver, possibly with multiple instances if more devices are present.
Alternatively a "nvm" interface could be defined and let various drivers implement it, including the RTC. Streams and block devices already do that for characters streams and storage media.
I see the nvm driver being at a higher level than the RTC driver, with RTC memory being one possible device - as you say, in much the same manner as block devices. (I already have a similar style driver for FRAM via I2C). Device support can then include a driver for any on-board EEPROM or RAM, with 'library' drivers for external NVM. Essentially it would become a block-structured driver where the user code manages the storage layout - so it should be simpler than a file system.
I'm in two minds as to the merit of an nvm driver - in my own case, I have a couple of values which I wish to save frequently - this could wear out my FRAM, so I'll hard code use of the RTC memory for these. In this situation there's no great need for a uniform interface, nor for the additional code which goes with it. (Incidentally, even though its much faster to update than EEPROM, I write to my FRAM as a background task - another potential complication for some drivers). Overall I suggest that use of the NVM driver should be optional, with the user readily able to access individual memory blocks directly via their drivers where that is preferable.