9uint32_t
cfg_crc32(
const void *data, uint32_t len)
11 const uint8_t *p = (
const uint8_t *)data;
12 uint32_t c = 0xFFFFFFFFu;
15 for (
int k = 0; k < 8; ++k) c = (c >> 1) ^ (0xEDB88320u & (0u - (c & 1u)));
63 if (best < 0 || (int32_t)(im->
seq -
seq) > 0) { best = p;
seq = im->
seq; }
104 memset(out, 0,
sizeof *out);
133_Static_assert(
sizeof(
cfg_image_t) <= 4096u,
"configuration image must fit one flash page");
void cal_set_defaults(cal_set_t *s, const float hi[3])
int cfg_save(cfg_image_t *img)
writes img (seq and crc filled here) to the other page; 0 = ok
void cfg_params_put(cfg_image_t *img, const float v[PARAM_COUNT])
parameters <-> slots (unknown ids ignored, missing ids -> default)
void cfg_params_get(const cfg_image_t *img, float v[PARAM_COUNT])
static int valid_version(const void *page)
static void cal_from_v1(cal_set_t *d, const cal_set_v1_t *s)
static int latest_page(void)
uint32_t cfg_crc32(const void *data, uint32_t len)
static int valid(const cfg_image_t *im)
int cfg_load(cfg_image_t *out)
latest valid image (version 1 converted); returns 0 if found, -1 if none (out left untouched)
Persistent configuration: parameters, drone name, calibrations and one backup per calibration type (H...
#define CFG_PARAM_SLOTS
room for parameters added later
const void * cfg_flash_page(int page)
memory-mapped page
int cfg_flash_write(int page, const void *data, uint32_t len)
erase + program; 0 = ok
static int pg(void *c, uint32_t a, const void *buf, uint32_t n)
const param_def_t g_param_def[PARAM_COUNT]
int params_index(uint16_t id)
-1 if unknown
uint8_t level
PV2_BATT_OK / LOW / CRITICAL / EMERGENCY
uint32_t done_mask
bit (type-1): this calibration was done and saved
uint32_t crc
CRC-32 of everything above
cal_set_t bak
previous set, per type (CAL_RESTORE)
float batt_used_scale_i
current scale it was counted with
cfg_param_t params[CFG_PARAM_SLOTS]
cal_set_t cal
saved calibrations
uint32_t bak_mask
bit (type-1): bak holds a set for it
uint16_t id
0 = empty slot