Speeduino
Loading...
Searching...
No Matches
storage_api.h
Go to the documentation of this file.
1#pragma once
7#include <stdint.h>
8#include "statuses.h"
9
10using byte = uint8_t;
11
20 byte (*read)(uint16_t address);
21
23 void (*write)(uint16_t address, byte val);
24
31
34};
35
42
58bool update(const storage_api_t &api, uint16_t address, byte value);
59
71void updateBlock(const storage_api_t &api, uint16_t address, const byte* pFirst, const byte* pLast);
72
92uint16_t updateBlockLimitWriteOps(const storage_api_t &api, uint16_t address, const byte* pFirst, const byte* pLast, uint16_t maxWrites);
93
104template< typename T >
105static inline void updateObject(const storage_api_t &api, const T &t, uint16_t address) {
106 updateBlock(api, address, (const byte*)&t, ((const byte*)&t)+sizeof(T));
107}
108
120uint16_t loadBlock(const storage_api_t &api, int16_t address, byte *pFirst, const byte *pLast);
121
131template< typename T >
132static inline T &loadObject(const storage_api_t &api, uint16_t address, T &t ){
133 byte *pFirst = (byte*) &t;
134 const byte *pLast = pFirst + sizeof(T);
135 (void)loadBlock(api, address, pFirst, pLast);
136 return t;
137}
138
147void fillBlock(const storage_api_t &api, uint16_t address, uint16_t length, byte value);
148
uint8_t byte
Definition config_pages.h:16
static TIntegral readSerialIntegralTimeout(void)
Reads an integral type, timing out if necessary.
Definition comms.cpp:175
The statuses struct and related defines.
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.
Definition storage_api.cpp:61
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 t...
Definition storage_api.h:105
uint8_t byte
Definition storage_api.h:10
void moveBlock(const storage_api_t &api, uint16_t dest, uint16_t source, uint16_t size)
Move a block of bytes.
Definition storage_api.cpp:87
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.
Definition storage_api.cpp:47
storage_api_t getEEPROMStorageApi(void)
Create a storage_api_t instance that wraps getEEPROM()
Definition storage_api.cpp:36
static T & loadObject(const storage_api_t &api, uint16_t address, T &t)
Copy a block of data from storage into a POD object.
Definition storage_api.h:132
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 fro...
Definition storage_api.cpp:55
void fillBlock(const storage_api_t &api, uint16_t address, uint16_t length, byte value)
Fills the given block with a constant.
Definition storage_api.cpp:81
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.
Definition storage_api.cpp:73
The status struct with current values for all 'live' variables.
Definition statuses.h:24
The external storage API. This must be supported by any storage system. E.g. EEPROM,...
Definition storage_api.h:18
uint16_t(* length)(void)
Function to get the size of the address space.
Definition storage_api.h:30
byte(* read)(uint16_t address)
Function to read a single byte from storage.
Definition storage_api.h:20
uint16_t(* getMaxWriteBlockSize)(const statuses &current)
The maximum number of write operations that will be performed in one go.
Definition storage_api.h:33
void(* write)(uint16_t address, byte val)
Function to write a single byte to storage.
Definition storage_api.h:23