Skip to content

File syn_param.c

FileList > src > syntropic > storage > syn_param.c

Go to the source code of this file

Persistent parameter store with wear leveling.

  • #include "../util/syn_assert.h"
  • #include "../util/syn_crc.h"
  • #include "syn_param.h"
  • #include <string.h>

Public Functions

Type Name
SYN_Status syn_param_erase_all (SYN_ParamStore * store)
Erase all parameter data (factory reset).
SYN_Status syn_param_init (SYN_ParamStore * store, uint32_t flash_base, uint8_t sector_count, uint16_t data_size)
Initialize the parameter store.
SYN_Status syn_param_load (const SYN_ParamStore * store, void * data)
Load parameters from the latest valid slot.
SYN_Status syn_param_save (SYN_ParamStore * store, const void * data)
Save parameters to the next slot (wear-leveled).

Public Static Functions

Type Name
uint16_t align16 (uint16_t size)
Align size up to 16-byte boundary for flash write alignment.
bool read_slot (const SYN_ParamStore * store, uint8_t sector, uint16_t slot, SYN_ParamSlotHeader * hdr, void * data)
Read a slot header and data from flash.
uint32_t slot_addr (const SYN_ParamStore * store, uint8_t sector, uint16_t slot)
Compute the flash address of a parameter slot.
bool verify_slot_crc (const SYN_ParamStore * store, uint8_t sector, uint16_t slot, uint16_t expected_crc)
Verify CRC of a stored slot's data.

Public Functions Documentation

function syn_param_erase_all

Erase all parameter data (factory reset).

SYN_Status syn_param_erase_all (
    SYN_ParamStore * store
) 

Parameters:

  • store Store instance.

Returns:

SYN_OK on success.


function syn_param_init

Initialize the parameter store.

SYN_Status syn_param_init (
    SYN_ParamStore * store,
    uint32_t flash_base,
    uint8_t sector_count,
    uint16_t data_size
) 

Scans flash to find the latest valid slot. Must be called before load or save.

Parameters:

  • store Store instance.
  • flash_base Start address of the flash region for params.
  • sector_count Number of flash sectors to use for wear leveling.
  • data_size Size of the parameter struct in bytes.

Returns:

SYN_OK if at least one valid slot was found, SYN_ERROR if flash is blank (use defaults).


function syn_param_load

Load parameters from the latest valid slot.

SYN_Status syn_param_load (
    const SYN_ParamStore * store,
    void * data
) 

Parameters:

  • store Initialized store.
  • data Buffer to receive the parameter data (must be data_size bytes).

Returns:

SYN_OK on success, SYN_ERROR if no valid data found.


function syn_param_save

Save parameters to the next slot (wear-leveled).

SYN_Status syn_param_save (
    SYN_ParamStore * store,
    const void * data
) 

Writes to the next free slot, rotating across sectors. When a sector fills up, the next sector is erased and writing continues there.

Parameters:

  • store Initialized store.
  • data Parameter data to save (must be data_size bytes).

Returns:

SYN_OK on success, SYN_ERROR on flash write failure.


Public Static Functions Documentation

function align16

Align size up to 16-byte boundary for flash write alignment.

static uint16_t align16 (
    uint16_t size
) 

Parameters:

  • size Size to align.

Returns:

Aligned size.


function read_slot

Read a slot header and data from flash.

static bool read_slot (
    const SYN_ParamStore * store,
    uint8_t sector,
    uint16_t slot,
    SYN_ParamSlotHeader * hdr,
    void * data
) 

Parameters:

  • store Parameter store.
  • sector Sector index.
  • slot Slot index.
  • hdr [out] Slot header.
  • data [out] Slot data.

Returns:

true on success.


function slot_addr

Compute the flash address of a parameter slot.

static uint32_t slot_addr (
    const SYN_ParamStore * store,
    uint8_t sector,
    uint16_t slot
) 

Parameters:

  • store Parameter store.
  • sector Sector index.
  • slot Slot index within sector.

Returns:

Absolute flash address.


function verify_slot_crc

Verify CRC of a stored slot's data.

static bool verify_slot_crc (
    const SYN_ParamStore * store,
    uint8_t sector,
    uint16_t slot,
    uint16_t expected_crc
) 

Parameters:

  • store Parameter store.
  • sector Sector index.
  • slot Slot index.
  • expected_crc Expected CRC value.

Returns:

true if CRC matches.



The documentation for this class was generated from the following file src/syntropic/storage/syn_param.c