diff --git a/src/Makefile b/src/Makefile index 3250b9236..87ba897c7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -506,17 +506,16 @@ ifeq ($(PCB), X9D) # X9D radio OPT = 2 CPPDEFS += -DPCBX9D -DCPUARM -DEEPROM_VARIANT=0 -DAUDIO -DPXX - EXTRAINCDIRS += x9d CoOS/kernel CoOS/portable + EXTRAINCDIRS += CoOS/kernel CoOS/portable EXTRAINCDIRS += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include EXTRAINCDIRS += x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc EXTRAINCDIRS += x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/hid/inc BOARDSRC = x9d/board_x9d.cpp - EXTRABOARDSRC += x9d/lcd_driver.cpp x9d/aspi.cpp x9d/i2c.c + EXTRABOARDSRC += x9d/lcd_driver.cpp x9d/aspi.cpp x9d/i2c.c x9d/pwr_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/adc_driver.cpp x9d/trainer_driver.cpp x9d/audio_driver.cpp x9d/delays.cpp x9d/uart_driver.cpp x9d/sport_driver.cpp SRC += CoOS/kernel/core.c CoOS/kernel/hook.c CoOS/kernel/task.c CoOS/kernel/event.c CoOS/kernel/time.c CoOS/kernel/timer.c CoOS/kernel/flag.c CoOS/kernel/mutex.c CoOS/kernel/serviceReq.c CoOS/portable/GCC/port.c CoOS/portable/arch.c - EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp # TODO later eeprom_conversions.cpp + EEPROMSRC = eeprom_avr.cpp # TODO later eeprom_conversions.cpp PULSESSRC = pulses_arm.cpp CPPSRC += audio_arm.cpp - CPPSRC += x9d/pwr_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/adc_driver.cpp x9d/trainer_driver.cpp x9d/audio_driver.cpp x9d/delays.cpp x9d/uart_driver.cpp x9d/sport_driver.cpp CPPSRC += bmp.cpp monitors_views.cpp SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/misc.c @@ -571,7 +570,7 @@ ifeq ($(PCB), SKY9X) SRC += sky9x/usb/device/massstorage/MSDDriver.c sky9x/usb/device/massstorage/MSDDStateMachine.c sky9x/usb/device/massstorage/MSDLun.c sky9x/usb/device/massstorage/MSDDriverDescriptors.c sky9x/usb/device/massstorage/SBCMethods.c SRC += sky9x/usb/common/core/USBEndpointDescriptor.c sky9x/usb/common/core/USBGenericRequest.c sky9x/usb/common/core/USBFeatureRequest.c sky9x/usb/common/core/USBInterfaceRequest.c sky9x/usb/common/core/USBGetDescriptorRequest.c sky9x/usb/common/core/USBSetAddressRequest.c sky9x/usb/common/core/USBSetConfigurationRequest.c sky9x/usb/common/core/USBConfigurationDescriptor.c sky9x/usb/common/core/USBGenericDescriptor.c SRC += sky9x/MEDSdcard.c - EEPROMSRC = eeprom_common.cpp eeprom_raw.cpp eeprom_conversions.cpp + EEPROMSRC = eeprom_arm.cpp eeprom_conversions.cpp PULSESSRC = pulses_arm.cpp CPPSRC += audio_arm.cpp haptic.cpp CPPSRC += sky9x/pwr_driver.cpp sky9x/adc_driver.cpp sky9x/coproc_driver.cpp sky9x/rotenc_driver.cpp sky9x/eeprom_driver.cpp sky9x/pulses_driver.cpp sky9x/keys_driver.cpp sky9x/audio_driver.cpp sky9x/buzzer_driver.cpp sky9x/haptic_driver.cpp sky9x/sdcard_driver.cpp sky9x/massstorage.cpp @@ -606,7 +605,7 @@ ifeq ($(PCB), GRUVIN9X) EXTRAINCDIRS += gruvin9x stock FatFs FatFs/option BOARDSRC += gruvin9x/board_gruvin9x.cpp EXTRABOARDSRC += stock/lcd_driver.cpp - EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp + EEPROMSRC = eeprom_avr.cpp PULSESSRC = pulses_avr.cpp CPPSRC += audio_avr.cpp haptic.cpp @@ -634,7 +633,7 @@ ifeq ($(PCB), $(filter $(PCB), STD128 9X128 9XR128)) EXTRAINCDIRS += stock BOARDSRC = stock/board_stock.cpp EXTRABOARDSRC += stock/lcd_driver.cpp - EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp + EEPROMSRC = eeprom_avr.cpp PULSESSRC = pulses_avr.cpp ifeq ($(PCB), 9XR128) @@ -680,7 +679,7 @@ ifeq ($(PCB), $(filter $(PCB), STD 9X 9XR)) CPPDEFS += -DPCBSTD -DCPUM64 -DEEPROM_VARIANT=$(shell echo ${EEPROM_VARIANT} | bc) BOARDSRC = stock/board_stock.cpp EXTRABOARDSRC += stock/lcd_driver.cpp - EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp + EEPROMSRC = eeprom_avr.cpp PULSESSRC = pulses_avr.cpp ifeq ($(PCB), 9XR) diff --git a/src/debug.cpp b/src/debug.cpp index f4fba14e1..de8609635 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -40,8 +40,8 @@ #if !defined(SIMU) -Fifo<512> debugRxFifo; -Fifo<512> debugTxFifo; +Fifo512 debugRxFifo; +Fifo512 debugTxFifo; // Outputs a string to the UART void debugPuts(const char *format, ...) @@ -61,17 +61,17 @@ void debugPuts(const char *format, ...) void dump(unsigned char *data, unsigned int size) { - debugPuts("DUMP %d bytes ...\n\r", size); - unsigned int i = 0, j=0; - while (i*32+j < size) { - debugPuts("%.2X ", data[i*32+j]); - j++; - if (j==32) { - i++; j=0; - debugPuts("\n\r"); - } - } - debugPuts("\n\r"); + debugPuts("DUMP %d bytes ...\n\r", size); + unsigned int i = 0, j=0; + while (i*32+j < size) { + debugPuts("%.2X ", data[i*32+j]); + j++; + if (j==32) { + i++; j=0; + debugPuts("\n\r"); + } + } + debugPuts("\n\r"); } void debugTask(void* pdata) @@ -87,9 +87,9 @@ void debugTask(void* pdata) void debugTx(void) { - uint8_t txchar; - - if (debugTxFifo.pop(txchar)) - debugPutc(txchar); + uint8_t txchar; + + if(debugTxFifo.pop(txchar)) + debugPutc(txchar); } #endif diff --git a/src/eeprom_raw.cpp b/src/eeprom_arm.cpp similarity index 98% rename from src/eeprom_raw.cpp rename to src/eeprom_arm.cpp index 0ad2b5c92..da33df48a 100644 --- a/src/eeprom_raw.cpp +++ b/src/eeprom_arm.cpp @@ -40,6 +40,8 @@ #include "string.h" volatile uint32_t Spi_complete; // TODO in the driver ? +uint8_t s_eeDirtyMsk; +tmr10ms_t s_eeDirtyTime10ms; // Logic for storing to EEPROM/loading from EEPROM // If main needs to wait for the eeprom, call mainsequence without actioning menus @@ -76,8 +78,15 @@ uint32_t Eeprom32_data_size ; #define EE_NOWAIT 1 +void eeDirty(uint8_t msk) +{ + s_eeDirtyMsk |= msk; + s_eeDirtyTime10ms = get_tmr10ms() ; +} + uint32_t get_current_block_number( uint32_t block_no, uint16_t *p_size, uint32_t *p_seq ) ; void write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate=0 ) ; +void eeLoadModelNames( void ) ; // New file system @@ -351,6 +360,8 @@ bool eeLoadGeneral() void eeLoadModel(uint8_t id) { + uint16_t size; + if (id sizeof(g_model)) { size = sizeof(g_model) ; } - + if(size < 256) { // if not loaded a fair amount modelDefault(id) ; eeCheck(true); @@ -434,19 +445,12 @@ void eeLoadModelName(uint8_t id, char *name) } } -#if defined(PXX) -uint8_t eeLoadModelId(uint8_t id) +void eeLoadModelNames() { - uint8_t modelId = 0; - if (id < MAX_MODELS) { - id += 1; - if (File_system[id].size > sizeof(g_model.name) + 1) { - read32_eeprom_data( ( File_system[id].block_no << 12) + 8 + sizeof(g_model.name), &modelId, 1); - } + for (uint32_t i=0; i #include +#if defined(SIMU) +#define WRITE_DELAY_10MS 200 +#elif defined(PCBSKY9X) && defined(REV0) +#define WRITE_DELAY_10MS 200 +#else +#define WRITE_DELAY_10MS 500 +#endif + +extern uint8_t s_eeDirtyMsk; +extern tmr10ms_t s_eeDirtyTime10ms; + // States in Eeprom32_process_state #define E32_IDLE 1 #define E32_ERASESENDING 2 @@ -66,10 +77,6 @@ extern bool eeModelExists(uint8_t id) ; extern bool eeCopyModel(uint8_t dst, uint8_t src); extern void eeSwapModels(uint8_t id1, uint8_t id2); -#if defined(PXX) -uint8_t eeLoadModelId(uint8_t id); -#endif - #define DISPLAY_PROGRESS_BAR(x) struct t_file_entry diff --git a/src/eeprom_rlc.cpp b/src/eeprom_avr.cpp similarity index 98% rename from src/eeprom_rlc.cpp rename to src/eeprom_avr.cpp index e6ef83cff..c48884972 100644 --- a/src/eeprom_rlc.cpp +++ b/src/eeprom_avr.cpp @@ -40,10 +40,18 @@ #include "string.h" uint8_t s_write_err = 0; // error reasons +uint8_t s_eeDirtyMsk; +tmr10ms_t s_eeDirtyTime10ms; RlcFile theFile; //used for any file operation EeFs eeFs; +void eeDirty(uint8_t msk) +{ + s_eeDirtyMsk |= msk; + s_eeDirtyTime10ms = get_tmr10ms(); +} + #if !defined(CPUARM) uint8_t s_sync_write = false; uint16_t eeprom_pointer; @@ -829,6 +837,7 @@ bool eeLoadGeneral() return false; } + void eeLoadModelName(uint8_t id, char *name) { memclear(name, sizeof(g_model.name)); @@ -838,14 +847,16 @@ void eeLoadModelName(uint8_t id, char *name) } } -#if defined(PXX) -// must be called just after eeLoadModelName! -uint8_t eeLoadModelIdAfterName() +#if defined(CPUARM) +// TODO same function in eeprom_arm.cpp +void eeLoadModelNames() { - uint8_t modelId = 0; - theFile.readRlc(&modelId, sizeof(modelId)); - return modelId; + for (uint32_t i=0; i +#if defined(SIMU) +#define WRITE_DELAY_10MS 200 +#elif defined(PCBX9D) +#define WRITE_DELAY_10MS 1000 +#elif defined(PCBGRUVIN9X) && !defined(REV0) +#define WRITE_DELAY_10MS 500 +#else +#define WRITE_DELAY_10MS 200 +#endif + +extern uint8_t s_eeDirtyMsk; +extern tmr10ms_t s_eeDirtyTime10ms; + #if defined(CPUARM) #define blkid_t uint16_t #define EESIZE (32*1024) @@ -140,11 +153,6 @@ class EFile #define eeFileSize(f) eeFs.files[f].size #define eeModelSize(id) eeFileSize(FILE_MODEL(id)) -#if defined(PXX) -uint8_t eeLoadModelIdAfterName(); -#define eeLoadModelId(id) eeLoadModelIdAfterName() -#endif - #define ERR_NONE 0 #define ERR_FULL 1 extern uint8_t s_write_err; // error reasons diff --git a/src/eeprom_common.cpp b/src/eeprom_common.cpp deleted file mode 100644 index 2f4d0271a..000000000 --- a/src/eeprom_common.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Authors (alphabetical order) - * - Andre Bernet - * - Andreas Weitl - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - Cameron Weeks - * - Erez Raviv - * - Gabriel Birkus - * - Jean-Pierre Parisy - * - Karl Szmutny - * - Michael Blandford - * - Michal Hlavinka - * - Pat Mackenzie - * - Philip Moss - * - Rob Thomson - * - Romolo Manfredini - * - Thomas Husterer - * - * open9x is based on code named - * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, - * er9x by Erez Raviv: http://code.google.com/p/er9x/, - * and the original (and ongoing) project by - * Thomas Husterer, th9x: http://code.google.com/p/th9x/ - * - * 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 -#include "open9x.h" -#include "inttypes.h" -#include "string.h" - -uint8_t s_eeDirtyMsk; -tmr10ms_t s_eeDirtyTime10ms; - -void eeDirty(uint8_t msk) -{ - s_eeDirtyMsk |= msk; - s_eeDirtyTime10ms = get_tmr10ms() ; -} - -#if defined(CPUARM) - -char modelNames[MAX_MODELS][sizeof(g_model.name)]; - -#if defined(PXX) -uint8_t modelIds[MAX_MODELS]; -#endif - -void eeLoadModelNames() -{ - for (uint32_t i=0; i - * - Andreas Weitl - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - Cameron Weeks - * - Erez Raviv - * - Gabriel Birkus - * - Jean-Pierre Parisy - * - Karl Szmutny - * - Michael Blandford - * - Michal Hlavinka - * - Pat Mackenzie - * - Philip Moss - * - Rob Thomson - * - Romolo Manfredini - * - Thomas Husterer - * - * open9x is based on code named - * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, - * er9x by Erez Raviv: http://code.google.com/p/er9x/, - * and the original (and ongoing) project by - * Thomas Husterer, th9x: http://code.google.com/p/th9x/ - * - * 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. - * - */ - -#if defined(SIMU) - #define WRITE_DELAY_10MS 200 -#elif defined(PCBX9D) - #define WRITE_DELAY_10MS 500 -#elif defined(PCBSKY9X) && !defined(REV0) - #define WRITE_DELAY_10MS 500 -#elif defined(PCBGRUVIN9X) && !defined(REV0) - #define WRITE_DELAY_10MS 500 -#else - #define WRITE_DELAY_10MS 200 -#endif - -extern uint8_t s_eeDirtyMsk; -extern tmr10ms_t s_eeDirtyTime10ms; - -void eeDirty(uint8_t msk); -void eeCheck(bool immediately=false); -void eeReadAll(); -bool eeModelExists(uint8_t id); -void eeLoadModelName(uint8_t id, char *name); -void eeLoadModel(uint8_t id); - -#if defined(CPUARM) - -extern char modelNames[MAX_MODELS][sizeof(g_model.name)]; -void eeLoadModelNames(); - -#if defined(PXX) -extern uint8_t modelIds[MAX_MODELS]; -#endif - -#else // defined(CPUARM) - -#define eeLoadModelNames() - -#endif diff --git a/src/fifo.h b/src/fifo.h index 0b2158ebb..af90a7306 100644 --- a/src/fifo.h +++ b/src/fifo.h @@ -37,18 +37,17 @@ #ifndef fifo_h #define fifo_h -template -class Fifo +class Fifo512 { public: - Fifo(): + Fifo512(): widx(0), ridx(0) { } void push(uint8_t byte) { - uint32_t next = (widx+1) & (N-1); + uint32_t next = (widx+1) & 0x1ff; if (next != ridx) { fifo[widx] = byte; widx = next; @@ -61,13 +60,13 @@ class Fifo } else { byte = fifo[ridx]; - ridx = (ridx+1) & (N-1); + ridx = (ridx+1) & 0x1ff; return true; } } protected: - uint8_t fifo[N]; + uint8_t fifo[512]; volatile uint32_t widx; volatile uint32_t ridx; }; diff --git a/src/gruvin9x/board_gruvin9x.h b/src/gruvin9x/board_gruvin9x.h index c6e6d4bcc..83c59c545 100644 --- a/src/gruvin9x/board_gruvin9x.h +++ b/src/gruvin9x/board_gruvin9x.h @@ -70,7 +70,6 @@ #define TIMER_16KHZ_VECT TIMER2_OVF_vect #define COUNTER_16KHZ TCNT2 #define TIMER_10MS_VECT TIMER2_COMPA_vect -#define TIMER_10MS_COMPVAL OCR2A #define PAUSE_10MS_INTERRUPT() TIMSK2 &= ~(1<0 || p1valdiff))) { + if (attr && (m_posHorz==0 && (editMode>0 || p1valdiff))) CHECK_INCDEC_MODELVAR_ZERO(event, g_model.modelId, 99); -#if defined(CPUARM) - if (checkIncDec_Ret) - modelIds[g_eeGeneral.currModel] = g_model.modelId; -#endif - } #if defined(PXX) if (protocol == PROTO_PXX) { -#if defined(CPUARM) - if (attr && m_posHorz==0 && editMode==0 && event==EVT_KEY_BREAK(KEY_ENTER)) - checkModelIdUnique(g_eeGeneral.currModel); -#endif - lcd_putsAtt(MODEL_SETUP_2ND_COLUMN, y, STR_SYNCMENU, (m_posHorz==1 ? attr : 0)); if (attr && m_posHorz==1) { s_editMode = 0; - if (event==EVT_KEY_LONG(KEY_ENTER)) { + if (event==EVT_KEY_LONG(KEY_MENU)) { // send reset code pxxFlag = PXX_SEND_RXNUM; } @@ -1101,7 +1091,7 @@ void menuModelSetup(uint8_t event) #if defined(DSM2) if (IS_DSM2_PROTOCOL(protocol)) { - lcd_putsiAtt(MODEL_SETUP_2ND_COLUMN, y, PSTR("\013Range"TR_ENTER"Norm "TR_ENTER), s_rangecheck_mode, (m_posHorz==1 ? attr : 0)); + lcd_putsiAtt(MODEL_SETUP_2ND_COLUMN, y, PSTR("\013Range[MENU]Norm [MENU]"), s_rangecheck_mode, (m_posHorz==1 ? attr : 0)); s_rangecheck_mode = (attr && m_posHorz==1 && editMode>0); // [MENU] key toggles range check mode } #endif diff --git a/src/myeeprom.h b/src/myeeprom.h index 4f4cf66bc..7a51c4e11 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -1104,7 +1104,6 @@ enum Protocols { PACK(typedef struct t_ModelData { char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName - uint8_t modelId; TimerData timers[MAX_TIMERS]; uint8_t protocol:3; uint8_t thrTrim:1; // Enable Throttle Trim @@ -1131,6 +1130,7 @@ PACK(typedef struct t_ModelData { int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5ms increments uint8_t thrTraceSrc; + uint8_t modelId; swstate_t switchWarningStates; diff --git a/src/open9x.cpp b/src/open9x.cpp index a3110bc92..74df6e72e 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -68,6 +68,8 @@ OS_FlagID audioFlag; OS_MutexID audioMutex; OS_MutexID mixerMutex; +char modelNames[MAX_MODELS][sizeof(g_model.name)]; + #endif // defined(CPUARM) #if defined(SPLASH) @@ -270,6 +272,7 @@ void per10ms() rePreviousValue = reNewValue; putEvent(scrollRE < 0 ? EVT_ROTARY_LEFT : EVT_ROTARY_RIGHT); } + extern uint8_t s_evt; uint8_t evt = s_evt; if (EVT_KEY_MASK(evt) == BTN_REa + NAVIGATION_RE_IDX()) { if (IS_KEY_BREAK(evt)) { @@ -282,7 +285,7 @@ void per10ms() } #endif -#if (defined(FRSKY) || defined(MAVLINK) || defined(JETI)) && !defined(CPUARM) +#if (defined(FRSKY) || defined(MAVLINK) || defined(JETI)) && !defined(CPUARM) && !(defined(PCBSTD) && (defined(AUDIO) || defined(VOICE))) if (!IS_DSM2_SERIAL_PROTOCOL(s_current_protocol)) telemetryPoll10ms(); #endif @@ -382,7 +385,7 @@ uint16_t evalChkSum() return sum; } -#if !defined(TEMPLATES) +#ifndef TEMPLATES inline void applyDefaultTemplate() { for (int i=0; i80) { extended=true; - } - else { + } else { k+=(k>>2); // use bigger values before extend, because the effect is anyway very very low extended=false; } // endif k > 50 @@ -784,40 +769,42 @@ int16_t applyLimits(uint8_t channel, int32_t value) if (ofs > lim_p) ofs = lim_p; if (ofs < lim_n) ofs = lim_n; - // because the rescaling optimization would reduce the calculation reserve we activate this for all builds - // it increases the calculation reserve from factor 20,25x to 32x, which it slightly better as original - // without it we would only have 16x which is slightly worse as original, we should not do this - +// because the recaling optimization would reduce the calculation reserve we activate this for all builds +// it increases the caculation reserve from factor 20,25x to 32x, which it slightly better as original +// without it we would only have 16x which is slightly worse as original, we should not do this +// #ifdef PREVENT_ARITHMETIC_OVERFLOW // thanks to gbirkus, he motivated this change, which greatly reduces overruns // unfortunately the constants and 32bit compares generates about 50 bytes codes; didn't find a way to get it down. - value = limit(int32_t(-RESXl*256), value, int32_t(RESXl*256)); // saves 2 bytes compared to other solutions up to now + + value = limit(int32_t(-RESXl*256),value,int32_t(RESXl*256)); // saves 2 bytes compared to other solutions up to now +// #endif #if defined(PPM_LIMITS_SYMETRICAL) if (value) { - int16_t tmp; + int16_t tmp; if (lim->symetrical) tmp = (value > 0) ? (lim_p) : (-lim_n); else tmp = (value > 0) ? (lim_p - ofs) : (-lim_n + ofs); - value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024 + value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024 #else if (value) { int16_t tmp = (value > 0) ? (lim_p - ofs) : (-lim_n + ofs); - value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024 + value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024 #endif #ifdef CORRECT_NEGATIVE_SHIFTS - int8_t sign = (value<0?1:0); - value -= sign; - tmp = value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes; - tmp >>= 2; // now one simple shift right for two bytes does the rest - tmp += sign; + int8_t sign=(value<0?1:0); + value-=sign; + tmp=value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes; + tmp>>=2; // now one simple shift right for two bytes does the rest + tmp+=sign; #else - tmp = value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes; - tmp >>= 2; // now one simple shift right for two bytes does the rest + tmp=value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes; + tmp>>=2; // now one simple shift right for two bytes does the rest #endif - ofs += tmp; // ofs can to added directly because already recalculated, + ofs+=tmp; // ofs can to added directly because already recalculated, } if (ofs > lim_p) ofs = lim_p; @@ -875,7 +862,8 @@ int16_t getValue(uint8_t i) #endif else if (i=0 && k<8 && !IS_KEY_BREAK(event)) { #endif // LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP - uint8_t idx = CONVERT_MODE(1+(uint8_t)k/2) - 1; + uint8_t idx = CONVERT_MODE(1+k/2) - 1; uint8_t phase; int16_t before; bool thro; @@ -1827,19 +1814,18 @@ uint16_t anaIn(uint8_t chan) #if defined(PCBX9D) // crossAna[]={LH,LV,RH,RV,S1,S2,LS,RS,BAT // s_anaFilt[]={LH,LV,RH,RV,S1,S2,LS,RS,_BAT - return s_anaFilt[chan]; + static const uint8_t crossAna[]={0,1,2,3,4,5,6,7,8}; #elif defined(PCBSKY9X) && !defined(REVA) static const uint8_t crossAna[]={1,5,7,0,4,6,2,3}; if (chan == TX_CURRENT) { return Current_analogue ; } - volatile uint16_t *p = &s_anaFilt[pgm_read_byte(crossAna+chan)]; - return *p; #else - static const pm_char crossAna[] PROGMEM = {3,1,2,0,4,5,6,7}; + static const pm_char crossAna[] PROGMEM ={3,1,2,0,4,5,6,7}; +#endif + volatile uint16_t *p = &s_anaFilt[pgm_read_byte(crossAna+chan)]; return *p; -#endif } #if defined(CPUARM) @@ -1907,7 +1893,7 @@ void getADC_bandgap() ADCSRB |= (1<speedUp || md->speedDown)) { // there are delay values #define DEL_MULT_SHIFT 8 // we recale to a mult 256 higher value for calculation - int32_t tact = act[i]; - int16_t diff = v - (tact>>DEL_MULT_SHIFT); + int16_t diff = v - ((int32_t) act[i]>>DEL_MULT_SHIFT); if (diff) { // open.20.fsguruh: speed is defined in % movement per second; In menu we specify the full movement (-100% to 100%) = 200% in total // the unit of the stored value is the value from md->speedUp or md->speedDown divide SLOW_STEP seconds; e.g. value 4 means 4/SLOW_STEP = 2 seconds for CPU64 @@ -2837,21 +2819,21 @@ void perOut(uint8_t mode, uint8_t tick10ms) if (diff>0) { if (md->speedUp>0) { // if a speed upwards is defined recalculate the new value according configured speed; the higher the speed the smaller the add value is - int32_t newValue = tact+rate/((int16_t)(100/SLOW_STEP)*md->speedUp); + int32_t newValue = act[i]+rate/((int16_t)(100/SLOW_STEP)*md->speedUp); if (newValuespeedDown>0) { // see explanation in speedUp - int32_t newValue = tact-rate/((int16_t)(100/SLOW_STEP)*md->speedDown); + int32_t newValue = act[i]-rate/((int16_t)(100/SLOW_STEP)*md->speedDown); if (newValue>currentValue) currentValue=newValue; // Endposition; prevent toggling around the destination } } //endif diff>0 - act[i] = tact = currentValue; + act[i] = currentValue; // open.20.fsguruh: this implementation would save about 50 bytes code } // endif tick10ms ; in case no time passed assign the old value, not the current value from source - v = (tact >> DEL_MULT_SHIFT); + v = (act[i] >> DEL_MULT_SHIFT); } //endif diff } //endif speed @@ -3541,13 +3523,24 @@ uint16_t getTmr16KHz() } } -#if defined(PCBSTD) && (defined(AUDIO) || defined(VOICE)) -// Clocks every 128 uS -ISR(TIMER2_OVF_vect, ISR_NOBLOCK) + + +// new implementation + +// This ISR is only called if timer matches OCR0. We updated OCR0 on each call to make ISR happen. +// If we do not do this, we have 16,385msec time before overflow causes an IRQ +// So it's so easy instead of preventing IRQ we +//just do not cause it! It's enough not to write to OCR0. This gives plenty of time to finish ISR. +// So instead of masking we write OCR0 at the end. Max would be ISR is caused here immediately, which would not do anything, +// because all critical pfathes are finished. It also would give us the chance to measure if we passed the next tick and count it. +// It's already implemented but commented out, because of code cost. + +ISR(TIMER_10MS_VECT, ISR_NOBLOCK) +// 10ms timer { - cli(); - TIMSK &= ~ (1< no problem + +#if defined(FRSKY) || defined(MAVLINK) || defined(JETI) + if (cnt10ms == 30) { + if (!IS_DSM2_SERIAL_PROTOCOL(s_current_protocol)) + telemetryPoll10ms(); + } #endif -// Clocks every 10ms -ISR(TIMER_10MS_VECT, ISR_NOBLOCK) -{ - // without correction we are 0,16% too fast; that mean in one hour we are 5,76Sek too fast; we do not like that - static uint8_t accuracyWarble; // because 16M / 1024 / 100 = 156.25. we need to correct the fault; no start value needed + if (--cnt10ms == 0) { // BEGIN { ... every 10ms ... } + // Begin 10ms event + // cnt10ms = 78; + cnt10ms = (!(++accuracyWarble &0x07)) ? 79 : 78; // instead of assigning we add to take missed ISRs into account + // each per10ms() we are 0,016msec too fast + // one tick more means 0,112 msec too slow = 7*0,016msec --> in sum we are correct!!! + // therefore every 8. round we need to slow down one tick + +#endif - AUDIO_HEARTBEAT(); + AUDIO_HEARTBEAT(); #if defined(HAPTIC) - HAPTIC_HEARTBEAT(); + HAPTIC_HEARTBEAT(); #endif - per10ms(); + per10ms(); +#if defined(PCBSTD) && (defined(AUDIO) || defined(VOICE)) + } // end 10ms event +#endif + + // without correction we are 0,16% too fast; that mean in one hour we are 5,76Sek too fast; we do not like that +#if defined(PCBGRUVIN9X) + // static uint8_t accuracyWarble; // because 16M / 1024 / 100 = 156.25. we need to correct the fault; not start value needed uint8_t bump = (!(++accuracyWarble & 0x03)) ? 157 : 156; - TIMER_10MS_COMPVAL += bump; + OCR2A += bump; +#elif defined(AUDIO) || defined(VOICE) + // simple solution; if ISR tooks longer this round is just ignored; The problem in this case is, it takes 16msec for the next ISR --> big gap in AUDIO, VOICE and a big fault in time calculaiton if it happens + // cnt10ms--; + OCR0 += 2; // interrupt every 128us +/* + // needs to change cnt10ms to int instead uint to allow cnt10ms to be negative + // also remove cnt10ms-- in if statement above, because substraction is done here + // code oost: 34 bytes + // this solutions all missed ISRs are counted and next ISR is in about 128usec (exception is wrap around) + cli(); + do { + cnt10ms--; + OCR0 += 2; // interrupt every 128us + } while ((OCR0=2)); // loop in case ISR tooks too long; If it laps around, ignore additional calcuation and stop anyway + // sei(); will be done anyway if ISR is left + */ +#else + // static uint8_t accuracyWarble; // because 16M / 1024 / 100 = 156.25. we need to correct the fault; not start value needed + // each tick we are 0,016msec too fast + // one tick more means 0,048 msec too slow = 3*0,016msec --> in sum we are correct!!! + // therefore every 4 round we need to slow down one tick + uint8_t bump = (!(++accuracyWarble & 0x03)) ? 157 : 156; + OCR0 += bump; +#endif + } + // Timer3 used for PPM_IN pulse width capture. Counter running at 16MHz / 8 = 2MHz // equating to one count every half millisecond. (2 counts = 1ms). Control channel // count delta values thus can range from about 1600 to 4400 counts (800us to 2200us), @@ -3999,14 +4032,10 @@ void menusTask(void * pdata) while (pwrCheck() != e_power_off) { perMain(); -#if defined(PCBSKY9X) for (uint8_t i=0; i<5; i++) { usbMassStorage(); CoTickDelay(1); // 5*2ms for now } -#else - CoTickDelay(5); // 5*2ms for now -#endif } #if defined(SDCARD) @@ -4114,7 +4143,7 @@ int main(void) open9xInit(mcusr); #endif -#if defined(PCBSKY9X) +#if defined(CPUARM) if (BOOTLOADER_REQUEST()) { pwrOff(); // Only turn power off if necessary diff --git a/src/open9x.h b/src/open9x.h index 9e0b27e31..ab5b49a95 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -362,6 +362,10 @@ enum EnumKeys { #define PPM_CH_CENTER(ch) (PPM_CENTER) #endif +#if defined(CPUARM) +extern char modelNames[MAX_MODELS][sizeof(g_model.name)]; +#endif + #if defined(CPUARM) // This doesn't need protection on this processor #define tmr10ms_t uint32_t @@ -380,11 +384,11 @@ extern inline uint16_t get_tmr10ms() } #endif -#include "eeprom_common.h" +// TODO try to merge the 2 include files #if defined(PCBSKY9X) -#include "eeprom_raw.h" +#include "eeprom_arm.h" #else -#include "eeprom_rlc.h" +#include "eeprom_avr.h" #endif #if defined(CPUARM) @@ -649,17 +653,18 @@ extern uint8_t pxxFlag; extern char idx2char(int8_t idx); -extern uint8_t s_evt; -#define putEvent(evt) s_evt = evt void clearKeyEvents(); void pauseEvents(uint8_t enuk); void killEvents(uint8_t enuk); + #if defined(CPUARM) uint8_t getEvent(bool trim); #else uint8_t getEvent(); #endif +void putEvent(uint8_t evt); + uint8_t keyDown(); enum PowerState { @@ -947,13 +952,15 @@ void saveTimers(); #define saveTimers() #endif +void eeDirty(uint8_t msk); +void eeCheck(bool immediately=false); +void eeReadAll(); +bool eeModelExists(uint8_t id); +void eeLoadModelName(uint8_t id, char *name); +void eeLoadModel(uint8_t id); void generalDefault(); void modelDefault(uint8_t id); -#if defined(PXX) && defined(CPUARM) -void checkModelIdUnique(uint8_t id); -#endif - #if defined(CPUARM) inline int16_t calc100to256_16Bits(register int16_t x) // @@@2 open.20.fsguruh: return x*2.56 { diff --git a/src/simpgmspace.h b/src/simpgmspace.h index 7f010fe88..2dabc7a7a 100644 --- a/src/simpgmspace.h +++ b/src/simpgmspace.h @@ -97,7 +97,6 @@ typedef const uint16_t pm_uint16_t; typedef const uint8_t pm_uint8_t; typedef const int16_t pm_int16_t; typedef const int8_t pm_int8_t; -typedef int32_t __int24; #if defined(PCBX9D) || defined(PCBACT) extern GPIO_TypeDef gpioa; diff --git a/src/sky9x/bluetooth.cpp b/src/sky9x/bluetooth.cpp index cdd05f778..8cde679b5 100644 --- a/src/sky9x/bluetooth.cpp +++ b/src/sky9x/bluetooth.cpp @@ -49,8 +49,8 @@ void btInit() } OS_FlagID btFlag; -Fifo<32> btTxFifo; -Fifo<32> btRxFifo; +Fifo32 btTxFifo; +Fifo32 btRxFifo; struct t_serial_tx btTx ; uint8_t btTxBuffer[32] ; diff --git a/src/sky9x/debug_driver.cpp b/src/sky9x/debug_driver.cpp index db6a6df68..4a7a04305 100644 --- a/src/sky9x/debug_driver.cpp +++ b/src/sky9x/debug_driver.cpp @@ -39,7 +39,7 @@ #if !defined(SIMU) -extern Fifo<512> debugRxFifo; +extern Fifo512 debugRxFifo; /* * Outputs a character on the UART line. diff --git a/src/stock/board_stock.cpp b/src/stock/board_stock.cpp index c798c505b..029894148 100644 --- a/src/stock/board_stock.cpp +++ b/src/stock/board_stock.cpp @@ -102,22 +102,29 @@ inline void boardInit() DDRB = 0x81; PORTB = 0x7e; //pullups keys+nc DDRC = 0x3e; PORTC = 0xc1; //pullups nc DDRD = 0x00; PORTD = 0xff; //pullups keys - DDRE = (1<> 24); - MSC_BOT_Data[1] = (uint8_t)((SCSI_blk_nbr - 1) >> 16); - MSC_BOT_Data[2] = (uint8_t)((SCSI_blk_nbr - 1) >> 8); + MSC_BOT_Data[0] = (uint8_t)(SCSI_blk_nbr - 1 >> 24); + MSC_BOT_Data[1] = (uint8_t)(SCSI_blk_nbr - 1 >> 16); + MSC_BOT_Data[2] = (uint8_t)(SCSI_blk_nbr - 1 >> 8); MSC_BOT_Data[3] = (uint8_t)(SCSI_blk_nbr - 1); MSC_BOT_Data[4] = (uint8_t)(SCSI_blk_size >> 24); @@ -309,9 +309,9 @@ static int8_t SCSI_ReadFormatCapacity(uint8_t lun, uint8_t *params) else { MSC_BOT_Data[3] = 0x08; - MSC_BOT_Data[4] = (uint8_t)((blk_nbr - 1) >> 24); - MSC_BOT_Data[5] = (uint8_t)((blk_nbr - 1) >> 16); - MSC_BOT_Data[6] = (uint8_t)((blk_nbr - 1) >> 8); + MSC_BOT_Data[4] = (uint8_t)(blk_nbr - 1 >> 24); + MSC_BOT_Data[5] = (uint8_t)(blk_nbr - 1 >> 16); + MSC_BOT_Data[6] = (uint8_t)(blk_nbr - 1 >> 8); MSC_BOT_Data[7] = (uint8_t)(blk_nbr - 1); MSC_BOT_Data[8] = 0x02; diff --git a/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc/usbd_core.h b/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc/usbd_core.h index 184e8d4a7..6fd3230e9 100644 --- a/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc/usbd_core.h +++ b/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc/usbd_core.h @@ -30,7 +30,7 @@ #define __USBD_CORE_H /* Includes ------------------------------------------------------------------*/ -#include "../../../STM32_USB_OTG_Driver/inc/usb_dcd.h" +#include "usb_dcd.h" #include "usbd_def.h" #include "../../../../../usbd_conf.h" diff --git a/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_core.h b/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_core.h index d44003b4f..0a0690b8f 100644 --- a/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_core.h +++ b/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_core.h @@ -30,7 +30,7 @@ #define __USB_CORE_H__ /* Includes ------------------------------------------------------------------*/ -#include "../../../../usb_conf.h" +#include "../../../../../usb_conf.h" #include "usb_regs.h" #include "usb_defines.h" diff --git a/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h b/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h index 6924276a6..73b63bda3 100644 --- a/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h +++ b/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_defines.h @@ -30,7 +30,7 @@ #define __USB_DEF_H__ /* Includes ------------------------------------------------------------------*/ -#include "../../../../usb_conf.h" +#include "../../../../../usb_conf.h" /** @addtogroup USB_OTG_DRIVER * @{ diff --git a/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_regs.h b/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_regs.h index 5bb42e1b7..898e55a1d 100644 --- a/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_regs.h +++ b/src/x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_regs.h @@ -30,7 +30,7 @@ #define __USB_OTG_REGS_H__ /* Includes ------------------------------------------------------------------*/ -#include "../../../../usb_conf.h" +#include "../../../../../usb_conf.h" /** @addtogroup USB_OTG_DRIVER diff --git a/src/x9d/board_x9d.cpp b/src/x9d/board_x9d.cpp index 2e31e6954..09958bba9 100644 --- a/src/x9d/board_x9d.cpp +++ b/src/x9d/board_x9d.cpp @@ -36,7 +36,7 @@ #include "../open9x.h" extern "C" { -#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" +#include "x9d/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" } // TODO needed? @@ -128,7 +128,14 @@ void start_ppm_capture() { } -#if !defined(SIMU) +void usbBootloader() +{ +} + +void usbMassStorage() +{ +} + extern "C" { USB_OTG_CORE_HANDLE USB_OTG_dev; @@ -142,7 +149,6 @@ void usbInit() { USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb); } -#endif void watchdogInit() { diff --git a/src/x9d/board_x9d.h b/src/x9d/board_x9d.h index 3f132770f..647549915 100644 --- a/src/x9d/board_x9d.h +++ b/src/x9d/board_x9d.h @@ -63,6 +63,8 @@ extern "C" { #define TIMER_MULT_APB1 2 #define TIMER_MULT_APB2 1 +void usbMassStorage(); + #define JACK_PPM_OUT() #define JACK_PPM_IN() diff --git a/src/x9d/pwr_driver.cpp b/src/x9d/pwr_driver.cpp index 3fab5d494..e57fe1796 100644 --- a/src/x9d/pwr_driver.cpp +++ b/src/x9d/pwr_driver.cpp @@ -50,10 +50,10 @@ uint32_t pwrCheck() return e_power_on; #if !defined(REV3) else if (GPIO_ReadInputDataBit(GPIOTRNDET, PIN_TRNDET) == Bit_SET) - return e_power_trainer; + return e_power_trainer; #endif else if (usbPlugged()) - return e_power_usb; + return e_power_usb; else return e_power_off; #endif diff --git a/src/x9d/usbd_desc.h b/src/x9d/usbd_desc.h index a6dc86291..e28e14ae0 100644 --- a/src/x9d/usbd_desc.h +++ b/src/x9d/usbd_desc.h @@ -31,7 +31,7 @@ #define __USB_DESC_H /* Includes ------------------------------------------------------------------*/ -#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc/usbd_def.h" +#include "usbd_def.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{