diff --git a/src/Makefile b/src/Makefile index ad0a8b099..e6559c29f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -512,9 +512,8 @@ ifeq ($(PCB), X9D) 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 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_avr.cpp # TODO later eeprom_conversions.cpp + EEPROMSRC = eeprom_common.cpp eeprom_rlc.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 @@ -572,7 +571,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_arm.cpp eeprom_conversions.cpp + EEPROMSRC = eeprom_common.cpp eeprom_raw.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 @@ -607,7 +606,7 @@ ifeq ($(PCB), GRUVIN9X) EXTRAINCDIRS += gruvin9x stock FatFs FatFs/option BOARDSRC += gruvin9x/board_gruvin9x.cpp EXTRABOARDSRC += stock/lcd_driver.cpp - EEPROMSRC = eeprom_avr.cpp + EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp PULSESSRC = pulses_avr.cpp CPPSRC += audio_avr.cpp haptic.cpp @@ -635,7 +634,7 @@ ifeq ($(PCB), $(filter $(PCB), STD128 9X128 9XR128)) EXTRAINCDIRS += stock BOARDSRC = stock/board_stock.cpp EXTRABOARDSRC += stock/lcd_driver.cpp - EEPROMSRC = eeprom_avr.cpp + EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp PULSESSRC = pulses_avr.cpp ifeq ($(PCB), 9XR128) @@ -681,7 +680,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_avr.cpp + EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp PULSESSRC = pulses_avr.cpp ifeq ($(PCB), 9XR) diff --git a/src/debug.cpp b/src/debug.cpp index de8609635..f4fba14e1 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -40,8 +40,8 @@ #if !defined(SIMU) -Fifo512 debugRxFifo; -Fifo512 debugTxFifo; +Fifo<512> debugRxFifo; +Fifo<512> 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_common.cpp b/src/eeprom_common.cpp new file mode 100644 index 000000000..2f4d0271a --- /dev/null +++ b/src/eeprom_common.cpp @@ -0,0 +1,68 @@ +/* + * 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/eeprom_arm.cpp b/src/eeprom_raw.cpp similarity index 98% rename from src/eeprom_arm.cpp rename to src/eeprom_raw.cpp index da33df48a..0ad2b5c92 100644 --- a/src/eeprom_arm.cpp +++ b/src/eeprom_raw.cpp @@ -40,8 +40,6 @@ #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 @@ -78,15 +76,8 @@ 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 @@ -360,8 +351,6 @@ 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); @@ -445,12 +434,19 @@ void eeLoadModelName(uint8_t id, char *name) } } -void eeLoadModelNames() +#if defined(PXX) +uint8_t eeLoadModelId(uint8_t id) { - for (uint32_t i=0; i sizeof(g_model.name) + 1) { + read32_eeprom_data( ( File_system[id].block_no << 12) + 8 + sizeof(g_model.name), &modelId, 1); + } } + return modelId; } +#endif void fill_file_index() { diff --git a/src/eeprom_arm.h b/src/eeprom_raw.h similarity index 93% rename from src/eeprom_arm.h rename to src/eeprom_raw.h index fb2c98dc4..f892b287c 100644 --- a/src/eeprom_arm.h +++ b/src/eeprom_raw.h @@ -40,17 +40,6 @@ #include #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 @@ -77,6 +66,10 @@ 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_avr.cpp b/src/eeprom_rlc.cpp similarity index 98% rename from src/eeprom_avr.cpp rename to src/eeprom_rlc.cpp index c48884972..e6ef83cff 100644 --- a/src/eeprom_avr.cpp +++ b/src/eeprom_rlc.cpp @@ -40,18 +40,10 @@ #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; @@ -837,7 +829,6 @@ bool eeLoadGeneral() return false; } - void eeLoadModelName(uint8_t id, char *name) { memclear(name, sizeof(g_model.name)); @@ -847,16 +838,14 @@ void eeLoadModelName(uint8_t id, char *name) } } -#if defined(CPUARM) -// TODO same function in eeprom_arm.cpp -void eeLoadModelNames() +#if defined(PXX) +// must be called just after eeLoadModelName! +uint8_t eeLoadModelIdAfterName() { - 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) @@ -153,6 +140,11 @@ 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/fifo.h b/src/fifo.h index af90a7306..0b2158ebb 100644 --- a/src/fifo.h +++ b/src/fifo.h @@ -37,17 +37,18 @@ #ifndef fifo_h #define fifo_h -class Fifo512 +template +class Fifo { public: - Fifo512(): + Fifo(): widx(0), ridx(0) { } void push(uint8_t byte) { - uint32_t next = (widx+1) & 0x1ff; + uint32_t next = (widx+1) & (N-1); if (next != ridx) { fifo[widx] = byte; widx = next; @@ -60,13 +61,13 @@ class Fifo512 } else { byte = fifo[ridx]; - ridx = (ridx+1) & 0x1ff; + ridx = (ridx+1) & (N-1); return true; } } protected: - uint8_t fifo[512]; + uint8_t fifo[N]; volatile uint32_t widx; volatile uint32_t ridx; }; diff --git a/src/gruvin9x/board_gruvin9x.h b/src/gruvin9x/board_gruvin9x.h index 83c59c545..c6e6d4bcc 100644 --- a/src/gruvin9x/board_gruvin9x.h +++ b/src/gruvin9x/board_gruvin9x.h @@ -70,6 +70,7 @@ #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; diff --git a/src/myeeprom.h b/src/myeeprom.h index 7a51c4e11..4f4cf66bc 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -1104,6 +1104,7 @@ 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 @@ -1130,7 +1131,6 @@ 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 74f838f9f..8051c8aa5 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -68,8 +68,6 @@ OS_FlagID audioFlag; OS_MutexID audioMutex; OS_MutexID mixerMutex; -char modelNames[MAX_MODELS][sizeof(g_model.name)]; - #endif // defined(CPUARM) #if defined(SPLASH) @@ -284,7 +282,7 @@ void per10ms() } #endif -#if (defined(FRSKY) || defined(MAVLINK) || defined(JETI)) && !defined(CPUARM) && !(defined(PCBSTD) && (defined(AUDIO) || defined(VOICE))) +#if (defined(FRSKY) || defined(MAVLINK) || defined(JETI)) && !defined(CPUARM) if (!IS_DSM2_SERIAL_PROTOCOL(s_current_protocol)) telemetryPoll10ms(); #endif @@ -384,7 +382,7 @@ uint16_t evalChkSum() return sum; } -#ifndef TEMPLATES +#if !defined(TEMPLATES) inline void applyDefaultTemplate() { for (int i=0; i lim_p) ofs = lim_p; if (ofs < lim_n) ofs = lim_n; -// 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 + // 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 + // 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 -// #endif + value = limit(int32_t(-RESXl*256), value, int32_t(RESXl*256)); // saves 2 bytes compared to other solutions up to now #if defined(PPM_LIMITS_SYMETRICAL) if (value) { @@ -1996,7 +2009,11 @@ uint16_t inacSum = 0; BeepANACenter bpanaCenter = 0; uint16_t sDelay[MAX_MIXERS] = {0}; +#if defined(CPUARM) +int32_t act [MAX_MIXERS] = {0}; +#else __int24 act [MAX_MIXERS] = {0}; +#endif uint8_t swOn [MAX_MIXERS] = {0}; uint8_t mixWarning; @@ -3524,24 +3541,13 @@ uint16_t getTmr16KHz() } } - - -// 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 -{ - static uint8_t accuracyWarble; // because 16M / 1024 / 100 = 156.25. we need to correct the fault; no start value needed - #if defined(PCBSTD) && (defined(AUDIO) || defined(VOICE)) +// Clocks every 128 uS +ISR(TIMER2_OVF_vect, ISR_NOBLOCK) +{ + cli(); + TIMSK &= ~ (1< no problem - -#if defined(FRSKY) || defined(MAVLINK) || defined(JETI) - if (cnt10ms == 30) { - if (!IS_DSM2_SERIAL_PROTOCOL(s_current_protocol)) - telemetryPoll10ms(); - } + cli(); + TIMSK |= (1< in sum we are correct!!! - // therefore every 8. round we need to slow down one tick - -#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 - 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; - 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 - + TIMER_10MS_COMPVAL += bump; } - // 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), diff --git a/src/open9x.h b/src/open9x.h index 2bd962225..9e0b27e31 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -362,10 +362,6 @@ 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 @@ -384,11 +380,11 @@ extern inline uint16_t get_tmr10ms() } #endif -// TODO try to merge the 2 include files +#include "eeprom_common.h" #if defined(PCBSKY9X) -#include "eeprom_arm.h" +#include "eeprom_raw.h" #else -#include "eeprom_avr.h" +#include "eeprom_rlc.h" #endif #if defined(CPUARM) @@ -951,15 +947,13 @@ 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/sky9x/bluetooth.cpp b/src/sky9x/bluetooth.cpp index 8cde679b5..cdd05f778 100644 --- a/src/sky9x/bluetooth.cpp +++ b/src/sky9x/bluetooth.cpp @@ -49,8 +49,8 @@ void btInit() } OS_FlagID btFlag; -Fifo32 btTxFifo; -Fifo32 btRxFifo; +Fifo<32> btTxFifo; +Fifo<32> btRxFifo; struct t_serial_tx btTx ; uint8_t btTxBuffer[32] ; diff --git a/src/sky9x/board_sky9x.h b/src/sky9x/board_sky9x.h index 5718ed93a..6c62f5101 100644 --- a/src/sky9x/board_sky9x.h +++ b/src/sky9x/board_sky9x.h @@ -98,6 +98,8 @@ #define PIN_TRIM_RH_R 0x00000200 #endif +void usbMassStorage(); + #define PIN_ENABLE 0x001 #define PIN_PERIPHERAL 0x000 #define PIN_INPUT 0x002 diff --git a/src/sky9x/debug_driver.cpp b/src/sky9x/debug_driver.cpp index 4a7a04305..db6a6df68 100644 --- a/src/sky9x/debug_driver.cpp +++ b/src/sky9x/debug_driver.cpp @@ -39,7 +39,7 @@ #if !defined(SIMU) -extern Fifo512 debugRxFifo; +extern Fifo<512> debugRxFifo; /* * Outputs a character on the UART line. diff --git a/src/stock/board_stock.cpp b/src/stock/board_stock.cpp index 029894148..c798c505b 100644 --- a/src/stock/board_stock.cpp +++ b/src/stock/board_stock.cpp @@ -102,29 +102,22 @@ 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/board_x9d.h b/src/x9d/board_x9d.h index 647549915..3f132770f 100644 --- a/src/x9d/board_x9d.h +++ b/src/x9d/board_x9d.h @@ -63,8 +63,6 @@ extern "C" { #define TIMER_MULT_APB1 2 #define TIMER_MULT_APB2 1 -void usbMassStorage(); - #define JACK_PPM_OUT() #define JACK_PPM_IN()