1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 17:25:13 +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,8 +86,15 @@ void checkEeprom()
#else
void checkEeprom()
{
if (TIME_TO_WRITE())
#if defined(RAMBACKUP)
if (TIME_TO_RAMBACKUP()) {
rambackupWrite();
rambackupDirtyMsk = 0;
}
#endif
if (TIME_TO_WRITE()) {
storageCheck(false);
}
}
#endif

View file

@ -39,19 +39,24 @@ PACK(struct RamBackup {
uint8_t data[4094];
});
RamBackup ramBackup;
#if defined(SIMU)
RamBackup _ramBackup;
RamBackup * ramBackup = &_ramBackup;
#else
RamBackup * ramBackup = (RamBackup *)BKPSRAM_BASE;
#endif
void rambackupWrite()
{
copyRadioData(&ramBackupUncompressed.radio, &g_eeGeneral);
copyModelData(&ramBackupUncompressed.model, &g_model);
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);
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);
#if 0
// TODO move this code to non regression tests
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");
if (memcmp(&ramBackupUncompressed, &ramBackupRestored, sizeof(ramBackupUncompressed)) != 0)
TRACE("ERROR restore");
@ -60,10 +65,10 @@ void rambackupWrite()
bool rambackupRestore()
{
if (ramBackup.size == 0)
if (ramBackup->size == 0)
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;
copyRadioData(&g_eeGeneral, &ramBackupUncompressed.radio);

View file

@ -22,8 +22,10 @@
#define _STORAGE_H_
#if defined(SIMU)
#define WRITE_DELAY_10MS 200
#elif defined(PCBTARANIS)
#define WRITE_DELAY_10MS 100
#elif defined(RAMBACKUP)
#define WRITE_DELAY_10MS 1500 /* 15s */
#elif defined(PCBTARANIS) || defined(PCBFLAMENCO)
#define WRITE_DELAY_10MS 500
#elif defined(PCBSKY9X) && !defined(REV0)
#define WRITE_DELAY_10MS 500
@ -35,8 +37,13 @@
extern uint8_t storageDirtyMsk;
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 storageFormat();

View file

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

View file

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