rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
out_store_rec.c File Reference

A store record's configuration by version. More...

#include "out_store_rec.h"
#include <string.h>
#include "link_crc.h"
#include "out_store_map.h"
#include "prog_port.h"
#include "sense_page.h"
#include "supply_page.h"
#include "tone_page.h"

Functions

size_t out_store_cfg_size (uint16_t version)
 Each version appends: its size is where the next version's field starts.
bool out_store_cfg_read (uint16_t version, const void *cfg, out_store_t *out)
 A record's configuration, as version wrote it at cfg (out_store_cfg_size() bytes), into out at the newest layout.
size_t out_store_rec_size (uint16_t version)
 A whole record of version, head and configuration: 308 bytes for version 8, 228 for 7. 0 for a version not read.
static uint16_t rec_crc (const uint8_t *rec, size_t size)
 The checksum: from the version to the record's end.
static uint32_t rec_zeros (const uint8_t *rec, size_t size)
 The 0 bits from the checksum to the record's end: everything but the magic and the count itself.
bool out_store_rec_build (uint8_t *rec, size_t slot, uint16_t version, uint32_t seq, const out_store_t *cfg)
 A record of version for cfg and seq into the slot bytes at rec: the record, then 0xFF to the slot's end, as an erased slot reads, so a program of the whole slot changes nothing past the record. A save writes OUT_STORE_VERSION; an older version is what an earlier build wrote. False, and nothing written, for a version not read or a record longer than slot.
bool out_store_rec_check (const uint8_t *rec, size_t avail, uint16_t min_version, uint16_t max_version, uint16_t *version, uint32_t *seq)
 Whether the avail bytes at rec start with a whole record of a version this build reads, from min_version to max_version: magic, version, zero count and checksum.

Detailed Description

A store record's configuration by version.

See out_store_rec.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ out_store_cfg_read()

bool out_store_cfg_read ( uint16_t version,
const void * cfg,
out_store_t * out )

A record's configuration, as version wrote it at cfg (out_store_cfg_size() bytes), into out at the newest layout.

What the version does not carry starts as its page does: the supply disabled at the module's 19200 baud, both current monitors off at their defaults (sense_page_defaults()), the phase tap off at its defaults (tone_page_defaults()), programming port 0 on PROG_PORT_DEFAULT_PIN and the other ports without a pin (prog_port_defaults()).

False for a version this build does not read, and out is untouched.

Parameters
versionRecord version the configuration was written with.
cfgThe configuration, out_store_cfg_size() bytes. Not NULL.
outReceives the configuration in the newest layout. Not NULL.
Returns
true when read, false for a version not read or a NULL pointer.

◆ out_store_cfg_size()

size_t out_store_cfg_size ( uint16_t version)

Each version appends: its size is where the next version's field starts.

How many bytes of configuration a record of version carries, from the start of an out_store_t: 128 for version 3, 136 for 4, 160 for 5, 176 for 6 (two of them the word prog_func), 208 for 7, 288 for 8. 0 for a version this build does not read.

Each version appends: its size is where the next version's field starts.

Parameters
versionRecord version, one of the OUT_STORE_VERSION values.
Returns
Configuration size in bytes, or 0 for a version not read.

◆ out_store_rec_build()

bool out_store_rec_build ( uint8_t * rec,
size_t slot,
uint16_t version,
uint32_t seq,
const out_store_t * cfg )

A record of version for cfg and seq into the slot bytes at rec: the record, then 0xFF to the slot's end, as an erased slot reads, so a program of the whole slot changes nothing past the record. A save writes OUT_STORE_VERSION; an older version is what an earlier build wrote. False, and nothing written, for a version not read or a record longer than slot.

Parameters
recReceives the record and the 0xFF fill, slot bytes.
slotSize of the slot in bytes.
versionRecord version, one of the OUT_STORE_VERSION values.
seqSequence number stored in the head.
cfgThe configuration to store, out_store_cfg_size() bytes of it.
Returns
true when the record is written, false when rec or cfg is NULL, the version is not read, or the record is longer than slot.

◆ out_store_rec_check()

bool out_store_rec_check ( const uint8_t * rec,
size_t avail,
uint16_t min_version,
uint16_t max_version,
uint16_t * version,
uint32_t * seq )

Whether the avail bytes at rec start with a whole record of a version this build reads, from min_version to max_version: magic, version, zero count and checksum.

On true, its version and sequence number. A record longer than avail is no record. The two-page layout takes version 8 alone: a version 7 record that happens to start a two-page slot is the layout before's, read with the rest of its slots.

Parameters
recThe bytes to check.
availNumber of bytes at rec.
min_versionLowest record version accepted.
max_versionHighest record version accepted.
versionReceives the record's version on true. May be NULL.
seqReceives the record's sequence number on true. May be NULL.
Returns
true when the record is whole and in range, false otherwise, including when rec is NULL or avail is below the head size.

◆ out_store_rec_size()

size_t out_store_rec_size ( uint16_t version)

A whole record of version, head and configuration: 308 bytes for version 8, 228 for 7. 0 for a version not read.

Parameters
versionRecord version, one of the OUT_STORE_VERSION values.
Returns
Record size in bytes, the head plus out_store_cfg_size(), or 0 for a version not read.

◆ rec_crc()

uint16_t rec_crc ( const uint8_t * rec,
size_t size )
static

The checksum: from the version to the record's end.

Parameters
recThe record, at least size bytes.
sizeRecord size in bytes, from out_store_rec_size().
Returns
CRC-16 over the bytes from the version field to size.

◆ rec_zeros()

uint32_t rec_zeros ( const uint8_t * rec,
size_t size )
static

The 0 bits from the checksum to the record's end: everything but the magic and the count itself.

Parameters
recThe record, at least size bytes.
sizeRecord size in bytes, from out_store_rec_size().
Returns
Number of 0 bits in the bytes from the checksum field to size.