Fix doc path
[opentx.git] / radio / src / storage / rambackup.cpp
blobb5a57c8328ed024ac6c4047e47ed6b12998ef8b5
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "opentx.h"
23 namespace Backup {
24 #define BACKUP
25 #include "datastructs.h"
26 PACK(struct RamBackupUncompressed {
27 ModelData model;
28 RadioData radio;
29 });
30 #undef BACKUP
33 #include "datacopy.cpp"
35 Backup::RamBackupUncompressed ramBackupUncompressed __DMA;
37 #if defined(SIMU)
38 RamBackup _ramBackup;
39 RamBackup * ramBackup = &_ramBackup;
40 #else
41 RamBackup * ramBackup = (RamBackup *)BKPSRAM_BASE;
42 #endif
44 void rambackupWrite()
46 copyRadioData(&ramBackupUncompressed.radio, &g_eeGeneral);
47 copyModelData(&ramBackupUncompressed.model, &g_model);
48 ramBackup->size = compress(ramBackup->data, 4094, (const uint8_t *)&ramBackupUncompressed, sizeof(ramBackupUncompressed));
49 TRACE("RamBackupWrite sdsize=%d backupsize=%d rlcsize=%d", sizeof(ModelData)+sizeof(RadioData), sizeof(Backup::RamBackupUncompressed), ramBackup->size);
52 bool rambackupRestore()
54 if (ramBackup->size == 0)
55 return false;
57 if (uncompress((uint8_t *)&ramBackupUncompressed, sizeof(ramBackupUncompressed), ramBackup->data, ramBackup->size) != sizeof(ramBackupUncompressed))
58 return false;
60 memset(&g_eeGeneral, 0, sizeof(g_eeGeneral));
61 memset(&g_model, 0, sizeof(g_model));
62 copyRadioData(&g_eeGeneral, &ramBackupUncompressed.radio);
63 copyModelData(&g_model, &ramBackupUncompressed.model);
64 return true;