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:
parent
52ebba3802
commit
04966868eb
5 changed files with 65 additions and 31 deletions
|
@ -86,8 +86,15 @@ 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
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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,8 +37,13 @@
|
||||||
|
|
||||||
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();
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) OpenTX
|
* Copyright (C) OpenTX
|
||||||
*
|
*
|
||||||
* Based on code named
|
* Based on code named
|
||||||
* th9x - http://code.google.com/p/th9x
|
* th9x - http://code.google.com/p/th9x
|
||||||
* er9x - http://code.google.com/p/er9x
|
* er9x - http://code.google.com/p/er9x
|
||||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
*
|
*
|
||||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
* published by the Free Software Foundation.
|
* published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "../../opentx.h"
|
||||||
|
|
||||||
void rtcSetTime(struct gtm * t)
|
void rtcSetTime(struct gtm * t)
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue