diff --git a/radio/src/main_arm.cpp b/radio/src/main_arm.cpp index b28cb3361..7d8071173 100644 --- a/radio/src/main_arm.cpp +++ b/radio/src/main_arm.cpp @@ -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 diff --git a/radio/src/storage/rambackup.cpp b/radio/src/storage/rambackup.cpp index 85e0d1a03..6e14b2af0 100644 --- a/radio/src/storage/rambackup.cpp +++ b/radio/src/storage/rambackup.cpp @@ -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); diff --git a/radio/src/storage/storage.h b/radio/src/storage/storage.h index 0dd292c11..eea938049 100644 --- a/radio/src/storage/storage.h +++ b/radio/src/storage/storage.h @@ -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(); diff --git a/radio/src/storage/storage_common.cpp b/radio/src/storage/storage_common.cpp index ee4b68a98..7f2e3eeb5 100644 --- a/radio/src/storage/storage_common.cpp +++ b/radio/src/storage/storage_common.cpp @@ -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() diff --git a/radio/src/targets/taranis/rtc_driver.cpp b/radio/src/targets/taranis/rtc_driver.cpp index e4ec42a1b..1a1071032 100644 --- a/radio/src/targets/taranis/rtc_driver.cpp +++ b/radio/src/targets/taranis/rtc_driver.cpp @@ -1,23 +1,23 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * 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 - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * 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 + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + #include "../../opentx.h" void rtcSetTime(struct gtm * t) @@ -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 }