![]() |
Speeduino
|
Defines the required external storage API plus some convenience functions built around that API. More...

Go to the source code of this file.
Classes | |
| struct | storage_api_t |
| The external storage API. This must be supported by any storage system. E.g. EEPROM, SPI. More... | |
Typedefs | |
| using | byte = uint8_t |
Functions | |
| storage_api_t | getEEPROMStorageApi (void) |
| Create a storage_api_t instance that wraps getEEPROM() | |
| bool | update (const storage_api_t &api, uint16_t address, byte value) |
| Conditionally write a byte to storage if it differs from the one already saved. | |
| void | updateBlock (const storage_api_t &api, uint16_t address, const byte *pFirst, const byte *pLast) |
| Conditionally write bytes from block of memory to storage. Values are written only if they differ from the one already saved at the same address. | |
| uint16_t | updateBlockLimitWriteOps (const storage_api_t &api, uint16_t address, const byte *pFirst, const byte *pLast, uint16_t maxWrites) |
| Conditionally write bytes from block of memory to storage, with a limited number of write operations. | |
| template<typename T > | |
| static void | updateObject (const storage_api_t &api, const T &t, uint16_t address) |
| Conditionally write bytes from a POD object to storage. Values are written only if they differ from the one already saved at the same address. | |
| uint16_t | loadBlock (const storage_api_t &api, int16_t address, byte *pFirst, const byte *pLast) |
| Copy a block of data from storage to memory. | |
| template<typename T > | |
| static T & | loadObject (const storage_api_t &api, uint16_t address, T &t) |
| Copy a block of data from storage into a POD object. | |
| void | fillBlock (const storage_api_t &api, uint16_t address, uint16_t length, byte value) |
| Fills the given block with a constant. | |
| void | moveBlock (const storage_api_t &api, uint16_t dest, uint16_t source, uint16_t size) |
| Move a block of bytes. | |
Defines the required external storage API plus some convenience functions built around that API.
Fills the given block with a constant.
| api | Raw storage API |
| address | the location to begin writing to (zero based) |
| length | number of bytes to write |
| value | fill value |


| storage_api_t getEEPROMStorageApi | ( | void | ) |
Create a storage_api_t instance that wraps getEEPROM()
Applies the adapter pattern to provide storage_api_t from EEPROM_t


| uint16_t loadBlock | ( | const storage_api_t & | api, |
| int16_t | address, | ||
| byte * | pFirst, | ||
| const byte * | pLast | ||
| ) |
Copy a block of data from storage to memory.
This is essentially the opposite of updateBlock()
| api | Raw storage API |
| address | the location to begin reading from (zero based) |
| pFirst | Points to the start of the memory block |
| pLast | Points to one byte past the end of the block |


Copy a block of data from storage into a POD object.
| T | - must be a POD type |
| api | Raw storage API |
| address | the location to begin reading from (zero based) |
| t | Object to write to |


Move a block of bytes.
This will handle overlapping blocks. I.e. if [dest, size) overlaps [source, size)
| api | Raw storage API |
| dest | Address to copy to |
| source | Address to copy from |
| size | number of bytes to copy |

| bool update | ( | const storage_api_t & | api, |
| uint16_t | address, | ||
| byte | value | ||
| ) |
Conditionally write a byte to storage if it differs from the one already saved.
Background: some storage hardware has a limited number of write cycles per cell. E.g. flash memory can only withstand a certain number of write/erase cycles before it begins to wear out and can no longer reliably store data. This is typically in the range of 3000-5000 cycles for multi-level cell (MLC) NAND flash, or 10,000-100,000 cycles for single-level cell (SLC) NAND flash. So we want to limit writes as much as possible. Hence this function.
| api | Raw storage API |
| address | the location to write to (zero based) |
| value | the value to write |


| void updateBlock | ( | const storage_api_t & | api, |
| uint16_t | address, | ||
| const byte * | pFirst, | ||
| const byte * | pLast | ||
| ) |
Conditionally write bytes from block of memory to storage. Values are written only if they differ from the one already saved at the same address.
address+(pLast-pFirst) < api.length(). I.e. that the block fits into the address space. | api | Raw storage API |
| address | the location to begin writing to (zero based) |
| pFirst | Points to the start of the memory block |
| pLast | Points to one byte past the end of the block |


| uint16_t updateBlockLimitWriteOps | ( | const storage_api_t & | api, |
| uint16_t | address, | ||
| const byte * | pFirst, | ||
| const byte * | pLast, | ||
| uint16_t | maxWrites | ||
| ) |
Conditionally write bytes from block of memory to storage, with a limited number of write operations.
Write operations are typically pretty slow (E.g. 3.3ms on AVR EEPROM). If a block contains many bytes that need to be written, we can cause the system to stutter as the main loop stalls waiting for writes to complete. So instead we limit the number of write operations per call to this function.
| api | Raw storage API |
| address | the location to begin writing to (zero based) |
| pFirst | Points to the start of the memory block |
| pLast | Points to one byte past the end of the block |
| maxWrites | Maximum number of write operations. |


Conditionally write bytes from a POD object to storage. Values are written only if they differ from the one already saved at the same address.
This is purely a convenience function
| T | - must be a POD type |
| api | Raw storage API |
| t | Object to write |
| address | the location to begin writing to (zero based) |

