Speeduino
Loading...
Searching...
No Matches
Classes | Functions | Variables
storage.cpp File Reference
#include "globals.h"
#include "storage.h"
#include "pages.h"
#include "sensors.h"
#include "utilities.h"
#include "preprocessor.h"
#include "unit_testing.h"

Classes

struct  write_location
 

Functions

static byte default_read (uint16_t address)
 
static void default_write (uint16_t address, byte value)
 
static uint16_t default_length (void)
 
static uint16_t default_write_size (const statuses &current)
 
void setStorageAPI (const storage_api_t &api)
 Inject the external storage API.
 
const storage_api_tgetStorageAPI (void)
 Provide global access to the raw storage API.
 
bool isEepromWritePending (void)
 Do we have page data that needs to be written to durable storage?
 
void setEepromWritePending (bool isPending)
 Set or clear the Write Pending flag.
 
void saveAllPages (void)
 Write all pages from RAM to durable storage.
 
static uint16_t write_range (const byte *pStart, const byte *pEnd, uint16_t address, uint16_t writesRemaining)
 
static write_location write (const table_row_iterator &row, const write_location &location)
 
static write_location write (table_value_iterator it, write_location location)
 
static write_location write (table_axis_iterator it, write_location location)
 
static uint16_t writeTable (table3d_t *pTable, TableType key, uint16_t address, uint16_t writesRemaining)
 
void savePage (uint8_t pageNum)
 Write one page from RAM to durable storage.
 
static uint16_t load_range (uint16_t address, byte *pFirst, const byte *pLast)
 
static uint16_t load (table_row_iterator row, uint16_t address)
 
static uint16_t load (table_value_iterator it, uint16_t address)
 
static uint16_t load (table_axis_iterator it, uint16_t address)
 
static uint16_t loadTable (table3d_t *pTable, TableType key, uint16_t address)
 
void loadAllPages (void)
 Load all pages from durable storage. I.e. load the tune.
 
void loadAllCalibrationTables (void)
 Load the curves for all sensors from durable storage.
 
void saveAllCalibrationTables (void)
 Store the curves for all sensors in durable storage.
 
void saveCalibrationTable (SensorCalibrationTable sensor)
 Store one sensor curve in durable storage.
 
TESTABLE_INLINE_STATIC uint16_t getSensorCalibrationCrcAddress (SensorCalibrationTable sensor)
 
void saveCalibrationCrc (SensorCalibrationTable sensor, uint32_t calibrationCRC)
 Store the CRC for one sensor curve in durable storage.
 
uint32_t loadCalibrationCrc (SensorCalibrationTable sensor)
 Retrieve the CRC for one sensor curve from durable storage.
 
uint8_t loadLastBaro (void)
 Last barometer reading cache.
 
void saveLastBaro (uint8_t newValue)
 Last barometer reading cache.
 
uint8_t loadEEPROMVersion (void)
 Save/load the version number of the storage layout.
 
void saveEEPROMVersion (uint8_t newVersion)
 Save/load the version number of the storage layout.
 

Variables

static storage_api_t externalApi
 
constexpr uint16_t EEPROM_DATA_VERSION = 0
 
constexpr uint16_t STORAGE_END = 0xFFF
 
constexpr uint16_t EEPROM_CALIBRATION_CLT_VALUES = STORAGE_END-(uint16_t)sizeof(decltype(cltCalibrationTable)::values)
 
constexpr uint16_t EEPROM_CALIBRATION_CLT_BINS = EEPROM_CALIBRATION_CLT_VALUES-(uint16_t)sizeof(decltype(cltCalibrationTable)::axis)
 
constexpr uint16_t EEPROM_CALIBRATION_IAT_VALUES = EEPROM_CALIBRATION_CLT_BINS-(uint16_t)sizeof(decltype(iatCalibrationTable)::values)
 
constexpr uint16_t EEPROM_CALIBRATION_IAT_BINS = EEPROM_CALIBRATION_IAT_VALUES-(uint16_t)sizeof(decltype(iatCalibrationTable)::axis)
 
constexpr uint16_t EEPROM_CALIBRATION_O2_VALUES = EEPROM_CALIBRATION_IAT_BINS-(uint16_t)sizeof(decltype(o2CalibrationTable)::values)
 
constexpr uint16_t EEPROM_CALIBRATION_O2_BINS = EEPROM_CALIBRATION_O2_VALUES-(uint16_t)sizeof(decltype(o2CalibrationTable)::axis)
 
constexpr uint16_t EEPROM_LAST_BARO = (EEPROM_CALIBRATION_O2_BINS-(uint16_t)1)
 
constexpr uint16_t EEPROM_CONFIG1_MAP = 3
 
constexpr uint16_t EEPROM_CONFIG2_START = 291
 
constexpr uint16_t EEPROM_CONFIG3_MAP = 421
 
constexpr uint16_t EEPROM_CONFIG4_START = 709
 
constexpr uint16_t EEPROM_CONFIG5_MAP = 839
 
constexpr uint16_t EEPROM_CONFIG6_START = 1127
 
constexpr uint16_t EEPROM_CONFIG7_MAP1 = 1257
 
constexpr uint16_t EEPROM_CONFIG7_MAP2 = 1339
 
constexpr uint16_t EEPROM_CONFIG7_MAP3 = 1421
 
constexpr uint16_t EEPROM_CONFIG8_MAP1 = 1503
 
constexpr uint16_t EEPROM_CONFIG8_MAP2 = 1553
 
constexpr uint16_t EEPROM_CONFIG8_MAP3 = 1603
 
constexpr uint16_t EEPROM_CONFIG8_MAP4 = 1653
 
constexpr uint16_t EEPROM_CONFIG9_START = 1710
 
constexpr uint16_t EEPROM_CONFIG10_START = 1902
 
constexpr uint16_t EEPROM_CONFIG11_MAP = 2096
 
constexpr uint16_t EEPROM_CONFIG12_MAP = 2387
 
constexpr uint16_t EEPROM_CONFIG12_MAP2 = 2469
 
constexpr uint16_t EEPROM_CONFIG12_MAP3 = 2551
 
constexpr uint16_t EEPROM_CONFIG13_START = 2580
 
constexpr uint16_t EEPROM_CONFIG14_MAP = 2710
 
constexpr uint16_t EEPROM_CONFIG8_MAP5 = 3001
 
constexpr uint16_t EEPROM_CONFIG8_MAP6 = 3051
 
constexpr uint16_t EEPROM_CONFIG8_MAP7 = 3101
 
constexpr uint16_t EEPROM_CONFIG8_MAP8 = 3151
 
constexpr uint16_t EEPROM_CONFIG15_MAP = 3199
 
constexpr uint16_t EEPROM_CONFIG15_START = 3281
 

Detailed Description

Lower level ConfigPage*, Table2D, Table3D and EEPROM storage operations.

Function Documentation

◆ default_length()

static uint16_t default_length ( void  )
static
Here is the call graph for this function:

◆ default_read()

static byte default_read ( uint16_t  address)
static
Here is the call graph for this function:

◆ default_write()

static void default_write ( uint16_t  address,
byte  value 
)
static
Here is the call graph for this function:

◆ default_write_size()

static uint16_t default_write_size ( const statuses current)
static
Here is the call graph for this function:

◆ getSensorCalibrationCrcAddress()

TESTABLE_INLINE_STATIC uint16_t getSensorCalibrationCrcAddress ( SensorCalibrationTable  sensor)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStorageAPI()

const storage_api_t & getStorageAPI ( void  )

Provide global access to the raw storage API.

Here is the caller graph for this function:

◆ load() [1/3]

static uint16_t load ( table_axis_iterator  it,
uint16_t  address 
)
inlinestatic
Here is the call graph for this function:

◆ load() [2/3]

static uint16_t load ( table_row_iterator  row,
uint16_t  address 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load() [3/3]

static uint16_t load ( table_value_iterator  it,
uint16_t  address 
)
inlinestatic
Here is the call graph for this function:

◆ load_range()

static uint16_t load_range ( uint16_t  address,
byte pFirst,
const byte pLast 
)
inlinestatic

Load range of bytes form EEPROM offset to memory.

Parameters
address- start offset in EEPROM
pFirst- Start memory address
pLast- End memory address
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadTable()

static uint16_t loadTable ( table3d_t pTable,
TableType  key,
uint16_t  address 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setStorageAPI()

void setStorageAPI ( const storage_api_t api)

Inject the external storage API.

Note
This must be called before any other storage function.

Storage is split into two components:

  1. An API that abstracts basic storage I/O (storage_api_t).
  2. A set of functions that read/write Speeduino entities to/from storage (defined here)
Parameters
apiThe external storage I/O functions
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [1/3]

static write_location write ( const table_row_iterator row,
const write_location location 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [2/3]

static write_location write ( table_axis_iterator  it,
write_location  location 
)
inlinestatic
Here is the call graph for this function:

◆ write() [3/3]

static write_location write ( table_value_iterator  it,
write_location  location 
)
inlinestatic
Here is the call graph for this function:

◆ write_range()

static uint16_t write_range ( const byte pStart,
const byte pEnd,
uint16_t  address,
uint16_t  writesRemaining 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeTable()

static uint16_t writeTable ( table3d_t pTable,
TableType  key,
uint16_t  address,
uint16_t  writesRemaining 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ EEPROM_CALIBRATION_CLT_BINS

◆ EEPROM_CALIBRATION_CLT_VALUES

constexpr uint16_t EEPROM_CALIBRATION_CLT_VALUES = STORAGE_END-(uint16_t)sizeof(decltype(cltCalibrationTable)::values)
constexpr

◆ EEPROM_CALIBRATION_IAT_BINS

◆ EEPROM_CALIBRATION_IAT_VALUES

constexpr uint16_t EEPROM_CALIBRATION_IAT_VALUES = EEPROM_CALIBRATION_CLT_BINS-(uint16_t)sizeof(decltype(iatCalibrationTable)::values)
constexpr

◆ EEPROM_CALIBRATION_O2_BINS

◆ EEPROM_CALIBRATION_O2_VALUES

constexpr uint16_t EEPROM_CALIBRATION_O2_VALUES = EEPROM_CALIBRATION_IAT_BINS-(uint16_t)sizeof(decltype(o2CalibrationTable)::values)
constexpr

◆ EEPROM_CONFIG10_START

constexpr uint16_t EEPROM_CONFIG10_START = 1902
constexpr

◆ EEPROM_CONFIG11_MAP

constexpr uint16_t EEPROM_CONFIG11_MAP = 2096
constexpr

◆ EEPROM_CONFIG12_MAP

constexpr uint16_t EEPROM_CONFIG12_MAP = 2387
constexpr

◆ EEPROM_CONFIG12_MAP2

constexpr uint16_t EEPROM_CONFIG12_MAP2 = 2469
constexpr

◆ EEPROM_CONFIG12_MAP3

constexpr uint16_t EEPROM_CONFIG12_MAP3 = 2551
constexpr

◆ EEPROM_CONFIG13_START

constexpr uint16_t EEPROM_CONFIG13_START = 2580
constexpr

◆ EEPROM_CONFIG14_MAP

constexpr uint16_t EEPROM_CONFIG14_MAP = 2710
constexpr

◆ EEPROM_CONFIG15_MAP

constexpr uint16_t EEPROM_CONFIG15_MAP = 3199
constexpr

◆ EEPROM_CONFIG15_START

constexpr uint16_t EEPROM_CONFIG15_START = 3281
constexpr

◆ EEPROM_CONFIG1_MAP

constexpr uint16_t EEPROM_CONFIG1_MAP = 3
constexpr

◆ EEPROM_CONFIG2_START

constexpr uint16_t EEPROM_CONFIG2_START = 291
constexpr

◆ EEPROM_CONFIG3_MAP

constexpr uint16_t EEPROM_CONFIG3_MAP = 421
constexpr

◆ EEPROM_CONFIG4_START

constexpr uint16_t EEPROM_CONFIG4_START = 709
constexpr

◆ EEPROM_CONFIG5_MAP

constexpr uint16_t EEPROM_CONFIG5_MAP = 839
constexpr

◆ EEPROM_CONFIG6_START

constexpr uint16_t EEPROM_CONFIG6_START = 1127
constexpr

◆ EEPROM_CONFIG7_MAP1

constexpr uint16_t EEPROM_CONFIG7_MAP1 = 1257
constexpr

◆ EEPROM_CONFIG7_MAP2

constexpr uint16_t EEPROM_CONFIG7_MAP2 = 1339
constexpr

◆ EEPROM_CONFIG7_MAP3

constexpr uint16_t EEPROM_CONFIG7_MAP3 = 1421
constexpr

◆ EEPROM_CONFIG8_MAP1

constexpr uint16_t EEPROM_CONFIG8_MAP1 = 1503
constexpr

◆ EEPROM_CONFIG8_MAP2

constexpr uint16_t EEPROM_CONFIG8_MAP2 = 1553
constexpr

◆ EEPROM_CONFIG8_MAP3

constexpr uint16_t EEPROM_CONFIG8_MAP3 = 1603
constexpr

◆ EEPROM_CONFIG8_MAP4

constexpr uint16_t EEPROM_CONFIG8_MAP4 = 1653
constexpr

◆ EEPROM_CONFIG8_MAP5

constexpr uint16_t EEPROM_CONFIG8_MAP5 = 3001
constexpr

◆ EEPROM_CONFIG8_MAP6

constexpr uint16_t EEPROM_CONFIG8_MAP6 = 3051
constexpr

◆ EEPROM_CONFIG8_MAP7

constexpr uint16_t EEPROM_CONFIG8_MAP7 = 3101
constexpr

◆ EEPROM_CONFIG8_MAP8

constexpr uint16_t EEPROM_CONFIG8_MAP8 = 3151
constexpr

◆ EEPROM_CONFIG9_START

constexpr uint16_t EEPROM_CONFIG9_START = 1710
constexpr

◆ EEPROM_DATA_VERSION

constexpr uint16_t EEPROM_DATA_VERSION = 0
constexpr

◆ EEPROM_LAST_BARO

constexpr uint16_t EEPROM_LAST_BARO = (EEPROM_CALIBRATION_O2_BINS-(uint16_t)1)
constexpr

◆ externalApi

storage_api_t externalApi
static
Initial value:
= {
.read = default_read,
.write = default_write,
.length = default_length,
.getMaxWriteBlockSize = default_write_size,
}
static uint16_t default_length(void)
Definition storage.cpp:29
static byte default_read(uint16_t address)
Definition storage.cpp:27
static void default_write(uint16_t address, byte value)
Definition storage.cpp:28
static uint16_t default_write_size(const statuses &current)
Definition storage.cpp:30

◆ STORAGE_END

constexpr uint16_t STORAGE_END = 0xFFF
constexpr