From 81278ce44e907c966f179659a983f5ec97d53e9b Mon Sep 17 00:00:00 2001 From: sys64738 Date: Thu, 26 Aug 2021 19:00:58 +0000 Subject: [PATCH] Update 'Persistent storage' --- Persistent-storage.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Persistent-storage.md b/Persistent-storage.md index 7ad2c22..4bd7776 100644 --- a/Persistent-storage.md +++ b/Persistent-storage.md @@ -30,7 +30,7 @@ After this data, the "mode data table" follows, consisting of 16 entries of 12 b struct mode_data { uint16_t version; uint16_t datasize; - uint28_t flashoffset; // from beginning of flash + uint28_t flashoffset; uint4_t modeid; uint32_t data_djb2; }; @@ -40,4 +40,12 @@ The `flashoffset` is relative to the beginning of flash. `version` is the versio Mode data blocks are allocated from the start of the last flash page (which is implementation defined), filling it up, and then continuing to the block before. First, smaller mode data blocks are allocated, ending with the larger ones. -### Storage API \ No newline at end of file +### Storage API + +Each mode has a `storage` field, which is a structure describing the following items (one constant and three callback functions, used by the storage subsystem): +* "storage class": maximum size of the mode's data block +* "get size" function: gets the current size of the data as it is now +* "get data": copies the mode data into a block +* "is dirty": return true to indicate the data has been changed and should be saved on the next 'flush' + +Additionally, modes can use the `storage_mode_get_info(int mode) and `storage_mode_read(int mode, void* dest, size_t offset, size_t maxlen)` functions to query and read their saved data. `storage_mode_get_info` returns a struct containing the size of the saved data, as well as the version of the mode that saved it. \ No newline at end of file