42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
/*
|
|
* @file eeprom.h
|
|
* @brief EEPROM management for persistent configuration storage.
|
|
*
|
|
* Dual-partition layout in ATmega4809 EEPROM (256 bytes):
|
|
*
|
|
* [0 .. sizeof(config_t)] Partition A: config_t + 1-byte generation counter
|
|
* [sizeof(config_t)+1 .. 2*(sizeof(config_t)+1)-1] Partition B: same layout
|
|
*
|
|
* On save, the alternate (older) partition is overwritten. If power fails
|
|
* mid-write the other partition retains the last good config. The generation
|
|
* counter wraps around uint8_t; the partition with the higher counter
|
|
* (mod-256 comparison via signed delta) is the newer one.
|
|
*
|
|
* Created: 21.09.2025
|
|
* Author: ThePetrovich
|
|
*
|
|
* Copyright YKSA - Sakha Aerospace Systems, LLC.
|
|
* See the LICENSE file for details.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef DET_EEPROM_H
|
|
#define DET_EEPROM_H
|
|
|
|
#include <stdint.h>
|
|
|
|
/**
|
|
* @brief Load the global @c config from EEPROM.
|
|
* Picks the freshest valid partition; writes factory defaults if both
|
|
* partitions are blank or corrupt.
|
|
*/
|
|
void eeprom_init(void);
|
|
|
|
/**
|
|
* @brief Persist the current global @c config to the alternate partition,
|
|
* bumping the generation counter to flip the active partition.
|
|
*/
|
|
void eeprom_save_config(void);
|
|
|
|
#endif /* DET_EEPROM_H */
|