Speeduino
Loading...
Searching...
No Matches
storage_api.h
Go to the documentation of this file.
1#pragma once
7#include <stdint.h>
8
9// Forward declare
10struct statuses;
11
12using byte = uint8_t;
13
22 byte (*read)(uint16_t address);
23
25 void (*write)(uint16_t address, byte val);
26
33
36};
37
53bool update(const storage_api_t &api, uint16_t address, byte value);
54
66void updateBlock(const storage_api_t &api, uint16_t address, const byte* pFirst, const byte* pLast);
67
87uint16_t updateBlockLimitWriteOps(const storage_api_t &api, uint16_t address, const byte* pFirst, const byte* pLast, uint16_t maxWrites);
88
99template< typename T >
100static inline void updateObject(const storage_api_t &api, const T &t, uint16_t address) {
101 updateBlock(api, address, (const byte*)&t, ((const byte*)&t)+sizeof(T));
102}
103
115uint16_t loadBlock(const storage_api_t &api, int16_t address, byte *pFirst, const byte *pLast);
116
126template< typename T >
127static inline T &loadObject(const storage_api_t &api, uint16_t address, T &t ){
128 byte *pFirst = (byte*) &t;
129 const byte *pLast = pFirst + sizeof(T);
130 (void)loadBlock(api, address, pFirst, pLast);
131 return t;
132}
133
142void fillBlock(const storage_api_t &api, uint16_t address, uint16_t length, byte value);
143
uint8_t byte
Definition config_pages.h:16
const config2 const config4 const config6 statuses & current
Definition scheduler_fuel_controller.cpp:506
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:21
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:100
uint8_t byte
Definition storage_api.h:12
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:47
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:7
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:127
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:15
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:41
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:33
Definition array.h:14
The status struct with current values for all 'live' variables.
Definition statuses.h:47
The external storage API. This must be supported by any storage system. E.g. EEPROM,...
Definition storage_api.h:20
uint16_t(* length)(void)
Function to get the size of the address space.
Definition storage_api.h:32
byte(* read)(uint16_t address)
Function to read a single byte from storage.
Definition storage_api.h:22
uint16_t(* getMaxWriteBlockSize)(const statuses &current)
The maximum number of write operations that will be performed in one go.
Definition storage_api.h:35
void(* write)(uint16_t address, byte val)
Function to write a single byte to storage.
Definition storage_api.h:25