From 40ba5925fc6ce49fec8e20fc66c6700339dc52e8 Mon Sep 17 00:00:00 2001 From: bsongis Date: Tue, 20 Nov 2012 22:33:26 +0000 Subject: [PATCH] [stock] Issue 157 fixed [gruvin9x] Issue 160 fixed --- src/FatFs/ffconf.h | 4 +- src/Makefile | 4 +- src/board_gruvin9x.cpp | 7 +- src/board_gruvin9x.h | 18 +++ src/board_sky9x.h | 7 +- src/board_stock.cpp | 20 +++ src/board_stock.h | 59 +++++++ src/drivers.cpp | 16 +- src/eeprom_avr.cpp | 4 +- src/frsky.cpp | 9 +- src/general_menus.cpp | 2 +- src/gruvin9x/diskio.cpp | 90 +++++++---- src/jeti.cpp | 2 +- src/main_views.cpp | 4 +- src/mavlink.cpp | 2 +- src/nmea.cpp | 32 ++-- src/open9x.cpp | 322 ++++++++++++--------------------------- src/open9x.h | 40 +---- src/pulses_avr.cpp | 60 +++----- src/sdcard.h | 7 +- src/sky9x/diskio.cpp | 4 +- src/statistics_views.cpp | 18 +-- src/translations.cpp | 2 +- src/translations.h | 2 +- src/translations/cz.h | 4 +- src/translations/de.h | 4 +- src/translations/en.h | 4 +- src/translations/es.h | 4 +- src/translations/fr.h | 4 +- src/translations/it.h | 4 +- src/translations/pt.h | 4 +- src/translations/se.h | 4 +- 32 files changed, 369 insertions(+), 398 deletions(-) create mode 100644 src/board_stock.h diff --git a/src/FatFs/ffconf.h b/src/FatFs/ffconf.h index 2957cc92e..5bbce477c 100644 --- a/src/FatFs/ffconf.h +++ b/src/FatFs/ffconf.h @@ -100,10 +100,12 @@ extern "C" { #if defined(PCBSKY9X) #define _USE_LFN 2 /* 0 to 3 */ +#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ #else #define _USE_LFN 1 /* 0 to 3 */ +#define _MAX_LFN 32 /* Maximum LFN length to handle (12 to 255) */ #endif -#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ + /* The _USE_LFN option switches the LFN support. / / 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect. diff --git a/src/Makefile b/src/Makefile index 2a132fa52..bee01d58a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -520,8 +520,8 @@ ifeq ($(PCB), GRUVIN9X) ifeq ($(SDCARD), YES) CPPDEFS += -DRTCLOCK - CPPSRC += rtc.cpp gruvin9x/rtc_driver.cpp gruvin9x/diskio.cpp - EXTRABOARDSRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c + CPPSRC += rtc.cpp gruvin9x/rtc_driver.cpp + EXTRABOARDSRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c gruvin9x/diskio.cpp endif ifeq ($(VOICE), YES) diff --git a/src/board_gruvin9x.cpp b/src/board_gruvin9x.cpp index f08ef887b..fbf7413c8 100644 --- a/src/board_gruvin9x.cpp +++ b/src/board_gruvin9x.cpp @@ -109,11 +109,6 @@ inline void board_init() OCR4A = 0x7d; TCCR4B = (1 << WGM42) | (3<PIO_PDR = PIO_PC22 +#define JACK_PPM_IN() PIOC->PIO_PER = PIO_PC22 + #endif diff --git a/src/board_stock.cpp b/src/board_stock.cpp index 45d6fe290..b614d0b07 100644 --- a/src/board_stock.cpp +++ b/src/board_stock.cpp @@ -182,3 +182,23 @@ void readKeysAndTrims() ++enuk; } } + +bool checkSlaveMode() +{ + // no power -> only phone jack = slave mode + static bool lastSlaveMode = false; + static uint8_t checkDelay = 0; + if (IS_AUDIO_BUSY()) { + checkDelay = 20; + } + else if (checkDelay) { + --checkDelay; + } + else { + lastSlaveMode = (PING & (1< + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - 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. + * + */ + +#ifndef board_stock_h +#define board_stock_h + +extern uint16_t nextMixerTime; + +#define TIMER_16KHZ_VECT TIMER0_OVF_vect +#define COUNTER_16KHZ TCNT0 + +#define TIMER_10MS_VECT TIMER0_COMP_vect +#define PAUSE_10MS_INTERRUPT() TIMSK &= ~(1< 0) WDT_RESET_STOCK(); + while (eeprom_buffer_size > 0) wdt_reset(); } } @@ -794,7 +794,7 @@ void RlcFile::nextRlcWriteStep() void RlcFile::flush() { - while (eeprom_buffer_size > 0) WDT_RESET_STOCK(); + while (eeprom_buffer_size > 0) wdt_reset(); s_sync_write = true; while (m_write_len && !s_write_err) diff --git a/src/frsky.cpp b/src/frsky.cpp index db873358b..6bdd3a272 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -1189,6 +1189,11 @@ uint8_t barCoord(int16_t value, int16_t min, int16_t max) void menuTelemetryFrsky(uint8_t event) { + if (event == EVT_KEY_FIRST(KEY_EXIT)) { + chainMenu(menuMainView); + return; + } + switch (event) { case EVT_KEY_BREAK(KEY_UP): if (s_frsky_view-- == 0) @@ -1200,10 +1205,6 @@ void menuTelemetryFrsky(uint8_t event) s_frsky_view = 0; break; - case EVT_KEY_FIRST(KEY_EXIT): - chainMenu(menuMainView); - break; - case EVT_KEY_FIRST(KEY_MENU): resetTelemetry(); break; diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 4f7f40039..45091d0ae 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -715,7 +715,7 @@ void menuGeneralSdManager(uint8_t event) void menuGeneralTrainer(uint8_t event) { uint8_t y; - bool slave = SLAVE_MODE; + bool slave = SLAVE_MODE(); MENU(STR_MENUTRAINER, menuTabDiag, e_Trainer, slave ? 1 : 7, {0, 2, 2, 2, 2, 0/*, 0*/}); diff --git a/src/gruvin9x/diskio.cpp b/src/gruvin9x/diskio.cpp index 23459c399..39edc0a5b 100644 --- a/src/gruvin9x/diskio.cpp +++ b/src/gruvin9x/diskio.cpp @@ -99,12 +99,31 @@ volatile BYTE Timer1, Timer2; /* 100Hz decrement timer */ static BYTE CardType; /* Card type flags */ +#if defined(SIMU) +#define loop_mixer_until_bit_is_set loop_until_bit_is_set +#else +inline void checkMixer() +{ + uint16_t t0 = getTmr16KHz(); + int16_t delta = t0 - nextMixerTime; + if (delta < 0) return; + + nextMixerTime = t0 + 20*16; + doMixerCalculations(); + + t0 = getTmr16KHz() - t0; + lastMixerDuration = t0; + if (t0 > maxMixerDuration) maxMixerDuration = t0; +} + +#define loop_mixer_until_bit_is_set(sfr, bit) do { checkMixer(); wdt_reset(); } while (bit_is_clear(sfr, bit)) +#endif /*-----------------------------------------------------------------------*/ /* Transmit a byte to MMC via SPI (Platform dependent) */ /*-----------------------------------------------------------------------*/ -#define xmit_spi(dat) SPDR=(dat); loop_until_bit_is_set(SPSR,SPIF) +#define xmit_spi(dat) SPDR=(dat); loop_mixer_until_bit_is_set(SPSR,SPIF) @@ -116,12 +135,12 @@ static BYTE rcvr_spi (void) { SPDR = 0xFF; - loop_until_bit_is_set(SPSR, SPIF); + loop_mixer_until_bit_is_set(SPSR, SPIF); return SPDR; } /* Alternative macro to receive data fast */ -#define rcvr_spi_m(dst) SPDR=0xFF; loop_until_bit_is_set(SPSR,SPIF); *(dst)=SPDR +#define rcvr_spi_m(dst) SPDR=0xFF; loop_mixer_until_bit_is_set(SPSR,SPIF); *(dst)=SPDR @@ -615,35 +634,48 @@ DRESULT disk_ioctl ( /*-----------------------------------------------------------------------*/ /* This function must be called in period of 10ms */ -void sdPoll10mS (void) +void sdPoll10ms() { - BYTE s; - - /* - n = Timer1; // 100Hz decrement timer - if (n) Timer1 = --n; - n = Timer2; - if (n) Timer2 = --n; - */ - if (Timer1) Timer1--; - if (Timer2) Timer2--; + BYTE s; - s = Stat; - - /* G: Not implemented - if (SOCKWP) // Write protected - s |= STA_PROTECT; - else // Write enabled - s &= ~STA_PROTECT; - if (SOCKINS) // Card inserted - s &= ~STA_NODISK; - else // Socket empty - s |= (STA_NODISK | STA_NOINIT); - */ - s &= ~STA_NODISK; - s &= ~STA_PROTECT; + /* + n = Timer1; // 100Hz decrement timer + if (n) Timer1 = --n; + n = Timer2; + if (n) Timer2 = --n; + */ + if (Timer1) Timer1--; + if (Timer2) Timer2--; - Stat = s; + s = Stat; + + /* G: Not implemented + if (SOCKWP) // Write protected + s |= STA_PROTECT; + else // Write enabled + s &= ~STA_PROTECT; + if (SOCKINS) // Card inserted + s &= ~STA_NODISK; + else // Socket empty + s |= (STA_NODISK | STA_NOINIT); + */ + s &= ~STA_NODISK; + s &= ~STA_PROTECT; + + Stat = s; } +#if !defined(SIMU) +void sdMountPoll() +{ + static uint8_t mountTimer; + if (mountTimer-- == 0) { + mountTimer = 100; + if (g_FATFS_Obj.fs_type == 0) { + f_mount(0, &g_FATFS_Obj); + } + } +} +#endif + FATFS g_FATFS_Obj; diff --git a/src/jeti.cpp b/src/jeti.cpp index 7d6195521..3f76c188d 100644 --- a/src/jeti.cpp +++ b/src/jeti.cpp @@ -193,7 +193,7 @@ void menuTelemetryJeti(uint8_t event) case EVT_KEY_FIRST(KEY_EXIT): JETI_DisableRXD(); chainMenu(menuMainView); - break; + return; } for (uint8_t i = 0; i < 16; i++) diff --git a/src/main_views.cpp b/src/main_views.cpp index 46af97435..ae6975f27 100644 --- a/src/main_views.cpp +++ b/src/main_views.cpp @@ -150,7 +150,7 @@ void menuMainView(uint8_t event) case EVT_KEY_STATISTICS: chainMenu(menuStatisticsView); killEvents(event); - break; + return; case EVT_KEY_TELEMETRY: #if defined(FRSKY) chainMenu(menuTelemetryFrsky); @@ -169,7 +169,7 @@ void menuMainView(uint8_t event) chainMenu(menuStatisticsDebug); #endif killEvents(event); - break; + return; case EVT_KEY_FIRST(KEY_EXIT): if (s_timerState[0]==TMR_BEEPING) { s_timerState[0] = TMR_STOPPED; diff --git a/src/mavlink.cpp b/src/mavlink.cpp index d1a983a8a..492e9429b 100644 --- a/src/mavlink.cpp +++ b/src/mavlink.cpp @@ -903,7 +903,7 @@ void menuTelemetryMavlink(uint8_t event) { case EVT_KEY_FIRST(KEY_EXIT): //MAVLINK_Quit(); chainMenu(menuMainView); - break; + return; } switch (MAVLINK_menu) { diff --git a/src/nmea.cpp b/src/nmea.cpp index 4b9f10ab5..7fe7ee0e5 100644 --- a/src/nmea.cpp +++ b/src/nmea.cpp @@ -394,18 +394,18 @@ void menuTelemetryNMEA1(uint8_t event) { case EVT_KEY_BREAK(KEY_LEFT): chainMenu(menuTelemetryNMEA4); - break; + return; case EVT_KEY_BREAK(KEY_RIGHT): chainMenu(menuTelemetryNMEA2); - break; + return; case EVT_KEY_LONG(KEY_UP): NMEA_DisableRXD(); chainMenu(menuStatisticsView); - break; + return; case EVT_KEY_LONG(KEY_DOWN): NMEA_DisableRXD(); chainMenu(menuMainView); - break; + return; case EVT_KEY_FIRST(KEY_MENU): if (show_timer == 0) { show_timer = 1; @@ -507,21 +507,21 @@ void menuTelemetryNMEA2(uint8_t event) ignore_break=0; break;} chainMenu(menuTelemetryNMEA1); - break; + return; case EVT_KEY_BREAK(KEY_RIGHT): if (ignore_break==1) { ignore_break=0; break;} chainMenu(menuTelemetryNMEA3); - break; + return; case EVT_KEY_LONG(KEY_UP): NMEA_DisableRXD(); chainMenu(menuStatisticsView); - break; + return; case EVT_KEY_LONG(KEY_DOWN): NMEA_DisableRXD(); chainMenu(menuMainView); - break; + return; //Beep setting case EVT_KEY_LONG(KEY_LEFT): @@ -662,18 +662,18 @@ void menuTelemetryNMEA3(uint8_t event) { case EVT_KEY_BREAK(KEY_LEFT): chainMenu(menuTelemetryNMEA2); - break; + return; case EVT_KEY_BREAK(KEY_RIGHT): chainMenu(menuTelemetryNMEA4); - break; + return; case EVT_KEY_LONG(KEY_UP): NMEA_DisableRXD(); chainMenu(menuStatisticsView); - break; + return; case EVT_KEY_LONG(KEY_DOWN): NMEA_DisableRXD(); chainMenu(menuMainView); - break; + return; } initval (LONG_BUF(0), PACK_RMC, SOG); initval (LONG_BUF(1), PACK_RMC, COG); @@ -711,18 +711,18 @@ void menuTelemetryNMEA4(uint8_t event) { case EVT_KEY_BREAK(KEY_LEFT): chainMenu(menuTelemetryNMEA3); - break; + return; case EVT_KEY_BREAK(KEY_RIGHT): chainMenu(menuTelemetryNMEA1); - break; + return; case EVT_KEY_LONG(KEY_UP): NMEA_DisableRXD(); chainMenu(menuStatisticsView); - break; + return; case EVT_KEY_LONG(KEY_DOWN): NMEA_DisableRXD(); chainMenu(menuMainView); - break; + return; } // expecting LAT value in POS packet to be stored in the first buffer initval (LONG_BUF(0), PACK_GGA, LAT); diff --git a/src/open9x.cpp b/src/open9x.cpp index a53421ed7..62695c4e6 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -95,10 +95,9 @@ uint8_t g_tmr1Latency_min; uint8_t unexpectedShutdown = 0; -uint16_t g_timeMainMax; -#if defined(PCBGRUVIN9X) -uint8_t lastMixerDuration; -#endif +/* mixer duration in 1/16ms */ +uint16_t maxMixerDuration; +uint16_t lastMixerDuration; #if defined(AUDIO) && !defined(PCBSKY9X) audioQueue audio; @@ -1259,7 +1258,7 @@ void checkSwitches() checkBacklight(); - WDT_RESET_STOCK(); + wdt_reset(); #ifdef SIMU if (!main_thread_running) return; @@ -1286,7 +1285,7 @@ void alert(const pm_char * t, const pm_char *s MESSAGE_SOUND_ARG) checkBacklight(); - WDT_RESET_STOCK(); + wdt_reset(); } } @@ -1324,19 +1323,19 @@ void message(const pm_char *title, const pm_char *t, const char *last MESSAGE_SO int8_t trimGvar[NUM_STICKS] = { -1, -1, -1, -1 }; #endif -#if defined(PCBSTD) -uint8_t checkTrim(uint8_t event) -{ - int8_t k = (event & EVT_KEY_MASK) - TRM_BASE; - int8_t s = g_model.trimInc; - if (k>=0 && k<8 && !IS_KEY_BREAK(event)) { -#else +#if defined(PCBSKY9X) void checkTrims() { uint8_t event = getEvent(true); if (event && !IS_KEY_BREAK(event)) { int8_t k = (event & EVT_KEY_MASK) - TRM_BASE; int8_t s = g_model.trimInc; +#else +uint8_t checkTrim(uint8_t event) +{ + int8_t k = (event & EVT_KEY_MASK) - TRM_BASE; + int8_t s = g_model.trimInc; + if (k>=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+k/2) - 1; @@ -1430,11 +1429,11 @@ void checkTrims() else { AUDIO_TRIM(event, after); } -#if defined(PCBSTD) +#if !defined(PCBSKY9X) return 0; #endif } -#if defined(PCBSTD) +#if !defined(PCBSKY9X) return event; #endif } @@ -1632,30 +1631,6 @@ void getADC_bandgap() uint8_t g_vbat100mV = 0; uint16_t g_LightOffCounter; -#if !defined(PCBSKY9X) -FORCEINLINE bool checkSlaveMode() -{ - // no power -> only phone jack = slave mode - -#if defined(PCBGRUVIN9X) - return SLAVE_MODE; -#else - static bool lastSlaveMode = false; - static uint8_t checkDelay = 0; - if (IS_AUDIO_BUSY()) { - checkDelay = 20; - } - else if (checkDelay) { - --checkDelay; - } - else { - lastSlaveMode = SLAVE_MODE; - } - return lastSlaveMode; -#endif -} -#endif - uint16_t s_timeCumTot; uint16_t s_timeCumThr; // THR in 1/16 sec uint16_t s_timeCum16ThrP; // THR% in 1/16 sec @@ -2363,7 +2338,7 @@ void perOut(uint8_t tick10ms) sDelay[i] = md->delayUp * 50; } if (sDelay[i] > 0) { // perform delay - sDelay[i] -= tick10ms; + sDelay[i] = max(0, sDelay[i]-tick10ms); if (!md->swtch) { v = -1024; } @@ -2387,7 +2362,7 @@ void perOut(uint8_t tick10ms) sDelay[i] = md->delayDown * 50; } if (sDelay[i] > 0) { // perform delay - sDelay[i] -= tick10ms; + sDelay[i] = max(0, sDelay[i]-tick10ms); if (!md->swtch) v = +1024; has_delay = true; } @@ -2510,9 +2485,24 @@ void perOut(uint8_t tick10ms) ACTIVE_MIXES_TYPE activeMixes; #endif int32_t sum_chans512[NUM_CHNOUT] = {0}; -inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms) + +#if defined(PCBSKY9X) +inline bool doMixerCalculations() +#else +inline void doMixerCalculations() +#endif { -#ifdef BOLD_FONT +#if defined(PCBGRUVIN9X) && defined(DEBUG) && !defined(VOICE) + PORTH |= 0x40; // PORTH:6 LOW->HIGH signals start of mixer interrupt +#endif + + static tmr10ms_t lastTMR; + + tmr10ms_t tmr10ms = get_tmr10ms(); + uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); + lastTMR = tmr10ms; + +#if defined(BOLD_FONT) activeMixes = 0; #endif @@ -2602,12 +2592,20 @@ inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms) sei(); } +#if defined(PCBGRUVIN9X) && defined(DEBUG) && !defined(VOICE) + PORTH &= ~0x40; // PORTH:6 HIGH->LOW signals end of mixer interrupt +#endif + // Bandgap has had plenty of time to settle... #if !defined(PCBSKY9X) getADC_bandgap(); #endif +#if defined(PCBSKY9X) + if (!tick10ms) return false; //make sure the rest happen only every 10ms. +#else if (!tick10ms) return; //make sure the rest happen only every 10ms. +#endif /* Throttle trace */ int16_t val; @@ -2813,43 +2811,48 @@ inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms) setVolume(requiredSpeakerVolume); currentSpeakerVolume = requiredSpeakerVolume; } + + return true; #endif } void perMain() { - static tmr10ms_t lastTMR; - tmr10ms_t tmr10ms = get_tmr10ms(); - uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); - lastTMR = tmr10ms; +#if defined(SIMU) + doMixerCalculations(); +#elif !defined(PCBSKY9X) + uint16_t t0 = getTmr16KHz(); + int16_t delta = t0 - nextMixerTime; + if (delta < 0) return; -#if defined(PCBSTD) || defined(SIMU) - doMixerCalculations(tmr10ms, tick10ms); + nextMixerTime = t0 + 20*16; + doMixerCalculations(); + + t0 = getTmr16KHz() - t0; + lastMixerDuration = t0; + if (t0 > maxMixerDuration) maxMixerDuration = t0; #endif // TODO same code here + integrate the timer which could be common #if defined(PCBSKY9X) - if (Tenms) { - Tenms = 0 ; + if (!Tenms) return; + Tenms = 0 ; - if (Eeprom32_process_state != E32_IDLE) - ee32_process(); - else if (TIME_TO_WRITE) - eeCheck(); - - Current_accumulator += Current_analogue ; - static uint32_t OneSecTimer; - if (++OneSecTimer >= 100) { - OneSecTimer -= 100 ; - sessionTimer += 1; - Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled) - Current_accumulator = 0 ; - } - -#if defined(SDCARD) && !defined(SIMU) - sdPoll10mS(); -#endif + Current_accumulator += Current_analogue ; + static uint32_t OneSecTimer; + if (++OneSecTimer >= 100) { + OneSecTimer -= 100 ; + sessionTimer += 1; + Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled) + Current_accumulator = 0 ; } +#endif + +#if defined(PCBSKY9X) + if (Eeprom32_process_state != E32_IDLE) + ee32_process(); + else if (TIME_TO_WRITE) + eeCheck(); #else if (!eeprom_buffer_size) { if (theFile.isWriting()) @@ -2859,33 +2862,20 @@ void perMain() } #endif - if (!tick10ms) return; //make sure the rest happen only every 10ms. - #if defined(SDCARD) -#if defined(PCBGRUVIN9X) - static uint8_t mountTimer; - if (mountTimer-- == 0) { - mountTimer = 100; - if (g_FATFS_Obj.fs_type == 0) { - f_mount(0, &g_FATFS_Obj); - } - } -#endif - + sdMountPoll(); writeLogs(); #endif - lcd_clear(); - #if defined(PCBSKY9X) && defined(SIMU) checkTrims(); #endif -#if defined(PCBSTD) +#if defined(PCBSKY9X) + uint8_t evt = getEvent(false); +#else uint8_t evt = getEvent(); evt = checkTrim(evt); -#else - uint8_t evt = getEvent(false); #endif if (g_LightOffCounter) g_LightOffCounter--; @@ -2897,44 +2887,27 @@ void perMain() check_frsky(); #endif + lcd_clear(); const char *warn = s_warning; g_menuStack[g_menuStackPtr](warn ? 0 : evt); if (warn) displayWarning(evt); drawStatusLine(); refreshDisplay(); -#if defined(PCBSKY9X) - if ( check_soft_power() == e_power_trainer ) { // On trainer power - PIOC->PIO_PDR = PIO_PC22 ; // Disable bit C22 Assign to peripheral + if (SLAVE_MODE()) { + JACK_PPM_OUT(); } else { - PIOC->PIO_PER = PIO_PC22 ; // Enable bit C22 as input + JACK_PPM_IN(); } -#elif defined(PCBGRUVIN9X) - // PPM signal on phono-jack. In or out? ... - if(checkSlaveMode()) { - PORTG |= (1<HIGH signals start of mixer interrupt -#endif - - cli(); - TIMSK5 &= ~(1<= lastTMR ? tmr10ms - lastTMR : 1); - lastTMR = tmr10ms; - - if (s_current_protocol < PROTO_NONE) { - doMixerCalculations(tmr10ms, tick10ms); - checkTrims(); - } - - heartbeat |= HEART_TIMER10ms; - - if (heartbeat == HEART_TIMER_PULSES+HEART_TIMER10ms) { - wdt_reset(); - heartbeat = 0; - } - - t0 = getTmr16KHz() - t0; - lastMixerDuration = t0 / 8; - if (t0 > g_timeMainMax) g_timeMainMax = t0 ; - - cli(); - TIMSK5 |= (1<LOW signals end of mixer interrupt -#endif -} -#endif - -#if defined (PCBGRUVIN9X) -ISR(TIMER2_COMPA_vect, ISR_NOBLOCK) //10ms timer -#else -// Clocks every 64 uS -ISR(TIMER0_COMP_vect, ISR_NOBLOCK) //10ms timer -#endif +ISR(TIMER_10MS_VECT, ISR_NOBLOCK) // 10ms timer { cli(); - -#if defined(PCBGRUVIN9X) - TIMSK2 &= ~(1<= lastTMR ? tmr10ms - lastTMR : 1); - lastTMR = tmr10ms; - if (s_current_protocol < PROTO_NONE) { CoEnterMutexSection(mixerMutex); - doMixerCalculations(tmr10ms, tick10ms); + bool tick10ms = doMixerCalculations(); CoLeaveMutexSection(mixerMutex); if (tick10ms) checkTrims(); } - heartbeat |= HEART_TIMER10ms; + heartbeat |= HEART_TIMER10ms; // TODO not here but in 10ms interrupt! if (heartbeat == HEART_TIMER_PULSES+HEART_TIMER10ms) { wdt_reset(); @@ -3554,7 +3437,7 @@ void mixerTask(void * pdata) } t0 = getTmr2MHz() - t0; - if (t0 > g_timeMainMax) g_timeMainMax = t0 ; + if (t0 > maxMixerDuration) maxMixerDuration = t0 ; } CoTickDelay(1); // 2ms for now @@ -3733,20 +3616,13 @@ int main(void) break; #endif -#if defined(PCBSTD) - uint16_t t0 = getTmr16KHz(); -#endif - perMain(); -#if defined(PCBSTD) +#if !defined(PCBSKY9X) if(heartbeat == HEART_TIMER_PULSES+HEART_TIMER10ms) { wdt_reset(); heartbeat = 0; } - - t0 = getTmr16KHz() - t0; - if (t0 > g_timeMainMax) g_timeMainMax = t0; #endif } #endif // PCBSKY9X diff --git a/src/open9x.h b/src/open9x.h index 114ecfaff..1238b3842 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -138,12 +138,6 @@ #define IF_GVARS(x) #endif -#if defined(PCBSTD) -#define WDT_RESET_STOCK() wdt_reset() -#else -#define WDT_RESET_STOCK() -#endif - /* #define HELI_VARIANT 0x0004 #define VOICE_VARIANT 0x0008 @@ -157,6 +151,8 @@ #include "board_sky9x.h" #elif defined(PCBGRUVIN9X) #include "board_gruvin9x.h" +#else +#include "board_stock.h" #endif #if defined(SIMU) @@ -400,12 +396,6 @@ extern uint8_t s_bind_allowed; #endif // defined (PCBGRUVIN9X) -#if defined(PCBSKY9X) -#define SLAVE_MODE (check_soft_power() == e_power_trainer) -#else -#define SLAVE_MODE (PING & (1<>1) | 0x80; //shift in stop bit } @@ -894,6 +882,8 @@ void setupPulses() #ifdef PXX case PROTO_PXX: + // schedule next Mixer calculations + SCHEDULE_MIXER(20*16-lastMixerDuration-2*16/*1ms*/); sei(); setupPulsesPXX(); break; @@ -901,11 +891,8 @@ void setupPulses() #ifdef DSM2 case PROTO_DSM2: -#if defined(PCBGRUVIN9X) - // schedule next Mixer interrupt - OCR5A = (uint16_t)0x7d * (44-lastMixerDuration-2/*1ms*/); - TCNT5 = 0; -#endif + // schedule next Mixer calculations + SCHEDULE_MIXER(22*16-lastMixerDuration-2*16/*1ms*/); sei(); setupPulsesDsm2(); // Different versions for DSM2=SERIAL vs. DSM2=PPM #if defined(PCBGRUVIN9X) && defined(DSM2_PPM) @@ -917,7 +904,7 @@ void setupPulses() break; #endif -#ifdef IRPROTOS +#if defined(IRPROTOS) case PROTO_PICZ: setupPulsesPiccoZ(g_model.ppmNCH); // TODO BSS stbyLevel = 0; //start with 1 @@ -925,14 +912,11 @@ void setupPulses() #endif default: // standard PPM protocol -#ifndef SIMU +#if !defined(SIMU) g_ppmPulsePolarity = g_model.pulsePol; #endif -#if defined(PCBGRUVIN9X) - // schedule next Mixer interrupt - OCR5A = (uint16_t)0x7d * (45+g_model.ppmFrameLength-lastMixerDuration-2/*1ms*/); - TCNT5 = 0; -#endif + // schedule next Mixer calculations + SCHEDULE_MIXER(45*8+g_model.ppmFrameLength*8-lastMixerDuration-2*16/*1ms*/); // no sei here setupPulsesPPM(PROTO_PPM); // if PPM16, PPM16 pulses are set up automatically within the interrupts diff --git a/src/sdcard.h b/src/sdcard.h index 4bbe19b83..db84bf45b 100644 --- a/src/sdcard.h +++ b/src/sdcard.h @@ -69,8 +69,11 @@ inline const pm_char *SDCARD_ERROR(FRESULT result) return STR_SDCARD_ERROR; } -// TODO move the ARM function definition here (when cpp) -extern void sdPoll10mS(); +#if defined(SIMU) +#define sdMountPoll() +#else +extern void sdMountPoll(); +#endif #if defined(PCBSKY9X) && !(defined(SIMU)) extern "C" { diff --git a/src/sky9x/diskio.cpp b/src/sky9x/diskio.cpp index 97e37f354..852a20e34 100644 --- a/src/sky9x/diskio.cpp +++ b/src/sky9x/diskio.cpp @@ -34,7 +34,7 @@ /*-----------------------------------------------------------------------*/ /* MMCv3/SDv1/SDv2 (in SPI mode) control module (C)ChaN, 2010 */ /*-----------------------------------------------------------------------*/ -/* Only rcvr_spi(), xmit_spi(), sdPoll10mS() and some macros */ +/* Only rcvr_spi(), xmit_spi(), sdPoll10ms() and some macros */ /* are platform dependent. */ /*-----------------------------------------------------------------------*/ @@ -956,7 +956,7 @@ FATFS g_FATFS_Obj = { 0 }; extern void retrieveAvailableAudioFiles(); -void sdPoll10mS() +void sdMountPoll() { if (!Card_initialized) return; diff --git a/src/statistics_views.cpp b/src/statistics_views.cpp index 218911857..682f08544 100644 --- a/src/statistics_views.cpp +++ b/src/statistics_views.cpp @@ -40,11 +40,11 @@ void menuStatisticsView(uint8_t event) { case EVT_KEY_FIRST(KEY_UP): chainMenu(menuStatisticsDebug); - break; + return; case EVT_KEY_FIRST(KEY_DOWN): case EVT_KEY_FIRST(KEY_EXIT): chainMenu(menuMainView); - break; + return; } lcd_puts( 1*FW, FH*1, STR_TM1TM2); @@ -105,16 +105,16 @@ void menuStatisticsDebug(uint8_t event) g_tmr1Latency_min = 0xff; g_tmr1Latency_max = 0; #endif - g_timeMainMax = 0; + maxMixerDuration = 0; AUDIO_KEYPAD_UP(); break; case EVT_KEY_FIRST(KEY_DOWN): chainMenu(menuStatisticsView); - break; + return; case EVT_KEY_FIRST(KEY_UP): case EVT_KEY_FIRST(KEY_EXIT): chainMenu(menuMainView); - break; + return; } #if defined(PCBSKY9X) @@ -143,8 +143,8 @@ void menuStatisticsDebug(uint8_t event) putsTelemetryValue(20*FW+2, 4*FH, Coproc_maxtemp, UNIT_DEGREES, 0); } - lcd_putsLeft(5*FH, STR_TMAINMAXMS); - lcd_outdezAtt(MENU_DEBUG_COL_OFS, 5*FH, (g_timeMainMax)/20, PREC2); + lcd_putsLeft(5*FH, STR_TMIXMAXMS); + lcd_outdezAtt(MENU_DEBUG_COL_OFS, 5*FH, (maxMixerDuration)/20, PREC2); lcd_putsLeft(6*FH, STR_FREESTACKMINB); lcd_outdezAtt(13*FW, 6*FH, stack_free(0), UNSIGN); @@ -159,8 +159,8 @@ void menuStatisticsDebug(uint8_t event) lcd_outdez8(MENU_DEBUG_COL_OFS , 2*FH, g_tmr1Latency_min/2 ); lcd_putsLeft(3*FH, STR_TMR1JITTERUS); lcd_outdez8(MENU_DEBUG_COL_OFS , 3*FH, (g_tmr1Latency_max - g_tmr1Latency_min) /2 ); - lcd_putsLeft(4*FH, STR_TMAINMAXMS); - lcd_outdezAtt(MENU_DEBUG_COL_OFS, 4*FH, (g_timeMainMax*100)/16, PREC2); + lcd_putsLeft(4*FH, STR_TMIXMAXMS); + lcd_outdezAtt(MENU_DEBUG_COL_OFS, 4*FH, (maxMixerDuration*100)/16, PREC2); lcd_putsLeft(5*FH, STR_FREESTACKMINB); lcd_outdezAtt(14*FW, 5*FH, stack_free(), UNSIGN) ; #endif diff --git a/src/translations.cpp b/src/translations.cpp index 2f072fe82..b456d2ae5 100644 --- a/src/translations.cpp +++ b/src/translations.cpp @@ -214,7 +214,7 @@ const pm_char STR_TOT[] PROGMEM = TR_TOT; const pm_char STR_TMR1LATMAXUS[] PROGMEM = TR_TMR1LATMAXUS; const pm_char STR_TMR1LATMINUS[] PROGMEM = TR_TMR1LATMINUS; const pm_char STR_TMR1JITTERUS[] PROGMEM = TR_TMR1JITTERUS; -const pm_char STR_TMAINMAXMS[] PROGMEM = TR_TMAINMAXMS; +const pm_char STR_TMIXMAXMS[] PROGMEM = TR_TMIXMAXMS; #ifdef DEBUG const pm_char STR_T10MSUS[] PROGMEM = TR_T10MSUS; #endif diff --git a/src/translations.h b/src/translations.h index e3ec63b55..69e6fe6be 100644 --- a/src/translations.h +++ b/src/translations.h @@ -323,7 +323,7 @@ extern const pm_char STR_TOT[]; extern const pm_char STR_TMR1LATMAXUS[]; extern const pm_char STR_TMR1LATMINUS[]; extern const pm_char STR_TMR1JITTERUS[]; -extern const pm_char STR_TMAINMAXMS[]; +extern const pm_char STR_TMIXMAXMS[]; extern const pm_char STR_T10MSUS[]; extern const pm_char STR_FREESTACKMINB[]; extern const pm_char STR_MENUTORESET[]; diff --git a/src/translations/cz.h b/src/translations/cz.h index 7681888ee..5516bed96 100644 --- a/src/translations/cz.h +++ b/src/translations/cz.h @@ -342,9 +342,9 @@ #define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #if defined(PCBSKY9X) -#define TR_TMAINMAXMS "Tmain max\010ms" +#define TR_TMIXMAXMS "Tmix max\012ms" #else -#define TR_TMAINMAXMS "Tmain max\012ms" +#define TR_TMIXMAXMS "Tmix max\014ms" #endif #define TR_T10MSUS "T10ms\016us" #define TR_FREESTACKMINB "Free Stack\010b" diff --git a/src/translations/de.h b/src/translations/de.h index 015c8b21a..a3fa6902c 100644 --- a/src/translations/de.h +++ b/src/translations/de.h @@ -343,9 +343,9 @@ #define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #if defined(PCBSKY9X) -#define TR_TMAINMAXMS "Tmain max\010ms" +#define TR_TMIXMAXMS "Tmix max\012ms" #else -#define TR_TMAINMAXMS "Tmain max\012ms" +#define TR_TMIXMAXMS "Tmix max\014ms" #endif #define TR_T10MSUS "T10ms\016us" #define TR_FREESTACKMINB "Free Stack\010b" diff --git a/src/translations/en.h b/src/translations/en.h index 9ef2ac188..33846c4d4 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -343,9 +343,9 @@ #define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #if defined(PCBSKY9X) -#define TR_TMAINMAXMS "Tmain max\010ms" +#define TR_TMIXMAXMS "Tmix max\012ms" #else -#define TR_TMAINMAXMS "Tmain max\012ms" +#define TR_TMIXMAXMS "Tmix max\014ms" #endif #define TR_T10MSUS "T10ms\016us" #define TR_FREESTACKMINB "Free Stack\010b" diff --git a/src/translations/es.h b/src/translations/es.h index e23ae4cd2..0c2cd5c10 100644 --- a/src/translations/es.h +++ b/src/translations/es.h @@ -337,9 +337,9 @@ #define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #if defined(PCBSKY9X) -#define TR_TMAINMAXMS "Tmain max\010ms" +#define TR_TMIXMAXMS "Tmix max\012ms" #else -#define TR_TMAINMAXMS "Tmain max\012ms" +#define TR_TMIXMAXMS "Tmix max\014ms" #endif #define TR_T10MSUS "T10ms\016us" #define TR_FREESTACKMINB "Pila libre\010b" diff --git a/src/translations/fr.h b/src/translations/fr.h index 5648e936d..c7c9d83ae 100644 --- a/src/translations/fr.h +++ b/src/translations/fr.h @@ -343,9 +343,9 @@ #define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #if defined(PCBSKY9X) -#define TR_TMAINMAXMS "Tmain max\010ms" +#define TR_TMIXMAXMS "Tmix max\012ms" #else -#define TR_TMAINMAXMS "Tmain max\012ms" +#define TR_TMIXMAXMS "Tmix max\014ms" #endif #define TR_T10MSUS "T10ms\016us" #define TR_FREESTACKMINB "Free Stack\010b" diff --git a/src/translations/it.h b/src/translations/it.h index 45466bd99..d32f82afc 100644 --- a/src/translations/it.h +++ b/src/translations/it.h @@ -341,9 +341,9 @@ #define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #if defined(PCBSKY9X) -#define TR_TMAINMAXMS "Tmain max\004ms" +#define TR_TMIXMAXMS "Tmix max\012ms" #else -#define TR_TMAINMAXMS "Tmain max\005ms" +#define TR_TMIXMAXMS "Tmix max\014ms" #endif #define TR_T10MSUS "T10ms\007us" #define TR_FREESTACKMINB "Free Stack\004b" diff --git a/src/translations/pt.h b/src/translations/pt.h index d9b327d86..462840c8f 100644 --- a/src/translations/pt.h +++ b/src/translations/pt.h @@ -343,9 +343,9 @@ #define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #if defined(PCBSKY9X) -#define TR_TMAINMAXMS "Tmain max\010ms" +#define TR_TMIXMAXMS "Tmix max\012ms" #else -#define TR_TMAINMAXMS "Tmain max\012ms" +#define TR_TMIXMAXMS "Tmix max\014ms" #endif #define TR_T10MSUS "T10ms\016us" #define TR_FREESTACKMINB "Pilha Livre\010b" diff --git a/src/translations/se.h b/src/translations/se.h index eb684f81b..d918aebf5 100644 --- a/src/translations/se.h +++ b/src/translations/se.h @@ -346,9 +346,9 @@ #define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #if defined(PCBSKY9X) -#define TR_TMAINMAXMS "Tmain max\010ms" +#define TR_TMIXMAXMS "Tmix max\012ms" #else -#define TR_TMAINMAXMS "Tmain max\012ms" +#define TR_TMIXMAXMS "Tmix max\014ms" #endif #define TR_T10MSUS "T10ms\016us" #define TR_FREESTACKMINB "Free Stack\010b"