Protocol rework
This commit is contained in:
parent
3e77d34ccc
commit
2b713a3e3a
15 changed files with 1347 additions and 1155 deletions
|
|
@ -1,6 +1,16 @@
|
|||
/*
|
||||
* @file eeprom.h
|
||||
* @brief EEPROM management for persistent settings
|
||||
* @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
|
||||
|
|
@ -17,30 +27,16 @@
|
|||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Potentiometer settings structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t hv_pot; ///< High voltage potentiometer value
|
||||
uint8_t amp_pot; ///< SiPM Pre-amp gain potentiometer value
|
||||
uint8_t det_pot; ///< Detection threshold potentiometer value
|
||||
} potentiometer_settings_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize EEPROM settings
|
||||
* Sets default values if EEPROM is uninitialized
|
||||
* @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 Load potentiometer settings from EEPROM
|
||||
* @param settings Pointer to settings structure to populate
|
||||
* @brief Persist the current global @c config to the alternate partition,
|
||||
* bumping the generation counter to flip the active partition.
|
||||
*/
|
||||
void eeprom_load_pot_settings(potentiometer_settings_t *settings);
|
||||
void eeprom_save_config(void);
|
||||
|
||||
/**
|
||||
* @brief Save potentiometer settings to EEPROM
|
||||
* @param settings Pointer to settings structure to save
|
||||
*/
|
||||
void eeprom_save_pot_settings(const potentiometer_settings_t *settings);
|
||||
|
||||
#endif // DET_EEPROM_H
|
||||
#endif /* DET_EEPROM_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue