Fix doc path
[opentx.git] / radio / src / storage / storage_common.cpp
blob1840b9050ee587114b50b76c20b061c300e72107
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 uint8_t storageDirtyMsk;
24 tmr10ms_t storageDirtyTime10ms;
26 #if defined(RAMBACKUP)
27 uint8_t rambackupDirtyMsk;
28 tmr10ms_t rambackupDirtyTime10ms;
29 #endif
31 void storageDirty(uint8_t msk)
33 storageDirtyMsk |= msk;
34 storageDirtyTime10ms = get_tmr10ms();
36 #if defined(RAMBACKUP)
37 rambackupDirtyMsk = storageDirtyMsk;
38 rambackupDirtyTime10ms = storageDirtyTime10ms;
39 #endif
42 void preModelLoad()
44 #if defined(CPUARM)
45 watchdogSuspend(500/*5s*/);
46 #endif
48 #if defined(SDCARD)
49 logsClose();
50 #endif
52 if (pulsesStarted()) {
53 pausePulses();
56 pauseMixerCalculations();
58 #if defined(PCBTARANIS) || defined(PCBHORUS)
59 static void fixUpModel()
61 // Ensure that when rfProtocol is RF_PROTO_OFF the type of the module is MODULE_TYPE_NONE
62 if (g_model.moduleData[INTERNAL_MODULE].type == MODULE_TYPE_XJT && g_model.moduleData[INTERNAL_MODULE].rfProtocol == RF_PROTO_OFF)
63 g_model.moduleData[INTERNAL_MODULE].type = MODULE_TYPE_NONE;
65 #endif
67 void postModelLoad(bool alarms)
69 #if defined(PCBTARANIS) || defined(PCBHORUS)
70 fixUpModel();
71 #endif
72 AUDIO_FLUSH();
73 flightReset(false);
75 customFunctionsReset();
77 restoreTimers();
79 #if defined(CPUARM)
80 for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
81 TelemetrySensor & sensor = g_model.telemetrySensors[i];
82 if (sensor.type == TELEM_TYPE_CALCULATED && sensor.persistent) {
83 telemetryItems[i].value = sensor.persistentValue;
84 telemetryItems[i].lastReceived = TELEMETRY_VALUE_OLD; // #3595: make value visible even before the first new value is received)
87 #endif
89 LOAD_MODEL_CURVES();
91 resumeMixerCalculations();
92 if (pulsesStarted()) {
93 #if defined(GUI)
94 if (alarms) {
95 checkAll();
96 PLAY_MODEL_NAME();
98 #endif
99 resumePulses();
102 #if defined(TELEMETRY_FRSKY)
103 frskySendAlarms();
104 #endif
106 #if defined(CPUARM) && defined(SDCARD)
107 referenceModelAudioFiles();
108 #endif
110 #if defined(PCBHORUS)
111 loadCustomScreens();
112 #endif
114 LOAD_MODEL_BITMAP();
115 LUA_LOAD_MODEL_SCRIPTS();
116 SEND_FAILSAFE_1S();
119 void storageFlushCurrentModel()
121 saveTimers();
123 #if defined(CPUARM)
124 for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
125 TelemetrySensor & sensor = g_model.telemetrySensors[i];
126 if (sensor.type == TELEM_TYPE_CALCULATED && sensor.persistent && sensor.persistentValue != telemetryItems[i].value) {
127 sensor.persistentValue = telemetryItems[i].value;
128 storageDirty(EE_MODEL);
131 #endif
133 #if defined(CPUARM)
134 if (g_model.potsWarnMode == POTS_WARN_AUTO) {
135 for (int i=0; i<NUM_POTS+NUM_SLIDERS; i++) {
136 if (!(g_model.potsWarnEnabled & (1 << i))) {
137 SAVE_POT_POSITION(i);
140 storageDirty(EE_MODEL);
142 #endif