1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 09:45:21 +03:00

[Horus] Ram backup write should be working now. Still needs to be tested with a restore on WDT

This commit is contained in:
Bertrand Songis 2016-03-05 16:34:23 +01:00
parent 52ebba3802
commit 04966868eb
5 changed files with 65 additions and 31 deletions

View file

@ -86,9 +86,16 @@ void checkEeprom()
#else #else
void checkEeprom() void checkEeprom()
{ {
if (TIME_TO_WRITE()) #if defined(RAMBACKUP)
if (TIME_TO_RAMBACKUP()) {
rambackupWrite();
rambackupDirtyMsk = 0;
}
#endif
if (TIME_TO_WRITE()) {
storageCheck(false); storageCheck(false);
} }
}
#endif #endif
#if defined(GUI) && defined(COLORLCD) #if defined(GUI) && defined(COLORLCD)

View file

@ -39,19 +39,24 @@ PACK(struct RamBackup {
uint8_t data[4094]; uint8_t data[4094];
}); });
RamBackup ramBackup; #if defined(SIMU)
RamBackup _ramBackup;
RamBackup * ramBackup = &_ramBackup;
#else
RamBackup * ramBackup = (RamBackup *)BKPSRAM_BASE;
#endif
void rambackupWrite() void rambackupWrite()
{ {
copyRadioData(&ramBackupUncompressed.radio, &g_eeGeneral); copyRadioData(&ramBackupUncompressed.radio, &g_eeGeneral);
copyModelData(&ramBackupUncompressed.model, &g_model); copyModelData(&ramBackupUncompressed.model, &g_model);
ramBackup.size = compress(ramBackup.data, (const uint8_t *)&ramBackupUncompressed, sizeof(ramBackupUncompressed)); ramBackup->size = compress(ramBackup->data, (const uint8_t *)&ramBackupUncompressed, sizeof(ramBackupUncompressed));
TRACE("RamBackupWrite sdsize=%d backupsize=%d rlcsize=%d", sizeof(ModelData)+sizeof(RadioData), sizeof(Backup::RamBackupUncompressed), ramBackup.size); TRACE("RamBackupWrite sdsize=%d backupsize=%d rlcsize=%d", sizeof(ModelData)+sizeof(RadioData), sizeof(Backup::RamBackupUncompressed), ramBackup->size);
#if 0 #if 0
// TODO move this code to non regression tests // TODO move this code to non regression tests
Backup::RamBackupUncompressed ramBackupRestored; Backup::RamBackupUncompressed ramBackupRestored;
if (uncompress((uint8_t *)&ramBackupRestored, ramBackup.data, ramBackup.size) != sizeof(ramBackupUncompressed)) if (uncompress((uint8_t *)&ramBackupRestored, ramBackup->data, ramBackup->size) != sizeof(ramBackupUncompressed))
TRACE("ERROR size"); TRACE("ERROR size");
if (memcmp(&ramBackupUncompressed, &ramBackupRestored, sizeof(ramBackupUncompressed)) != 0) if (memcmp(&ramBackupUncompressed, &ramBackupRestored, sizeof(ramBackupUncompressed)) != 0)
TRACE("ERROR restore"); TRACE("ERROR restore");
@ -60,10 +65,10 @@ void rambackupWrite()
bool rambackupRestore() bool rambackupRestore()
{ {
if (ramBackup.size == 0) if (ramBackup->size == 0)
return false; return false;
if (uncompress((uint8_t *)&ramBackupUncompressed, ramBackup.data, ramBackup.size) != sizeof(ramBackupUncompressed)) if (uncompress((uint8_t *)&ramBackupUncompressed, ramBackup->data, ramBackup->size) != sizeof(ramBackupUncompressed))
return false; return false;
copyRadioData(&g_eeGeneral, &ramBackupUncompressed.radio); copyRadioData(&g_eeGeneral, &ramBackupUncompressed.radio);

View file

@ -22,8 +22,10 @@
#define _STORAGE_H_ #define _STORAGE_H_
#if defined(SIMU) #if defined(SIMU)
#define WRITE_DELAY_10MS 200 #define WRITE_DELAY_10MS 100
#elif defined(PCBTARANIS) #elif defined(RAMBACKUP)
#define WRITE_DELAY_10MS 1500 /* 15s */
#elif defined(PCBTARANIS) || defined(PCBFLAMENCO)
#define WRITE_DELAY_10MS 500 #define WRITE_DELAY_10MS 500
#elif defined(PCBSKY9X) && !defined(REV0) #elif defined(PCBSKY9X) && !defined(REV0)
#define WRITE_DELAY_10MS 500 #define WRITE_DELAY_10MS 500
@ -35,9 +37,14 @@
extern uint8_t storageDirtyMsk; extern uint8_t storageDirtyMsk;
extern tmr10ms_t storageDirtyTime10ms; extern tmr10ms_t storageDirtyTime10ms;
#define TIME_TO_WRITE() (storageDirtyMsk && (tmr10ms_t)(get_tmr10ms() - storageDirtyTime10ms) >= (tmr10ms_t)WRITE_DELAY_10MS) #define TIME_TO_WRITE() (storageDirtyMsk && (tmr10ms_t)(get_tmr10ms() - storageDirtyTime10ms) >= (tmr10ms_t)WRITE_DELAY_10MS)
#if defined(RAMBACKUP)
extern uint8_t rambackupDirtyMsk;
extern tmr10ms_t rambackupDirtyTime10ms;
#define TIME_TO_RAMBACKUP() (rambackupDirtyMsk && (tmr10ms_t)(get_tmr10ms() - rambackupDirtyTime10ms) >= (tmr10ms_t)100)
#endif
void storageEraseAll(bool warn); void storageEraseAll(bool warn);
void storageFormat(); void storageFormat();
void storageReadAll(); void storageReadAll();

View file

@ -23,10 +23,20 @@
uint8_t storageDirtyMsk; uint8_t storageDirtyMsk;
tmr10ms_t storageDirtyTime10ms; tmr10ms_t storageDirtyTime10ms;
#if defined(RAMBACKUP)
uint8_t rambackupDirtyMsk;
tmr10ms_t rambackupDirtyTime10ms;
#endif
void storageDirty(uint8_t msk) void storageDirty(uint8_t msk)
{ {
storageDirtyMsk |= msk; storageDirtyMsk |= msk;
storageDirtyTime10ms = get_tmr10ms(); storageDirtyTime10ms = get_tmr10ms();
#if defined(RAMBACKUP)
rambackupDirtyMsk = storageDirtyMsk;
rambackupDirtyTime10ms = storageDirtyTime10ms;
#endif
} }
void preModelLoad() void preModelLoad()

View file

@ -76,4 +76,9 @@ void rtcInit()
struct gtm utm; struct gtm utm;
rtcGetTime(&utm); rtcGetTime(&utm);
g_rtcTime = gmktime(&utm); g_rtcTime = gmktime(&utm);
#if defined(RAMBACKUP)
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);
PWR_BackupRegulatorCmd(ENABLE);
#endif
} }