Improve SRAM and Flash write cycles

This commit is contained in:
Armel FAUVEAU committed 2026-01-22 02:48:19 +01:00
1 parent b9ce4934d8
commit 6b94ae4ed3
11 files changed
+436 -52

No files matched your search

+59 -3
View File
@@ -37,10 +37,14 @@
#endif
#define FM_CHANNELS_MAX 48
#define MR_CHANNELS_MAX 768
#define MR_CHANNELS_MAX 1024
#define MR_CHANNELS_LIST 24
#define MENU_ITEMS 68
// CACHE-BASED OPTIMIZATION: Only keep active channels in RAM
// Full array stays in EEPROM, cache holds ~10 most-used channels
#define MR_CHANNELS_CACHE_SIZE 10
#define IS_MR_CHANNEL(x) ((x) >= MR_CHANNEL_FIRST && (x) <= MR_CHANNEL_LAST)
#define IS_FREQ_CHANNEL(x) ((x) >= FREQ_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST)
@@ -238,7 +242,55 @@ typedef union {
uint16_t __val;
} ChannelAttributes_t;
extern ChannelAttributes_t gMR_ChannelAttributes[MR_CHANNELS_MAX + 7];
//
// Cache-Based Architecture
//
//
// Instead of keeping all 1038 channel attributes in RAM (~ 2,000 bytes),
// we now keep only the active ones in a small cache (40 bytes).
//
// The full array remains in Flash and is loaded on-demand.
//
// SRAM Savings: ~ 2,000 bytes (84% reduction!)
//
// Cache entry structure
typedef struct {
uint16_t channel_id; // Which channel this is
ChannelAttributes_t attributes; // The actual attributes
uint32_t access_time; // For LRU eviction (optional)
} MR_ChannelCache_t;
// The cache (small, stays in RAM)
extern MR_ChannelCache_t gMR_ChannelAttributes_Cache[MR_CHANNELS_CACHE_SIZE];
// REMOVED: extern ChannelAttributes_t gMR_ChannelAttributes[MR_CHANNELS_MAX + 7];
// This now stays in Flash, not in RAM
//
// Cache Access Functions (See misc.c for implementation)
//
// Get channel attributes (from cache or Flash)
// Returns pointer to attributes, loads from Flash if not in cache
void MR_InitChannelAttributesCache(void);
ChannelAttributes_t* MR_GetChannelAttributes(uint16_t channel_id);
// Set channel attributes (updates both cache and Flasf)
void MR_SetChannelAttributes(uint16_t channel_id, const ChannelAttributes_t* attributes);
// Invalidate cache (on Flash clear)
void MR_InvalidateChannelAttributesCache(void);
// Load channel attributes from Flash directly (internal use)
void MR_LoadChannelAttributesFromFlash(uint16_t channel_id, ChannelAttributes_t* attributes);
// Save channel attributes to Flash directly (internal use)
void MR_SaveChannelAttributesToFlash(uint16_t channel_id, const ChannelAttributes_t* attributes);
extern ChannelAttributes_t gMR_ChannelAttributes_Current; // Current VFO attributes (for speed)
extern volatile uint16_t gBatterySaveCountdown_10ms;
@@ -395,6 +447,10 @@ extern volatile uint8_t boot_counter_10ms;
extern uint8_t gBacklightBrightnessOld;
extern uint8_t gPttOnePushCounter;
extern uint32_t gBlinkCounter;
extern uint16_t gVfoSaveCountdown_10ms;
extern bool gScheduleVfoSave;
extern bool gVfoStateChanged;
#endif
int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit);
@@ -404,4 +460,4 @@ void FUNCTION_NOP();
static inline bool SerialConfigInProgress() { return gSerialConfigCountDown_500ms != 0; }
#endif
#endif