diff --git a/src/eeprom_common.h b/src/eeprom_common.h index 2658d096a..68b3910c0 100644 --- a/src/eeprom_common.h +++ b/src/eeprom_common.h @@ -50,7 +50,7 @@ extern uint8_t s_eeDirtyMsk; extern tmr10ms_t s_eeDirtyTime10ms; void eeDirty(uint8_t msk); -void eeCheck(bool immediately=false); +void eeCheck(bool immediately); void eeReadAll(); bool eeModelExists(uint8_t id); void eeLoadModelName(uint8_t id, char *name); diff --git a/src/eeprom_rlc.cpp b/src/eeprom_rlc.cpp index 730f430fd..61ea906ec 100644 --- a/src/eeprom_rlc.cpp +++ b/src/eeprom_rlc.cpp @@ -42,13 +42,14 @@ uint8_t s_write_err = 0; // error reasons RlcFile theFile; //used for any file operation EeFs eeFs; -#if defined(PCBTARANIS) + +#if defined(CPUARM) blkid_t freeBlocks = 0; #endif +uint8_t s_sync_write = false; #if !defined(CPUARM) -uint8_t s_sync_write = false; uint16_t eeprom_pointer; const char * eeprom_buffer_data; volatile int8_t eeprom_buffer_size = 0; @@ -832,19 +833,22 @@ void RlcFile::nextRlcWriteStep() } } -#if !defined(CPUARM) void RlcFile::flush() { +#if !defined(CPUARM) while (eeprom_buffer_size > 0) wdt_reset(); +#endif ENABLE_SYNC_WRITE(true); + while (m_write_len && !s_write_err) nextWriteStep(); + while (isWriting() && !s_write_err) nextRlcWriteStep(); + ENABLE_SYNC_WRITE(false); } -#endif #if defined (EEPROM_PROGRESS_BAR) void RlcFile::DisplayProgressBar(uint8_t x) diff --git a/src/eeprom_rlc.h b/src/eeprom_rlc.h index 94458e684..669f828b7 100644 --- a/src/eeprom_rlc.h +++ b/src/eeprom_rlc.h @@ -148,14 +148,9 @@ class EFile #define ERR_FULL 1 extern uint8_t s_write_err; // error reasons -#if defined(CPUARM) -#define ENABLE_SYNC_WRITE(val) -#define IS_SYNC_WRITE_ENABLE() true -#else extern uint8_t s_sync_write; #define ENABLE_SYNC_WRITE(val) s_sync_write = val; #define IS_SYNC_WRITE_ENABLE() s_sync_write -#endif ///deliver current errno, this is reset in open inline uint8_t write_errno() { return s_write_err; } @@ -201,10 +196,8 @@ public: void nextRlcWriteStep(); void writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t *buf, uint16_t i_len, uint8_t sync_write); -#if !defined(CPUARM) // flush the current write operation if any void flush(); -#endif // read from opened file and decode rlc-coded data uint16_t readRlc(uint8_t *buf, uint16_t i_len); @@ -216,11 +209,7 @@ public: extern RlcFile theFile; //used for any file operation -#if defined(CPUARM) -#define eeFlush() -#else inline void eeFlush() { theFile.flush(); } -#endif #if defined (EEPROM_PROGRESS_BAR) #define DISPLAY_PROGRESS_BAR(x) theFile.DisplayProgressBar(x) diff --git a/src/gui/menu_model.cpp b/src/gui/menu_model.cpp index 464508e3e..cdda93fd0 100644 --- a/src/gui/menu_model.cpp +++ b/src/gui/menu_model.cpp @@ -1235,9 +1235,9 @@ void menuModelSetup(uint8_t event) CHECK_INCDEC_MODELVAR_ZERO(event, moduleData.channelsStart, 32-8-moduleData.channelsCount); break; case 1: - CHECK_INCDEC_MODELVAR_ZERO(event, moduleData.channelsCount, min(MAX_CHANNELS(moduleIdx), 32-8-moduleData.channelsStart)); + CHECK_INCDEC_MODELVAR(event, moduleData.channelsCount, -4, min(MAX_CHANNELS(moduleIdx), 32-8-moduleData.channelsStart)); if ((k == ITEM_MODEL_EXTERNAL_MODULE_CHANNELS && g_model.externalModule == MODULE_TYPE_PPM) || (k == ITEM_MODEL_TRAINER_CHANNELS)) - moduleData.ppmFrameLength = moduleData.channelsCount * 4; + SET_DEFAULT_PPM_FRAME_LENGTH(moduleIdx); break; } } @@ -1383,7 +1383,8 @@ void menuModelSetup(uint8_t event) case 1: #if defined(PCBSKY9X) CHECK_INCDEC_MODELVAR_ZERO(event, g_model.moduleData[0].channelsStart, 32-8-g_model.moduleData[0].channelsCount); - g_model.moduleData[0].ppmFrameLength = 4*(NUM_PORT1_CHANNELS()-8); + g_model.moduleData[0].ppmFrameLength = max((int8_t)0, g_model.moduleData[0].channelsCount) * 4; + SET_DEFAULT_PPM_FRAME_LENGTH(0); #else CHECK_INCDEC_MODELVAR(event, g_model.ppmNCH, -2, 4); g_model.ppmFrameLength = g_model.ppmNCH * 8; @@ -1393,7 +1394,7 @@ void menuModelSetup(uint8_t event) case 2: if (IS_PPM_PROTOCOL(protocol)) { CHECK_INCDEC_MODELVAR(event, g_model.moduleData[0].channelsCount, -4, min(8, 32-8-g_model.moduleData[0].channelsStart)); - g_model.moduleData[0].ppmFrameLength = 4*(NUM_PORT1_CHANNELS()-8); + SET_DEFAULT_PPM_FRAME_LENGTH(0); } else REPEAT_LAST_CURSOR_MOVE(); @@ -1415,11 +1416,11 @@ void menuModelSetup(uint8_t event) switch (m_posHorz) { case 0: CHECK_INCDEC_MODELVAR_ZERO(event, g_model.moduleData[1].channelsStart, 32-8-g_model.moduleData[1].channelsCount); - g_model.moduleData[1].ppmFrameLength = 4*(NUM_PORT2_CHANNELS()-8); + SET_DEFAULT_PPM_FRAME_LENGTH(1); break; case 1: CHECK_INCDEC_MODELVAR(event, g_model.moduleData[1].channelsCount, -4, min(8, 32-8-g_model.moduleData[1].channelsStart)); - g_model.moduleData[1].ppmFrameLength = 4*(NUM_PORT2_CHANNELS()-8); + SET_DEFAULT_PPM_FRAME_LENGTH(1); break; } } diff --git a/src/myeeprom.h b/src/myeeprom.h index 323d0d8cb..8b0d4ee11 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -228,6 +228,8 @@ PACK(typedef struct t_ModuleData { uint8_t ppmPulsePol; }) ModuleData; +#define SET_DEFAULT_PPM_FRAME_LENGTH(idx) g_model.moduleData[idx].ppmFrameLength = 4 * max((int8_t)0, g_model.moduleData[idx].channelsCount) + #if defined(PCBTARANIS) enum ModuleIndex { INTERNAL_MODULE, diff --git a/src/opentx.cpp b/src/opentx.cpp index e286ac99d..54d93a624 100644 --- a/src/opentx.cpp +++ b/src/opentx.cpp @@ -3602,16 +3602,18 @@ void perMain() if (Eeprom32_process_state != E32_IDLE) ee32_process(); else if (TIME_TO_WRITE()) - eeCheck(); + eeCheck(false); #elif defined(CPUARM) - if (TIME_TO_WRITE()) - eeCheck(); + if (theFile.isWriting()) + theFile.nextWriteStep(); + else if (TIME_TO_WRITE()) + eeCheck(false); #else if (!eeprom_buffer_size) { if (theFile.isWriting()) theFile.nextWriteStep(); else if (TIME_TO_WRITE()) - eeCheck(); + eeCheck(false); } #endif diff --git a/src/protocols/pxx_arm.cpp b/src/protocols/pxx_arm.cpp index 9a5e5eb03..b093ea4a7 100644 --- a/src/protocols/pxx_arm.cpp +++ b/src/protocols/pxx_arm.cpp @@ -186,11 +186,11 @@ void setupPulsesPXX(unsigned int port) /* PPM */ static uint32_t pass[NUM_MODULES] = { MODULES_INIT(0) }; - uint32_t sendUpperChannels = 0; + int sendUpperChannels = 0; if (pass[port]++ & 0x01) { sendUpperChannels = g_model.moduleData[port].channelsCount; } - for (uint32_t i=0; i<8; i++) { + for (int i=0; i<8; i++) { if (flag1 & PXX_SEND_FAILSAFE) { if (g_model.moduleData[port].failsafeMode == FAILSAFE_NOPULSES) { if (i < sendUpperChannels)