[stock] Issue 157 fixed

[gruvin9x] Issue 160 fixed
This commit is contained in:
bsongis
2012-11-20 22:33:26 +00:00
parent 6f2452afd0
commit 40ba5925fc
32 changed files with 369 additions and 398 deletions
+3 -1
View File
@@ -100,10 +100,12 @@ extern "C" {
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define _USE_LFN 2 /* 0 to 3 */ #define _USE_LFN 2 /* 0 to 3 */
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
#else #else
#define _USE_LFN 1 /* 0 to 3 */ #define _USE_LFN 1 /* 0 to 3 */
#define _MAX_LFN 32 /* Maximum LFN length to handle (12 to 255) */
#endif #endif
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN support. /* The _USE_LFN option switches the LFN support.
/ /
/ 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect. / 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
+2 -2
View File
@@ -520,8 +520,8 @@ ifeq ($(PCB), GRUVIN9X)
ifeq ($(SDCARD), YES) ifeq ($(SDCARD), YES)
CPPDEFS += -DRTCLOCK CPPDEFS += -DRTCLOCK
CPPSRC += rtc.cpp gruvin9x/rtc_driver.cpp gruvin9x/diskio.cpp CPPSRC += rtc.cpp gruvin9x/rtc_driver.cpp
EXTRABOARDSRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c EXTRABOARDSRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c gruvin9x/diskio.cpp
endif endif
ifeq ($(VOICE), YES) ifeq ($(VOICE), YES)
+2 -5
View File
@@ -109,11 +109,6 @@ inline void board_init()
OCR4A = 0x7d; OCR4A = 0x7d;
TCCR4B = (1 << WGM42) | (3<<CS40); // CTC OCR1A, 16MHz / 64 (4us ticks) TCCR4B = (1 << WGM42) | (3<<CS40); // CTC OCR1A, 16MHz / 64 (4us ticks)
/* Mixer interrupt */
OCR5A = 0x7d * 40; /* 20ms */
TCCR5B = (1 << WGM52) | (3<<CS50); // CTC OCR1A, 16MHz / 64 (4us ticks)
TIMSK5 |= (1<<OCIE5A);
#if defined(EXTRA_ROTARY_ENCODERS) #if defined(EXTRA_ROTARY_ENCODERS)
//configure uart1 here //configure uart1 here
DDRD &= ~(1 << 2); DDRD &= ~(1 << 2);
@@ -301,3 +296,5 @@ void readKeysAndTrims()
++enuk; ++enuk;
} }
} }
uint16_t nextMixerTime = 0;
+18
View File
@@ -34,5 +34,23 @@
#ifndef board_gruvin9x_h #ifndef board_gruvin9x_h
#define board_gruvin9x_h #define board_gruvin9x_h
extern uint16_t nextMixerTime;
#define TIMER_16KHZ_VECT TIMER2_OVF_vect
#define COUNTER_16KHZ TCNT2
#define TIMER_10MS_VECT TIMER2_COMPA_vect
#define PAUSE_10MS_INTERRUPT() TIMSK2 &= ~(1<<OCIE2A)
#define RESUME_10MS_INTERRUPT() TIMSK2 |= (1<<OCIE2A)
#define SCHEDULE_MIXER(delay) nextMixerTime = getTmr16KHz() + (delay)
#define PAUSE_PULSES_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
#define RESUME_PULSES_INTERRUPT() TIMSK1 |= (1<<OCIE1A)
#define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3)
#define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3)
#define SLAVE_MODE() (PING & (1<<INP_G_RF_POW))
#define JACK_PPM_OUT() PORTG |= (1<<OUT_G_SIM_CTL)
#define JACK_PPM_IN() PORTG &= ~(1<<OUT_G_SIM_CTL)
extern void sdPoll10ms();
#endif #endif
+6 -1
View File
@@ -47,9 +47,10 @@
extern "C" { extern "C" {
extern void init_SDcard(); extern void init_SDcard();
extern void sdInit(); extern void sdInit();
extern void sdPoll10mS();
} }
#define sdPoll10ms()
void usbMassStorage(); void usbMassStorage();
#define PIN_ENABLE 0x001 #define PIN_ENABLE 0x001
@@ -98,4 +99,8 @@ extern uint32_t Current_used;
extern uint16_t sessionTimer; extern uint16_t sessionTimer;
#endif #endif
#define SLAVE_MODE() (check_soft_power() == e_power_trainer)
#define JACK_PPM_OUT() PIOC->PIO_PDR = PIO_PC22
#define JACK_PPM_IN() PIOC->PIO_PER = PIO_PC22
#endif #endif
+20
View File
@@ -182,3 +182,23 @@ void readKeysAndTrims()
++enuk; ++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<<INP_G_RF_POW));
}
return lastSlaveMode;
}
uint16_t nextMixerTime = 0;
+59
View File
@@ -0,0 +1,59 @@
/*
* Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de>
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - 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<<OCIE0)
#define RESUME_10MS_INTERRUPT() TIMSK |= (1<<OCIE0)
#define PAUSE_PULSES_INTERRUPT() TIMSK &= ~(1<<OCIE1A);
#define RESUME_PULSES_INTERRUPT() TIMSK |= (1<<OCIE1A)
#define SCHEDULE_MIXER(delay) nextMixerTime = getTmr16KHz() + (delay)
#define PAUSE_PPMIN_INTERRUPT() ETIMSK &= ~(1<<TICIE3)
#define RESUME_PPMIN_INTERRUPT() ETIMSK |= (1<<TICIE3)
bool checkSlaveMode();
#define SLAVE_MODE() checkSlaveMode()
#define JACK_PPM_OUT() PORTG &= ~(1<<OUT_G_SIM_CTL)
#define JACK_PPM_IN() PORTG |= (1<<OUT_G_SIM_CTL)
#endif
+8 -8
View File
@@ -39,14 +39,7 @@ void putEvent(uint8_t evt)
s_evt = evt; s_evt = evt;
} }
#if defined(PCBSTD) #if defined(PCBSKY9X)
uint8_t getEvent()
{
uint8_t evt = s_evt;
s_evt = 0;
return evt;
}
#else
uint8_t getEvent(bool trim) uint8_t getEvent(bool trim)
{ {
uint8_t evt = s_evt; uint8_t evt = s_evt;
@@ -61,6 +54,13 @@ uint8_t getEvent(bool trim)
return 0; return 0;
} }
} }
#else
uint8_t getEvent()
{
uint8_t evt = s_evt;
s_evt = 0;
return evt;
}
#endif #endif
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
+2 -2
View File
@@ -106,7 +106,7 @@ void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_
#endif #endif
if (s_sync_write) { if (s_sync_write) {
while (eeprom_buffer_size > 0) WDT_RESET_STOCK(); while (eeprom_buffer_size > 0) wdt_reset();
} }
} }
@@ -794,7 +794,7 @@ void RlcFile::nextRlcWriteStep()
void RlcFile::flush() void RlcFile::flush()
{ {
while (eeprom_buffer_size > 0) WDT_RESET_STOCK(); while (eeprom_buffer_size > 0) wdt_reset();
s_sync_write = true; s_sync_write = true;
while (m_write_len && !s_write_err) while (m_write_len && !s_write_err)
+5 -4
View File
@@ -1189,6 +1189,11 @@ uint8_t barCoord(int16_t value, int16_t min, int16_t max)
void menuTelemetryFrsky(uint8_t event) void menuTelemetryFrsky(uint8_t event)
{ {
if (event == EVT_KEY_FIRST(KEY_EXIT)) {
chainMenu(menuMainView);
return;
}
switch (event) { switch (event) {
case EVT_KEY_BREAK(KEY_UP): case EVT_KEY_BREAK(KEY_UP):
if (s_frsky_view-- == 0) if (s_frsky_view-- == 0)
@@ -1200,10 +1205,6 @@ void menuTelemetryFrsky(uint8_t event)
s_frsky_view = 0; s_frsky_view = 0;
break; break;
case EVT_KEY_FIRST(KEY_EXIT):
chainMenu(menuMainView);
break;
case EVT_KEY_FIRST(KEY_MENU): case EVT_KEY_FIRST(KEY_MENU):
resetTelemetry(); resetTelemetry();
break; break;
+1 -1
View File
@@ -715,7 +715,7 @@ void menuGeneralSdManager(uint8_t event)
void menuGeneralTrainer(uint8_t event) void menuGeneralTrainer(uint8_t event)
{ {
uint8_t y; 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*/}); MENU(STR_MENUTRAINER, menuTabDiag, e_Trainer, slave ? 1 : 7, {0, 2, 2, 2, 2, 0/*, 0*/});
+59 -27
View File
@@ -99,12 +99,31 @@ volatile BYTE Timer1, Timer2; /* 100Hz decrement timer */
static static
BYTE CardType; /* Card type flags */ 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) */ /* 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) BYTE rcvr_spi (void)
{ {
SPDR = 0xFF; SPDR = 0xFF;
loop_until_bit_is_set(SPSR, SPIF); loop_mixer_until_bit_is_set(SPSR, SPIF);
return SPDR; return SPDR;
} }
/* Alternative macro to receive data fast */ /* 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 */ /* This function must be called in period of 10ms */
void sdPoll10mS (void) void sdPoll10ms()
{ {
BYTE s; BYTE s;
/* /*
n = Timer1; // 100Hz decrement timer n = Timer1; // 100Hz decrement timer
if (n) Timer1 = --n; if (n) Timer1 = --n;
n = Timer2; n = Timer2;
if (n) Timer2 = --n; if (n) Timer2 = --n;
*/ */
if (Timer1) Timer1--; if (Timer1) Timer1--;
if (Timer2) Timer2--; if (Timer2) Timer2--;
s = Stat; s = Stat;
/* G: Not implemented /* G: Not implemented
if (SOCKWP) // Write protected if (SOCKWP) // Write protected
s |= STA_PROTECT; s |= STA_PROTECT;
else // Write enabled else // Write enabled
s &= ~STA_PROTECT; s &= ~STA_PROTECT;
if (SOCKINS) // Card inserted if (SOCKINS) // Card inserted
s &= ~STA_NODISK; s &= ~STA_NODISK;
else // Socket empty else // Socket empty
s |= (STA_NODISK | STA_NOINIT); s |= (STA_NODISK | STA_NOINIT);
*/ */
s &= ~STA_NODISK; s &= ~STA_NODISK;
s &= ~STA_PROTECT; s &= ~STA_PROTECT;
Stat = s; 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; FATFS g_FATFS_Obj;
+1 -1
View File
@@ -193,7 +193,7 @@ void menuTelemetryJeti(uint8_t event)
case EVT_KEY_FIRST(KEY_EXIT): case EVT_KEY_FIRST(KEY_EXIT):
JETI_DisableRXD(); JETI_DisableRXD();
chainMenu(menuMainView); chainMenu(menuMainView);
break; return;
} }
for (uint8_t i = 0; i < 16; i++) for (uint8_t i = 0; i < 16; i++)
+2 -2
View File
@@ -150,7 +150,7 @@ void menuMainView(uint8_t event)
case EVT_KEY_STATISTICS: case EVT_KEY_STATISTICS:
chainMenu(menuStatisticsView); chainMenu(menuStatisticsView);
killEvents(event); killEvents(event);
break; return;
case EVT_KEY_TELEMETRY: case EVT_KEY_TELEMETRY:
#if defined(FRSKY) #if defined(FRSKY)
chainMenu(menuTelemetryFrsky); chainMenu(menuTelemetryFrsky);
@@ -169,7 +169,7 @@ void menuMainView(uint8_t event)
chainMenu(menuStatisticsDebug); chainMenu(menuStatisticsDebug);
#endif #endif
killEvents(event); killEvents(event);
break; return;
case EVT_KEY_FIRST(KEY_EXIT): case EVT_KEY_FIRST(KEY_EXIT):
if (s_timerState[0]==TMR_BEEPING) { if (s_timerState[0]==TMR_BEEPING) {
s_timerState[0] = TMR_STOPPED; s_timerState[0] = TMR_STOPPED;
+1 -1
View File
@@ -903,7 +903,7 @@ void menuTelemetryMavlink(uint8_t event) {
case EVT_KEY_FIRST(KEY_EXIT): case EVT_KEY_FIRST(KEY_EXIT):
//MAVLINK_Quit(); //MAVLINK_Quit();
chainMenu(menuMainView); chainMenu(menuMainView);
break; return;
} }
switch (MAVLINK_menu) { switch (MAVLINK_menu) {
+16 -16
View File
@@ -394,18 +394,18 @@ void menuTelemetryNMEA1(uint8_t event)
{ {
case EVT_KEY_BREAK(KEY_LEFT): case EVT_KEY_BREAK(KEY_LEFT):
chainMenu(menuTelemetryNMEA4); chainMenu(menuTelemetryNMEA4);
break; return;
case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_BREAK(KEY_RIGHT):
chainMenu(menuTelemetryNMEA2); chainMenu(menuTelemetryNMEA2);
break; return;
case EVT_KEY_LONG(KEY_UP): case EVT_KEY_LONG(KEY_UP):
NMEA_DisableRXD(); NMEA_DisableRXD();
chainMenu(menuStatisticsView); chainMenu(menuStatisticsView);
break; return;
case EVT_KEY_LONG(KEY_DOWN): case EVT_KEY_LONG(KEY_DOWN):
NMEA_DisableRXD(); NMEA_DisableRXD();
chainMenu(menuMainView); chainMenu(menuMainView);
break; return;
case EVT_KEY_FIRST(KEY_MENU): case EVT_KEY_FIRST(KEY_MENU):
if (show_timer == 0) { if (show_timer == 0) {
show_timer = 1; show_timer = 1;
@@ -507,21 +507,21 @@ void menuTelemetryNMEA2(uint8_t event)
ignore_break=0; ignore_break=0;
break;} break;}
chainMenu(menuTelemetryNMEA1); chainMenu(menuTelemetryNMEA1);
break; return;
case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_BREAK(KEY_RIGHT):
if (ignore_break==1) { if (ignore_break==1) {
ignore_break=0; ignore_break=0;
break;} break;}
chainMenu(menuTelemetryNMEA3); chainMenu(menuTelemetryNMEA3);
break; return;
case EVT_KEY_LONG(KEY_UP): case EVT_KEY_LONG(KEY_UP):
NMEA_DisableRXD(); NMEA_DisableRXD();
chainMenu(menuStatisticsView); chainMenu(menuStatisticsView);
break; return;
case EVT_KEY_LONG(KEY_DOWN): case EVT_KEY_LONG(KEY_DOWN):
NMEA_DisableRXD(); NMEA_DisableRXD();
chainMenu(menuMainView); chainMenu(menuMainView);
break; return;
//Beep setting //Beep setting
case EVT_KEY_LONG(KEY_LEFT): case EVT_KEY_LONG(KEY_LEFT):
@@ -662,18 +662,18 @@ void menuTelemetryNMEA3(uint8_t event)
{ {
case EVT_KEY_BREAK(KEY_LEFT): case EVT_KEY_BREAK(KEY_LEFT):
chainMenu(menuTelemetryNMEA2); chainMenu(menuTelemetryNMEA2);
break; return;
case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_BREAK(KEY_RIGHT):
chainMenu(menuTelemetryNMEA4); chainMenu(menuTelemetryNMEA4);
break; return;
case EVT_KEY_LONG(KEY_UP): case EVT_KEY_LONG(KEY_UP):
NMEA_DisableRXD(); NMEA_DisableRXD();
chainMenu(menuStatisticsView); chainMenu(menuStatisticsView);
break; return;
case EVT_KEY_LONG(KEY_DOWN): case EVT_KEY_LONG(KEY_DOWN):
NMEA_DisableRXD(); NMEA_DisableRXD();
chainMenu(menuMainView); chainMenu(menuMainView);
break; return;
} }
initval (LONG_BUF(0), PACK_RMC, SOG); initval (LONG_BUF(0), PACK_RMC, SOG);
initval (LONG_BUF(1), PACK_RMC, COG); initval (LONG_BUF(1), PACK_RMC, COG);
@@ -711,18 +711,18 @@ void menuTelemetryNMEA4(uint8_t event)
{ {
case EVT_KEY_BREAK(KEY_LEFT): case EVT_KEY_BREAK(KEY_LEFT):
chainMenu(menuTelemetryNMEA3); chainMenu(menuTelemetryNMEA3);
break; return;
case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_BREAK(KEY_RIGHT):
chainMenu(menuTelemetryNMEA1); chainMenu(menuTelemetryNMEA1);
break; return;
case EVT_KEY_LONG(KEY_UP): case EVT_KEY_LONG(KEY_UP):
NMEA_DisableRXD(); NMEA_DisableRXD();
chainMenu(menuStatisticsView); chainMenu(menuStatisticsView);
break; return;
case EVT_KEY_LONG(KEY_DOWN): case EVT_KEY_LONG(KEY_DOWN):
NMEA_DisableRXD(); NMEA_DisableRXD();
chainMenu(menuMainView); chainMenu(menuMainView);
break; return;
} }
// expecting LAT value in POS packet to be stored in the first buffer // expecting LAT value in POS packet to be stored in the first buffer
initval (LONG_BUF(0), PACK_GGA, LAT); initval (LONG_BUF(0), PACK_GGA, LAT);
+99 -223
View File
@@ -95,10 +95,9 @@ uint8_t g_tmr1Latency_min;
uint8_t unexpectedShutdown = 0; uint8_t unexpectedShutdown = 0;
uint16_t g_timeMainMax; /* mixer duration in 1/16ms */
#if defined(PCBGRUVIN9X) uint16_t maxMixerDuration;
uint8_t lastMixerDuration; uint16_t lastMixerDuration;
#endif
#if defined(AUDIO) && !defined(PCBSKY9X) #if defined(AUDIO) && !defined(PCBSKY9X)
audioQueue audio; audioQueue audio;
@@ -1259,7 +1258,7 @@ void checkSwitches()
checkBacklight(); checkBacklight();
WDT_RESET_STOCK(); wdt_reset();
#ifdef SIMU #ifdef SIMU
if (!main_thread_running) return; if (!main_thread_running) return;
@@ -1286,7 +1285,7 @@ void alert(const pm_char * t, const pm_char *s MESSAGE_SOUND_ARG)
checkBacklight(); 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 }; int8_t trimGvar[NUM_STICKS] = { -1, -1, -1, -1 };
#endif #endif
#if defined(PCBSTD) #if defined(PCBSKY9X)
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
void checkTrims() void checkTrims()
{ {
uint8_t event = getEvent(true); uint8_t event = getEvent(true);
if (event && !IS_KEY_BREAK(event)) { if (event && !IS_KEY_BREAK(event)) {
int8_t k = (event & EVT_KEY_MASK) - TRM_BASE; int8_t k = (event & EVT_KEY_MASK) - TRM_BASE;
int8_t s = g_model.trimInc; 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 #endif
// LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP // 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; uint8_t idx = CONVERT_MODE(1+k/2) - 1;
@@ -1430,11 +1429,11 @@ void checkTrims()
else { else {
AUDIO_TRIM(event, after); AUDIO_TRIM(event, after);
} }
#if defined(PCBSTD) #if !defined(PCBSKY9X)
return 0; return 0;
#endif #endif
} }
#if defined(PCBSTD) #if !defined(PCBSKY9X)
return event; return event;
#endif #endif
} }
@@ -1632,30 +1631,6 @@ void getADC_bandgap()
uint8_t g_vbat100mV = 0; uint8_t g_vbat100mV = 0;
uint16_t g_LightOffCounter; 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_timeCumTot;
uint16_t s_timeCumThr; // THR in 1/16 sec uint16_t s_timeCumThr; // THR in 1/16 sec
uint16_t s_timeCum16ThrP; // 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; sDelay[i] = md->delayUp * 50;
} }
if (sDelay[i] > 0) { // perform delay if (sDelay[i] > 0) { // perform delay
sDelay[i] -= tick10ms; sDelay[i] = max(0, sDelay[i]-tick10ms);
if (!md->swtch) { if (!md->swtch) {
v = -1024; v = -1024;
} }
@@ -2387,7 +2362,7 @@ void perOut(uint8_t tick10ms)
sDelay[i] = md->delayDown * 50; sDelay[i] = md->delayDown * 50;
} }
if (sDelay[i] > 0) { // perform delay if (sDelay[i] > 0) { // perform delay
sDelay[i] -= tick10ms; sDelay[i] = max(0, sDelay[i]-tick10ms);
if (!md->swtch) v = +1024; if (!md->swtch) v = +1024;
has_delay = true; has_delay = true;
} }
@@ -2510,9 +2485,24 @@ void perOut(uint8_t tick10ms)
ACTIVE_MIXES_TYPE activeMixes; ACTIVE_MIXES_TYPE activeMixes;
#endif #endif
int32_t sum_chans512[NUM_CHNOUT] = {0}; 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; activeMixes = 0;
#endif #endif
@@ -2602,12 +2592,20 @@ inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms)
sei(); 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... // Bandgap has had plenty of time to settle...
#if !defined(PCBSKY9X) #if !defined(PCBSKY9X)
getADC_bandgap(); getADC_bandgap();
#endif #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. if (!tick10ms) return; //make sure the rest happen only every 10ms.
#endif
/* Throttle trace */ /* Throttle trace */
int16_t val; int16_t val;
@@ -2813,43 +2811,48 @@ inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms)
setVolume(requiredSpeakerVolume); setVolume(requiredSpeakerVolume);
currentSpeakerVolume = requiredSpeakerVolume; currentSpeakerVolume = requiredSpeakerVolume;
} }
return true;
#endif #endif
} }
void perMain() void perMain()
{ {
static tmr10ms_t lastTMR; #if defined(SIMU)
tmr10ms_t tmr10ms = get_tmr10ms(); doMixerCalculations();
uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); #elif !defined(PCBSKY9X)
lastTMR = tmr10ms; uint16_t t0 = getTmr16KHz();
int16_t delta = t0 - nextMixerTime;
if (delta < 0) return;
#if defined(PCBSTD) || defined(SIMU) nextMixerTime = t0 + 20*16;
doMixerCalculations(tmr10ms, tick10ms); doMixerCalculations();
t0 = getTmr16KHz() - t0;
lastMixerDuration = t0;
if (t0 > maxMixerDuration) maxMixerDuration = t0;
#endif #endif
// TODO same code here + integrate the timer which could be common // TODO same code here + integrate the timer which could be common
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
if (Tenms) { if (!Tenms) return;
Tenms = 0 ; Tenms = 0 ;
if (Eeprom32_process_state != E32_IDLE) Current_accumulator += Current_analogue ;
ee32_process(); static uint32_t OneSecTimer;
else if (TIME_TO_WRITE) if (++OneSecTimer >= 100) {
eeCheck(); OneSecTimer -= 100 ;
sessionTimer += 1;
Current_accumulator += Current_analogue ; Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled)
static uint32_t OneSecTimer; Current_accumulator = 0 ;
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
} }
#endif
#if defined(PCBSKY9X)
if (Eeprom32_process_state != E32_IDLE)
ee32_process();
else if (TIME_TO_WRITE)
eeCheck();
#else #else
if (!eeprom_buffer_size) { if (!eeprom_buffer_size) {
if (theFile.isWriting()) if (theFile.isWriting())
@@ -2859,33 +2862,20 @@ void perMain()
} }
#endif #endif
if (!tick10ms) return; //make sure the rest happen only every 10ms.
#if defined(SDCARD) #if defined(SDCARD)
#if defined(PCBGRUVIN9X) sdMountPoll();
static uint8_t mountTimer;
if (mountTimer-- == 0) {
mountTimer = 100;
if (g_FATFS_Obj.fs_type == 0) {
f_mount(0, &g_FATFS_Obj);
}
}
#endif
writeLogs(); writeLogs();
#endif #endif
lcd_clear();
#if defined(PCBSKY9X) && defined(SIMU) #if defined(PCBSKY9X) && defined(SIMU)
checkTrims(); checkTrims();
#endif #endif
#if defined(PCBSTD) #if defined(PCBSKY9X)
uint8_t evt = getEvent(false);
#else
uint8_t evt = getEvent(); uint8_t evt = getEvent();
evt = checkTrim(evt); evt = checkTrim(evt);
#else
uint8_t evt = getEvent(false);
#endif #endif
if (g_LightOffCounter) g_LightOffCounter--; if (g_LightOffCounter) g_LightOffCounter--;
@@ -2897,44 +2887,27 @@ void perMain()
check_frsky(); check_frsky();
#endif #endif
lcd_clear();
const char *warn = s_warning; const char *warn = s_warning;
g_menuStack[g_menuStackPtr](warn ? 0 : evt); g_menuStack[g_menuStackPtr](warn ? 0 : evt);
if (warn) displayWarning(evt); if (warn) displayWarning(evt);
drawStatusLine(); drawStatusLine();
refreshDisplay(); refreshDisplay();
#if defined(PCBSKY9X) if (SLAVE_MODE()) {
if ( check_soft_power() == e_power_trainer ) { // On trainer power JACK_PPM_OUT();
PIOC->PIO_PDR = PIO_PC22 ; // Disable bit C22 Assign to peripheral
} }
else { 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<<OUT_G_SIM_CTL); // 1=ppm out
}
else{
PORTG &= ~(1<<OUT_G_SIM_CTL); // 0=ppm in
}
#elif defined(PCBSTD)
// PPM signal on phono-jack. In or out? ...
if(checkSlaveMode()) {
PORTG &= ~(1<<OUT_G_SIM_CTL); // 0=ppm out
}
else{
PORTG |= (1<<OUT_G_SIM_CTL); // 1=ppm-in
}
#endif
#if defined(PCBSKY9X)
static uint8_t counter = 0; static uint8_t counter = 0;
if (g_menuStack[g_menuStackPtr] == menuGeneralDiagAna) {
g_vbat100mV = 0;
counter = 0;
}
if (counter-- == 0) { if (counter-- == 0) {
counter = 10; counter = 10;
#else
if ((tmr10ms & 0x1f) == 2 /*every 10ms*32*/ || g_menuStack[g_menuStackPtr] == menuGeneralDiagAna) {
#endif
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
int32_t instant_vbat = anaIn(7); int32_t instant_vbat = anaIn(7);
@@ -2954,7 +2927,7 @@ void perMain()
s_batCheck += 32; s_batCheck += 32;
s_batSum += instant_vbat; s_batSum += instant_vbat;
if (g_vbat100mV == 0 || g_menuStack[g_menuStackPtr] == menuGeneralDiagAna) { if (g_vbat100mV == 0) {
g_vbat100mV = instant_vbat; g_vbat100mV = instant_vbat;
s_batSum = 0; s_batSum = 0;
s_batCheck = 0; s_batCheck = 0;
@@ -2983,11 +2956,7 @@ uint8_t ppmInState = 0; //0=unsync 1..8= wait for value i-1
#if !defined(SIMU) && !defined(PCBSKY9X) #if !defined(SIMU) && !defined(PCBSKY9X)
volatile uint8_t g_tmr16KHz; //continuous timer 16ms (16MHz/1024/256) -- 8-bit counter overflow volatile uint8_t g_tmr16KHz; //continuous timer 16ms (16MHz/1024/256) -- 8-bit counter overflow
#if defined (PCBGRUVIN9X) ISR(TIMER_16KHZ_VECT, ISR_NOBLOCK)
ISR(TIMER2_OVF_vect)
#else
ISR(TIMER0_OVF_vect) // TODO now NOBLOCK in er9x
#endif
{ {
g_tmr16KHz++; // gruvin: Not 16KHz. Overflows occur at 61.035Hz (1/256th of 15.625KHz) g_tmr16KHz++; // gruvin: Not 16KHz. Overflows occur at 61.035Hz (1/256th of 15.625KHz)
// to give *16.384ms* intervals. Kind of matters for accuracy elsewhere. ;) // to give *16.384ms* intervals. Kind of matters for accuracy elsewhere. ;)
@@ -2999,80 +2968,15 @@ uint16_t getTmr16KHz()
{ {
while(1){ while(1){
uint8_t hb = g_tmr16KHz; uint8_t hb = g_tmr16KHz;
#if defined (PCBGRUVIN9X) uint8_t lb = COUNTER_16KHZ;
uint8_t lb = TCNT2;
#else
uint8_t lb = TCNT0;
#endif
if(hb-g_tmr16KHz==0) return (hb<<8)|lb; if(hb-g_tmr16KHz==0) return (hb<<8)|lb;
} }
} }
#if defined (PCBGRUVIN9X) ISR(TIMER_10MS_VECT, ISR_NOBLOCK) // 10ms timer
/**** SCHEDULED MIXER INTERRUPT ****/
// On G9X board, we use TIMER5 to schedule mixer execution, to achieve
// minimal system latency between reading sticks and outputting data.
ISR(TIMER5_COMPA_vect, ISR_NOBLOCK)
{
#if defined(DEBUG) && !defined(VOICE)
PORTH |= 0x40; // PORTH:6 LOW->HIGH signals start of mixer interrupt
#endif
cli();
TIMSK5 &= ~(1<<OCIE5A); //stop reentrance
OCR5A = 0x7d * 40; /* 20ms */
sei();
uint16_t t0 = getTmr16KHz();
static tmr10ms_t lastTMR;
tmr10ms_t tmr10ms = get_tmr10ms();
uint8_t tick10ms = (tmr10ms >= 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<<OCIE5A); //stop reentrance
sei();
#if defined(DEBUG) && !defined(VOICE)
PORTH &= ~0x40; // PORTH:6 HIGH->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
{ {
cli(); cli();
PAUSE_10MS_INTERRUPT();
#if defined(PCBGRUVIN9X)
TIMSK2 &= ~(1<<OCIE2A); // stop reentrance
#else
TIMSK &= ~(1<<OCIE0); // stop reentrance
#endif
sei(); sei();
#if defined(PCBGRUVIN9X) #if defined(PCBGRUVIN9X)
@@ -3112,32 +3016,24 @@ ISR(TIMER0_COMP_vect, ISR_NOBLOCK) //10ms timer
AUDIO_HEARTBEAT(); AUDIO_HEARTBEAT();
#ifdef HAPTIC #if defined(HAPTIC)
HAPTIC_HEARTBEAT(); HAPTIC_HEARTBEAT();
#endif #endif
per10ms(); per10ms();
#if defined(PCBGRUVIN9X) && defined(SDCARD) #if defined(SDCARD)
sdPoll10mS(); sdPoll10ms();
#endif #endif
#if !defined(PCBGRUVIN9X) heartbeat |= HEART_TIMER10ms;
heartbeat |= HEART_TIMER10ms; // TODO check heartbeat everywhere!
#endif
#if defined(PCBSTD) && (defined(AUDIO) || defined(VOICE)) #if defined(PCBSTD) && (defined(AUDIO) || defined(VOICE))
} // end 10ms event } // end 10ms event
#endif #endif
cli(); cli();
RESUME_10MS_INTERRUPT();
#if defined(PCBGRUVIN9X)
TIMSK2 |= (1<<OCIE2A);
#else
TIMSK |= (1<<OCIE0);
#endif
sei(); sei();
} }
@@ -3153,11 +3049,7 @@ ISR(TIMER3_CAPT_vect) // G: High frequency noise can cause stack overflo with IS
uint16_t capture=ICR3; uint16_t capture=ICR3;
// Prevent rentrance for this IRQ only // Prevent rentrance for this IRQ only
#if defined (PCBGRUVIN9X) PAUSE_PPMIN_INTERRUPT();
TIMSK3 &= ~(1<<ICIE3);
#else
ETIMSK &= ~(1<<TICIE3);
#endif
sei(); // enable other interrupts sei(); // enable other interrupts
uint16_t val = (capture - lastCapt) / 2; uint16_t val = (capture - lastCapt) / 2;
@@ -3183,11 +3075,7 @@ ISR(TIMER3_CAPT_vect) // G: High frequency noise can cause stack overflo with IS
lastCapt = capture; lastCapt = capture;
cli(); // disable other interrupts for stack pops before this function's RETI cli(); // disable other interrupts for stack pops before this function's RETI
#if defined (PCBGRUVIN9X) RESUME_PPMIN_INTERRUPT();
TIMSK3 |= (1<<ICIE3);
#else
ETIMSK |= (1<<TICIE3);
#endif
} }
/* /*
@@ -3534,19 +3422,14 @@ void mixerTask(void * pdata)
if (!s_pulses_paused) { if (!s_pulses_paused) {
uint16_t t0 = getTmr2MHz(); uint16_t t0 = getTmr2MHz();
static tmr10ms_t lastTMR;
tmr10ms_t tmr10ms = get_tmr10ms();
uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1);
lastTMR = tmr10ms;
if (s_current_protocol < PROTO_NONE) { if (s_current_protocol < PROTO_NONE) {
CoEnterMutexSection(mixerMutex); CoEnterMutexSection(mixerMutex);
doMixerCalculations(tmr10ms, tick10ms); bool tick10ms = doMixerCalculations();
CoLeaveMutexSection(mixerMutex); CoLeaveMutexSection(mixerMutex);
if (tick10ms) checkTrims(); if (tick10ms) checkTrims();
} }
heartbeat |= HEART_TIMER10ms; heartbeat |= HEART_TIMER10ms; // TODO not here but in 10ms interrupt!
if (heartbeat == HEART_TIMER_PULSES+HEART_TIMER10ms) { if (heartbeat == HEART_TIMER_PULSES+HEART_TIMER10ms) {
wdt_reset(); wdt_reset();
@@ -3554,7 +3437,7 @@ void mixerTask(void * pdata)
} }
t0 = getTmr2MHz() - t0; t0 = getTmr2MHz() - t0;
if (t0 > g_timeMainMax) g_timeMainMax = t0 ; if (t0 > maxMixerDuration) maxMixerDuration = t0 ;
} }
CoTickDelay(1); // 2ms for now CoTickDelay(1); // 2ms for now
@@ -3733,20 +3616,13 @@ int main(void)
break; break;
#endif #endif
#if defined(PCBSTD)
uint16_t t0 = getTmr16KHz();
#endif
perMain(); perMain();
#if defined(PCBSTD) #if !defined(PCBSKY9X)
if(heartbeat == HEART_TIMER_PULSES+HEART_TIMER10ms) { if(heartbeat == HEART_TIMER_PULSES+HEART_TIMER10ms) {
wdt_reset(); wdt_reset();
heartbeat = 0; heartbeat = 0;
} }
t0 = getTmr16KHz() - t0;
if (t0 > g_timeMainMax) g_timeMainMax = t0;
#endif #endif
} }
#endif // PCBSKY9X #endif // PCBSKY9X
+7 -33
View File
@@ -138,12 +138,6 @@
#define IF_GVARS(x) #define IF_GVARS(x)
#endif #endif
#if defined(PCBSTD)
#define WDT_RESET_STOCK() wdt_reset()
#else
#define WDT_RESET_STOCK()
#endif
/* /*
#define HELI_VARIANT 0x0004 #define HELI_VARIANT 0x0004
#define VOICE_VARIANT 0x0008 #define VOICE_VARIANT 0x0008
@@ -157,6 +151,8 @@
#include "board_sky9x.h" #include "board_sky9x.h"
#elif defined(PCBGRUVIN9X) #elif defined(PCBGRUVIN9X)
#include "board_gruvin9x.h" #include "board_gruvin9x.h"
#else
#include "board_stock.h"
#endif #endif
#if defined(SIMU) #if defined(SIMU)
@@ -400,12 +396,6 @@ extern uint8_t s_bind_allowed;
#endif // defined (PCBGRUVIN9X) #endif // defined (PCBGRUVIN9X)
#if defined(PCBSKY9X)
#define SLAVE_MODE (check_soft_power() == e_power_trainer)
#else
#define SLAVE_MODE (PING & (1<<INP_G_RF_POW))
#endif
extern const pm_uint8_t bchout_ar[]; extern const pm_uint8_t bchout_ar[];
extern const pm_uint8_t modn12x3[]; extern const pm_uint8_t modn12x3[];
@@ -644,10 +634,10 @@ extern char idx2char(int8_t idx);
void clearKeyEvents(); void clearKeyEvents();
void pauseEvents(uint8_t enuk); void pauseEvents(uint8_t enuk);
void killEvents(uint8_t enuk); void killEvents(uint8_t enuk);
#if defined(PCBSTD) #if defined(PCBSKY9X)
uint8_t getEvent();
#else
uint8_t getEvent(bool trim); uint8_t getEvent(bool trim);
#else
uint8_t getEvent();
#endif #endif
void putEvent(uint8_t evt); void putEvent(uint8_t evt);
@@ -787,10 +777,8 @@ void resetAll();
extern uint8_t unexpectedShutdown; extern uint8_t unexpectedShutdown;
extern uint8_t g_tmr1Latency_max; extern uint8_t g_tmr1Latency_max;
extern uint8_t g_tmr1Latency_min; extern uint8_t g_tmr1Latency_min;
extern uint16_t g_timeMainMax; extern uint16_t maxMixerDuration;
#if defined(PCBGRUVIN9X) extern uint16_t lastMixerDuration;
extern uint8_t lastMixerDuration;
#endif
#if defined(THRTRACE) #if defined(THRTRACE)
#define MAXTRACE 120 #define MAXTRACE 120
@@ -930,20 +918,6 @@ inline void resumeMixerCalculations()
{ {
CoLeaveMutexSection(mixerMutex); CoLeaveMutexSection(mixerMutex);
} }
#elif defined(PCBGRUVIN9X)
inline void pauseMixerCalculations()
{
cli();
TIMSK5 &= ~(1<<OCIE5A);
sei();
}
inline void resumeMixerCalculations()
{
cli();
TIMSK5 |= (1<<OCIE5A);
sei();
}
#else #else
#define pauseMixerCalculations() #define pauseMixerCalculations()
#define resumeMixerCalculations() #define resumeMixerCalculations()
+22 -38
View File
@@ -147,23 +147,13 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation (BLOCKING ISR)
pulses2MHzRPtr += sizeof(uint16_t); // non PPM protocols use uint8_t pulse buffer pulses2MHzRPtr += sizeof(uint16_t); // non PPM protocols use uint8_t pulse buffer
if (*((uint16_t*)pulses2MHzRPtr) == 0) { if (*((uint16_t*)pulses2MHzRPtr) == 0) {
PAUSE_PULSES_INTERRUPT();
#if defined(PCBGRUVIN9X)
TIMSK1 &= ~(1<<OCIE1A); // stop reentrance (disable Timer1 interrupt)
#else
TIMSK &= ~(1<<OCIE1A); // stop reentrance (disable Timer1 interrupt)
#endif
setupPulses(); // does not sei() for setupPulsesPPM setupPulses(); // does not sei() for setupPulsesPPM
// if setupPulses changed protocol to one that doesn't use COMPA then don't re-enable. // if setupPulses changed protocol to one that doesn't use COMPA then don't re-enable.
if (!IS_PXX_PROTOCOL(s_current_protocol) && !IS_DSM2_PROTOCOL(s_current_protocol)) { if (!IS_PXX_PROTOCOL(s_current_protocol) && !IS_DSM2_PROTOCOL(s_current_protocol)) {
// cli is not needed because for PPM protocols interrupts are not enabled when entering here // cli is not needed because for PPM protocols interrupts are not enabled when entering here
#if defined(PCBGRUVIN9X) RESUME_PULSES_INTERRUPT();
TIMSK1 |= (1<<OCIE1A); // re-enable Timer1 interrupt
#else
TIMSK |= (1<<OCIE1A); // re-enable Timer1 interrupt
#endif
sei(); sei();
} }
} }
@@ -495,23 +485,21 @@ void sendByteDsm2(uint8_t b) //max 10changes 0 10 10 10 10 1
{ {
bool lev = 0; bool lev = 0;
uint8_t len = BITLEN_DSM2; //max val: 9*16 < 256 uint8_t len = BITLEN_DSM2; //max val: 9*16 < 256
for( uint8_t i=0; i<=8; i++){ //8Bits + Stop=1 for (uint8_t i=0; i<=8; i++) { //8Bits + Stop=1
bool nlev = b & 1; //lsb first bool nlev = b & 1; //lsb first
if(lev == nlev){ if (lev == nlev){
len += BITLEN_DSM2; len += BITLEN_DSM2;
}else{ }
#if defined (PCBGRUVIN9X) else {
// G: Compensate for main clock synchronisation -- to get accurate 8us bit length #if defined(PCBGRUVIN9X)
// NOTE: This has now been tested as NOT required on the stock board, with the ATmega64A chip. // G: Compensate for main clock synchronisation -- to get accurate 8us bit length
if (nlev) // NOTE: This has now been tested as NOT required on the stock board, with the ATmega64A chip.
_send_1(len-5);// -1); _send_1(nlev ? len-5 : len+3);
else
_send_1(len+3);
#else #else
_send_1(len -1); _send_1(len -1);
#endif #endif
len = BITLEN_DSM2; len = BITLEN_DSM2;
lev = nlev; lev = nlev;
} }
b = (b>>1) | 0x80; //shift in stop bit b = (b>>1) | 0x80; //shift in stop bit
} }
@@ -894,6 +882,8 @@ void setupPulses()
#ifdef PXX #ifdef PXX
case PROTO_PXX: case PROTO_PXX:
// schedule next Mixer calculations
SCHEDULE_MIXER(20*16-lastMixerDuration-2*16/*1ms*/);
sei(); sei();
setupPulsesPXX(); setupPulsesPXX();
break; break;
@@ -901,11 +891,8 @@ void setupPulses()
#ifdef DSM2 #ifdef DSM2
case PROTO_DSM2: case PROTO_DSM2:
#if defined(PCBGRUVIN9X) // schedule next Mixer calculations
// schedule next Mixer interrupt SCHEDULE_MIXER(22*16-lastMixerDuration-2*16/*1ms*/);
OCR5A = (uint16_t)0x7d * (44-lastMixerDuration-2/*1ms*/);
TCNT5 = 0;
#endif
sei(); sei();
setupPulsesDsm2(); // Different versions for DSM2=SERIAL vs. DSM2=PPM setupPulsesDsm2(); // Different versions for DSM2=SERIAL vs. DSM2=PPM
#if defined(PCBGRUVIN9X) && defined(DSM2_PPM) #if defined(PCBGRUVIN9X) && defined(DSM2_PPM)
@@ -917,7 +904,7 @@ void setupPulses()
break; break;
#endif #endif
#ifdef IRPROTOS #if defined(IRPROTOS)
case PROTO_PICZ: case PROTO_PICZ:
setupPulsesPiccoZ(g_model.ppmNCH); setupPulsesPiccoZ(g_model.ppmNCH);
// TODO BSS stbyLevel = 0; //start with 1 // TODO BSS stbyLevel = 0; //start with 1
@@ -925,14 +912,11 @@ void setupPulses()
#endif #endif
default: // standard PPM protocol default: // standard PPM protocol
#ifndef SIMU #if !defined(SIMU)
g_ppmPulsePolarity = g_model.pulsePol; g_ppmPulsePolarity = g_model.pulsePol;
#endif #endif
#if defined(PCBGRUVIN9X) // schedule next Mixer calculations
// schedule next Mixer interrupt SCHEDULE_MIXER(45*8+g_model.ppmFrameLength*8-lastMixerDuration-2*16/*1ms*/);
OCR5A = (uint16_t)0x7d * (45+g_model.ppmFrameLength-lastMixerDuration-2/*1ms*/);
TCNT5 = 0;
#endif
// no sei here // no sei here
setupPulsesPPM(PROTO_PPM); setupPulsesPPM(PROTO_PPM);
// if PPM16, PPM16 pulses are set up automatically within the interrupts // if PPM16, PPM16 pulses are set up automatically within the interrupts
+5 -2
View File
@@ -69,8 +69,11 @@ inline const pm_char *SDCARD_ERROR(FRESULT result)
return STR_SDCARD_ERROR; return STR_SDCARD_ERROR;
} }
// TODO move the ARM function definition here (when cpp) #if defined(SIMU)
extern void sdPoll10mS(); #define sdMountPoll()
#else
extern void sdMountPoll();
#endif
#if defined(PCBSKY9X) && !(defined(SIMU)) #if defined(PCBSKY9X) && !(defined(SIMU))
extern "C" { extern "C" {
+2 -2
View File
@@ -34,7 +34,7 @@
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* MMCv3/SDv1/SDv2 (in SPI mode) control module (C)ChaN, 2010 */ /* 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. */ /* are platform dependent. */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
@@ -956,7 +956,7 @@ FATFS g_FATFS_Obj = { 0 };
extern void retrieveAvailableAudioFiles(); extern void retrieveAvailableAudioFiles();
void sdPoll10mS() void sdMountPoll()
{ {
if (!Card_initialized) if (!Card_initialized)
return; return;
+9 -9
View File
@@ -40,11 +40,11 @@ void menuStatisticsView(uint8_t event)
{ {
case EVT_KEY_FIRST(KEY_UP): case EVT_KEY_FIRST(KEY_UP):
chainMenu(menuStatisticsDebug); chainMenu(menuStatisticsDebug);
break; return;
case EVT_KEY_FIRST(KEY_DOWN): case EVT_KEY_FIRST(KEY_DOWN):
case EVT_KEY_FIRST(KEY_EXIT): case EVT_KEY_FIRST(KEY_EXIT):
chainMenu(menuMainView); chainMenu(menuMainView);
break; return;
} }
lcd_puts( 1*FW, FH*1, STR_TM1TM2); lcd_puts( 1*FW, FH*1, STR_TM1TM2);
@@ -105,16 +105,16 @@ void menuStatisticsDebug(uint8_t event)
g_tmr1Latency_min = 0xff; g_tmr1Latency_min = 0xff;
g_tmr1Latency_max = 0; g_tmr1Latency_max = 0;
#endif #endif
g_timeMainMax = 0; maxMixerDuration = 0;
AUDIO_KEYPAD_UP(); AUDIO_KEYPAD_UP();
break; break;
case EVT_KEY_FIRST(KEY_DOWN): case EVT_KEY_FIRST(KEY_DOWN):
chainMenu(menuStatisticsView); chainMenu(menuStatisticsView);
break; return;
case EVT_KEY_FIRST(KEY_UP): case EVT_KEY_FIRST(KEY_UP):
case EVT_KEY_FIRST(KEY_EXIT): case EVT_KEY_FIRST(KEY_EXIT):
chainMenu(menuMainView); chainMenu(menuMainView);
break; return;
} }
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
@@ -143,8 +143,8 @@ void menuStatisticsDebug(uint8_t event)
putsTelemetryValue(20*FW+2, 4*FH, Coproc_maxtemp, UNIT_DEGREES, 0); putsTelemetryValue(20*FW+2, 4*FH, Coproc_maxtemp, UNIT_DEGREES, 0);
} }
lcd_putsLeft(5*FH, STR_TMAINMAXMS); lcd_putsLeft(5*FH, STR_TMIXMAXMS);
lcd_outdezAtt(MENU_DEBUG_COL_OFS, 5*FH, (g_timeMainMax)/20, PREC2); lcd_outdezAtt(MENU_DEBUG_COL_OFS, 5*FH, (maxMixerDuration)/20, PREC2);
lcd_putsLeft(6*FH, STR_FREESTACKMINB); lcd_putsLeft(6*FH, STR_FREESTACKMINB);
lcd_outdezAtt(13*FW, 6*FH, stack_free(0), UNSIGN); 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_outdez8(MENU_DEBUG_COL_OFS , 2*FH, g_tmr1Latency_min/2 );
lcd_putsLeft(3*FH, STR_TMR1JITTERUS); lcd_putsLeft(3*FH, STR_TMR1JITTERUS);
lcd_outdez8(MENU_DEBUG_COL_OFS , 3*FH, (g_tmr1Latency_max - g_tmr1Latency_min) /2 ); lcd_outdez8(MENU_DEBUG_COL_OFS , 3*FH, (g_tmr1Latency_max - g_tmr1Latency_min) /2 );
lcd_putsLeft(4*FH, STR_TMAINMAXMS); lcd_putsLeft(4*FH, STR_TMIXMAXMS);
lcd_outdezAtt(MENU_DEBUG_COL_OFS, 4*FH, (g_timeMainMax*100)/16, PREC2); lcd_outdezAtt(MENU_DEBUG_COL_OFS, 4*FH, (maxMixerDuration*100)/16, PREC2);
lcd_putsLeft(5*FH, STR_FREESTACKMINB); lcd_putsLeft(5*FH, STR_FREESTACKMINB);
lcd_outdezAtt(14*FW, 5*FH, stack_free(), UNSIGN) ; lcd_outdezAtt(14*FW, 5*FH, stack_free(), UNSIGN) ;
#endif #endif
+1 -1
View File
@@ -214,7 +214,7 @@ const pm_char STR_TOT[] PROGMEM = TR_TOT;
const pm_char STR_TMR1LATMAXUS[] PROGMEM = TR_TMR1LATMAXUS; const pm_char STR_TMR1LATMAXUS[] PROGMEM = TR_TMR1LATMAXUS;
const pm_char STR_TMR1LATMINUS[] PROGMEM = TR_TMR1LATMINUS; const pm_char STR_TMR1LATMINUS[] PROGMEM = TR_TMR1LATMINUS;
const pm_char STR_TMR1JITTERUS[] PROGMEM = TR_TMR1JITTERUS; 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 #ifdef DEBUG
const pm_char STR_T10MSUS[] PROGMEM = TR_T10MSUS; const pm_char STR_T10MSUS[] PROGMEM = TR_T10MSUS;
#endif #endif
+1 -1
View File
@@ -323,7 +323,7 @@ extern const pm_char STR_TOT[];
extern const pm_char STR_TMR1LATMAXUS[]; extern const pm_char STR_TMR1LATMAXUS[];
extern const pm_char STR_TMR1LATMINUS[]; extern const pm_char STR_TMR1LATMINUS[];
extern const pm_char STR_TMR1JITTERUS[]; 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_T10MSUS[];
extern const pm_char STR_FREESTACKMINB[]; extern const pm_char STR_FREESTACKMINB[];
extern const pm_char STR_MENUTORESET[]; extern const pm_char STR_MENUTORESET[];
+2 -2
View File
@@ -342,9 +342,9 @@
#define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1LATMINUS "Tmr1Lat min\006us"
#define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us"
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define TR_TMAINMAXMS "Tmain max\010ms" #define TR_TMIXMAXMS "Tmix max\012ms"
#else #else
#define TR_TMAINMAXMS "Tmain max\012ms" #define TR_TMIXMAXMS "Tmix max\014ms"
#endif #endif
#define TR_T10MSUS "T10ms\016us" #define TR_T10MSUS "T10ms\016us"
#define TR_FREESTACKMINB "Free Stack\010b" #define TR_FREESTACKMINB "Free Stack\010b"
+2 -2
View File
@@ -343,9 +343,9 @@
#define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1LATMINUS "Tmr1Lat min\006us"
#define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us"
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define TR_TMAINMAXMS "Tmain max\010ms" #define TR_TMIXMAXMS "Tmix max\012ms"
#else #else
#define TR_TMAINMAXMS "Tmain max\012ms" #define TR_TMIXMAXMS "Tmix max\014ms"
#endif #endif
#define TR_T10MSUS "T10ms\016us" #define TR_T10MSUS "T10ms\016us"
#define TR_FREESTACKMINB "Free Stack\010b" #define TR_FREESTACKMINB "Free Stack\010b"
+2 -2
View File
@@ -343,9 +343,9 @@
#define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1LATMINUS "Tmr1Lat min\006us"
#define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us"
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define TR_TMAINMAXMS "Tmain max\010ms" #define TR_TMIXMAXMS "Tmix max\012ms"
#else #else
#define TR_TMAINMAXMS "Tmain max\012ms" #define TR_TMIXMAXMS "Tmix max\014ms"
#endif #endif
#define TR_T10MSUS "T10ms\016us" #define TR_T10MSUS "T10ms\016us"
#define TR_FREESTACKMINB "Free Stack\010b" #define TR_FREESTACKMINB "Free Stack\010b"
+2 -2
View File
@@ -337,9 +337,9 @@
#define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1LATMINUS "Tmr1Lat min\006us"
#define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us"
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define TR_TMAINMAXMS "Tmain max\010ms" #define TR_TMIXMAXMS "Tmix max\012ms"
#else #else
#define TR_TMAINMAXMS "Tmain max\012ms" #define TR_TMIXMAXMS "Tmix max\014ms"
#endif #endif
#define TR_T10MSUS "T10ms\016us" #define TR_T10MSUS "T10ms\016us"
#define TR_FREESTACKMINB "Pila libre\010b" #define TR_FREESTACKMINB "Pila libre\010b"
+2 -2
View File
@@ -343,9 +343,9 @@
#define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1LATMINUS "Tmr1Lat min\006us"
#define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us"
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define TR_TMAINMAXMS "Tmain max\010ms" #define TR_TMIXMAXMS "Tmix max\012ms"
#else #else
#define TR_TMAINMAXMS "Tmain max\012ms" #define TR_TMIXMAXMS "Tmix max\014ms"
#endif #endif
#define TR_T10MSUS "T10ms\016us" #define TR_T10MSUS "T10ms\016us"
#define TR_FREESTACKMINB "Free Stack\010b" #define TR_FREESTACKMINB "Free Stack\010b"
+2 -2
View File
@@ -341,9 +341,9 @@
#define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1LATMINUS "Tmr1Lat min\006us"
#define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us"
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define TR_TMAINMAXMS "Tmain max\004ms" #define TR_TMIXMAXMS "Tmix max\012ms"
#else #else
#define TR_TMAINMAXMS "Tmain max\005ms" #define TR_TMIXMAXMS "Tmix max\014ms"
#endif #endif
#define TR_T10MSUS "T10ms\007us" #define TR_T10MSUS "T10ms\007us"
#define TR_FREESTACKMINB "Free Stack\004b" #define TR_FREESTACKMINB "Free Stack\004b"
+2 -2
View File
@@ -343,9 +343,9 @@
#define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1LATMINUS "Tmr1Lat min\006us"
#define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us"
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define TR_TMAINMAXMS "Tmain max\010ms" #define TR_TMIXMAXMS "Tmix max\012ms"
#else #else
#define TR_TMAINMAXMS "Tmain max\012ms" #define TR_TMIXMAXMS "Tmix max\014ms"
#endif #endif
#define TR_T10MSUS "T10ms\016us" #define TR_T10MSUS "T10ms\016us"
#define TR_FREESTACKMINB "Pilha Livre\010b" #define TR_FREESTACKMINB "Pilha Livre\010b"
+2 -2
View File
@@ -346,9 +346,9 @@
#define TR_TMR1LATMINUS "Tmr1Lat min\006us" #define TR_TMR1LATMINUS "Tmr1Lat min\006us"
#define TR_TMR1JITTERUS "Tmr1 Jitter\006us" #define TR_TMR1JITTERUS "Tmr1 Jitter\006us"
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
#define TR_TMAINMAXMS "Tmain max\010ms" #define TR_TMIXMAXMS "Tmix max\012ms"
#else #else
#define TR_TMAINMAXMS "Tmain max\012ms" #define TR_TMIXMAXMS "Tmix max\014ms"
#endif #endif
#define TR_T10MSUS "T10ms\016us" #define TR_T10MSUS "T10ms\016us"
#define TR_FREESTACKMINB "Free Stack\010b" #define TR_FREESTACKMINB "Free Stack\010b"