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
51bool update(const storage_api_t &api, uint16_t address, byte value);
52
64void updateBlock(const storage_api_t &api, uint16_t address, const byte* pFirst, const byte* pLast);
65
85uint16_t updateBlockLimitWriteOps(const storage_api_t &api, uint16_t address, const byte* pFirst, const byte* pLast, uint16_t maxWrites);
86
97template< typename T >
98static inline void updateObject(const storage_api_t &api, const T &t, uint16_t address) {
99 updateBlock(api, address, (const byte*)&t, ((const byte*)&t)+sizeof(T));
100}
101
113uint16_t loadBlock(const storage_api_t &api, int16_t address, byte *pFirst, const byte *pLast);
114
124template< typename T >
125static inline T &loadObject(const storage_api_t &api, uint16_t address, T &t ){
126 byte *pFirst = (byte*) &t;
127 const byte *pLast = pFirst + sizeof(T);
128 (void)loadBlock(api, address, pFirst, pLast);
129 return t;
130}
131
140void fillBlock(const storage_api_t &api, uint16_t address, uint16_t length, byte value);
141
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: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:98
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: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:125
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
The status struct with current values for all 'live' variables.
Definition statuses.h:36
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