diff --git a/src/Makefile b/src/Makefile index 73ff3dad3..b9b84d669 100644 --- a/src/Makefile +++ b/src/Makefile @@ -425,6 +425,7 @@ ifeq ($(PCB), ARM) OPT = 2 CPPDEFS += -DPCBARM -DAUDIO -DHAPTIC -DPXX -DDSM2 -DDSM2_PPM -DROTARY_ENCODERS=1 EXTRAINCDIRS += ersky9x CoOS/kernel CoOS/portable + EXTRAINCDIRS += ../Atmel/sam3s/sam3s-ek/libraries/usb/include/ ../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/ ../Atmel/sam3s/sam3s-ek/libraries/memories/ BOARDSRC = board_ersky9x.cpp SRC += ersky9x/core_cm3.c ersky9x/board_lowlevel.c ersky9x/crt.c ersky9x/vectors_sam3s.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 @@ -444,6 +445,10 @@ ifeq ($(PCB), ARM) CPPSRC += ersky9x/bluetooth.cpp endif + ifeq ($(DEBUG), YES) + CPPSRC += ersky9x/debug.cpp + endif + endif ifeq ($(PCB), V4) @@ -843,7 +848,7 @@ OBJS = $(SRC:.c=.o) @echo @echo $(MSG_COMPILING) $@ $(CC) $(ARMCPPFLAGS) $< -o allsrc.o - $(CC) allsrc.o $(OBJS) -mcpu=cortex-m3 -mthumb -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref,--no-warn-mismatch -o $@ + $(CC) $(OBJS) allsrc.o -mcpu=cortex-m3 -mthumb -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref,--no-warn-mismatch -o $@ else %.elf: allsrc.cpp @echo diff --git a/src/board_ersky9x.cpp b/src/board_ersky9x.cpp index 2a69abb1d..d1c78877f 100644 --- a/src/board_ersky9x.cpp +++ b/src/board_ersky9x.cpp @@ -221,7 +221,14 @@ inline void UART_Configure( uint32_t baudrate, uint32_t masterClock) /* Enable receiver and transmitter */ pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN; + pUart->UART_IER = UART_IER_RXRDY ; + NVIC_EnableIRQ(UART0_IRQn) ; +} +void UART_Stop() +{ + CONSOLE_USART->UART_IDR = UART_IDR_RXRDY ; + NVIC_DisableIRQ(UART0_IRQn) ; } inline void UART3_Configure( uint32_t baudrate, uint32_t masterClock) @@ -258,6 +265,12 @@ inline void UART3_Configure( uint32_t baudrate, uint32_t masterClock) #endif } +void UART3_Stop() +{ + BT_USART->UART_IDR = UART_IDR_RXRDY ; + NVIC_DisableIRQ(UART1_IRQn) ; +} + // USART0 configuration // Work in Progress, UNTESTED // Uses PA5 and PA6 (RXD and TXD) @@ -770,7 +783,7 @@ void board_init() UART_Configure( 9600, Master_frequency ) ; UART2_Configure( 9600, Master_frequency ) ; // Testing - UART3_Configure( 9600, Master_frequency ) ; // Testing + UART3_Configure( 9600, Master_frequency ) ; // TODO not needed, done after ... start_timer2() ; start_timer0() ; @@ -1178,13 +1191,25 @@ void usb_mode() end_ppm_capture() ; end_spi() ; end_sound() ; + TC0->TC_CHANNEL[2].TC_IDR = TC_IDR0_CPCS ; + TC0->TC_CHANNEL[0].TC_CCR = TC_CCR0_CLKDIS ; + TC0->TC_CHANNEL[1].TC_CCR = TC_CCR0_CLKDIS ; + TC0->TC_CHANNEL[2].TC_CCR = TC_CCR0_CLKDIS ; + TC1->TC_CHANNEL[0].TC_CCR = TC_CCR0_CLKDIS ; + TC1->TC_CHANNEL[1].TC_CCR = TC_CCR0_CLKDIS ; + TC1->TC_CHANNEL[2].TC_CCR = TC_CCR0_CLKDIS ; + PWM->PWM_DIS = PWM_DIS_CHID0 | PWM_DIS_CHID1 | PWM_DIS_CHID2 | PWM_DIS_CHID3 ; // Disable all NVIC_DisableIRQ(TC2_IRQn) ; - // PWM->PWM_IDR1 = PWM_IDR1_CHID0 ; + disable_main_ppm() ; // PWM->PWM_IDR1 = PWM_IDR1_CHID3 ; // NVIC_DisableIRQ(PWM_IRQn) ; disable_ssc() ; + + UART_Stop(); + UART3_Stop(); + sam_boot() ; } diff --git a/src/board_ersky9x.h b/src/board_ersky9x.h index bc087294a..2dd456239 100644 --- a/src/board_ersky9x.h +++ b/src/board_ersky9x.h @@ -37,6 +37,7 @@ #include "ersky9x/board.h" #include "ersky9x/sound_driver.h" #include "ersky9x/haptic_driver.h" +#include "ersky9x/debug.h" #if defined(BLUETOOTH) #include "ersky9x/bluetooth.h" diff --git a/src/eeprom_arm.cpp b/src/eeprom_arm.cpp index c90fef6e5..e1713b497 100644 --- a/src/eeprom_arm.cpp +++ b/src/eeprom_arm.cpp @@ -511,6 +511,12 @@ void eeLoadModel(uint8_t id) resetProto(); resetAll(); + for (uint8_t i=0; i + * - 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. + * + */ + +#include "../open9x.h" +#include +#include + +/* + * Outputs a character on the UART line. + * + * This function is synchronous (i.e. uses polling). + * c Character to send. + */ +void debugPutc(const uint8_t c) +{ + Uart *pUart = CONSOLE_USART; + + /* Wait for the transmitter to be ready */ + while ( (pUart->UART_SR & UART_SR_TXEMPTY) == 0 ) ; + + /* Send character */ + pUart->UART_THR = c; +} + +// Outputs a string to the UART +void debugPuts(const char *format, ...) +{ + va_list arglist; + char tmp[256]; + + va_start(arglist, format); + vsnprintf(tmp, 256, format, arglist); + va_end(arglist); + + const char *t = tmp; + while (*t) { + debugPutc(*t++); + } +} + +Fifo32 debugFifo; + +extern "C" void UART0_IRQHandler() +{ + debugFifo.push(CONSOLE_USART->UART_RHR); +} + + +void debugTask(void* pdata) +{ + uint8_t rxchar ; + + for (;;) { + while (!debugFifo.pop(rxchar)) + CoTickDelay(5); // 10ms + + } +} diff --git a/src/ersky9x/debug.h b/src/ersky9x/debug.h new file mode 100644 index 000000000..07b68b79a --- /dev/null +++ b/src/ersky9x/debug.h @@ -0,0 +1,48 @@ +/* + * Authors (alphabetical order) + * - Bertrand Songis + * - 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 debug_h +#define debug_h + +#if defined(DEBUG) +void debugPutc(const uint8_t c); +void debugPuts(const char *string, ...); +void debugTask(void* pdata); +#else +#define debugPutc(...) +#define debugPuts(...) +#define debugTask(...) +#endif + +#endif + diff --git a/src/ersky9x/fifo.h b/src/ersky9x/fifo.h new file mode 100644 index 000000000..841824577 --- /dev/null +++ b/src/ersky9x/fifo.h @@ -0,0 +1,71 @@ +/* + * Authors (alphabetical order) + * - Bertrand Songis + * - 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 fifo_h +#define fifo_h + +class Fifo32 +{ + public: + Fifo32(): + widx(0), + ridx(0) + { + } + + void push(uint8_t byte) { + uint32_t next = (widx+1) & 0x1f; + if (next != ridx) { + fifo[widx] = byte; + widx = next; + } + } + + bool pop(uint8_t & byte) { + if (ridx == widx) { + return false; + } + else { + byte = fifo[ridx]; + ridx = (ridx+1) & 0x1f; + return true; + } + } + + protected: + uint8_t fifo[32]; + volatile uint32_t widx; + volatile uint32_t ridx; +}; + +#endif diff --git a/src/ersky9x/sam3s4c_flash.ld b/src/ersky9x/sam3s4c_flash.ld index 0f350737c..8563d14e6 100644 --- a/src/ersky9x/sam3s4c_flash.ld +++ b/src/ersky9x/sam3s4c_flash.ld @@ -128,9 +128,11 @@ SECTIONS *(.bss.*) . = ALIGN(4); /* Align the end of the section */ + *(.ram.b) + _end = .; + __end = .; } > RAM - _ebss = .; /* Provide the name for the end of this section */ - + _ebss = .; /* Provide the name for the end of this section */ /* * The ".stack" section is our stack. diff --git a/src/ersky9x/vectors_sam3s.c b/src/ersky9x/vectors_sam3s.c index 8afee9c73..8ee89952d 100644 --- a/src/ersky9x/vectors_sam3s.c +++ b/src/ersky9x/vectors_sam3s.c @@ -84,7 +84,7 @@ void DAC_IRQHandler (void) __attribute__((weak)); void PWM_IRQHandler (void) __attribute__((weak)); void CRCCU_IRQHandler (void) __attribute__((weak)); void ACC_IRQHandler (void) __attribute__((weak)); -void USBD_IRQHandler (void) __attribute__((weak)); +extern void USBD_IRQHandler (void);// __attribute__((weak)); /*=========================================================================*/ /* DEFINE: All code exported */ @@ -164,7 +164,7 @@ void RTT_IRQHandler (void) { while(1); } void WDT_IRQHandler (void) { while(1); } void PMC_IRQHandler (void) { while(1); } void EEFC_IRQHandler (void) { while(1); } -void UART0_IRQHandler (void) { while(1); } +//void UART0_IRQHandler (void) { while(1); } void UART1_IRQHandler (void) { while(1); } void SMC_IRQHandler (void) { while(1); } void PIOA_IRQHandler (void) { while(1); } @@ -188,6 +188,6 @@ void ADC_IRQHandler (void) { while(1); } // void PWM_IRQHandler (void) { while(1); } void CRCCU_IRQHandler (void) { while(1); } void ACC_IRQHandler (void) { while(1); } -void USBD_IRQHandler (void) { while(1); } +// void USBD_IRQHandler (void) { while(1); } /*** EOF ***/ diff --git a/src/lcd.cpp b/src/lcd.cpp index 5f461ca4f..7e130a18c 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -476,7 +476,7 @@ void lcd_filled_rect(uint8_t x, int8_t y, uint8_t w, uint8_t h, uint8_t pat, uin } } -void putsTime(uint8_t x,uint8_t y,int16_t tme,uint8_t att,uint8_t att2) +void putsTime(uint8_t x, uint8_t y, putstime_t tme, uint8_t att, uint8_t att2) { div_t qr; @@ -489,6 +489,16 @@ void putsTime(uint8_t x,uint8_t y,int16_t tme,uint8_t att,uint8_t att2) qr = div(tme, 60); +#if defined(PCBARM) + if (tme >= 3600) { + qr = div(qr.quot, 60); + lcd_outdezAtt(x+2*FWNUM, y, qr.quot, att); + lcd_putcAtt(lcdLastPos-((att & DBLSIZE) ? 1 : 0), y, 'h', att&att2); + lcd_outdezNAtt(lcdLastPos+FW, y, qr.rem, att2|LEADING0|LEFT, 2); + return; + } +#endif + lcd_outdezNAtt(x, y, qr.quot, att|LEADING0|LEFT, 2); lcd_putcAtt(lcdLastPos-((att & DBLSIZE) ? 1 : 0), y, ':', att&att2); lcd_outdezNAtt(lcdLastPos+FW, y, qr.rem, att2|LEADING0|LEFT, 2); diff --git a/src/lcd.h b/src/lcd.h index 5ae2b63a9..651106ba8 100644 --- a/src/lcd.h +++ b/src/lcd.h @@ -136,7 +136,14 @@ extern void putsChnLetter(uint8_t x, uint8_t y, uint8_t idx, uint8_t attr); extern void putsVolts(uint8_t x, uint8_t y, uint16_t volts, uint8_t att); extern void putsVBat(uint8_t x, uint8_t y, uint8_t att); -extern void putsTime(uint8_t x,uint8_t y, int16_t tme, uint8_t att, uint8_t att2); + +#if defined(PCBARM) +#define putstime_t int32_t +#else +#define putstime_t int16_t +#endif + +extern void putsTime(uint8_t x,uint8_t y, putstime_t tme, uint8_t att, uint8_t att2); #define SOLID 0xff #define DOTTED 0x55 diff --git a/src/main_views.cpp b/src/main_views.cpp index 71ff17efb..cd2e7888a 100644 --- a/src/main_views.cpp +++ b/src/main_views.cpp @@ -72,6 +72,8 @@ void doMainScreenGrphics() } } +extern char usbState; + void menuMainView(uint8_t event) { uint8_t view = g_eeGeneral.view; @@ -208,6 +210,10 @@ void menuMainView(uint8_t event) if (unexpectedShutdown) { lcd_putcAtt(20*FW-3, 0*FH, '!', INVERS); } +#if defined(PCBARM) + if (usbState >= '0') + lcd_putcAtt(20*FW-3, 0*FH, usbState, INVERS); +#endif if (g_model.timers[0].mode) { uint8_t att = DBLSIZE | (s_timerState[0]==TMR_BEEPING ? BLINK|INVERS : 0); diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 3c9df3861..f0359429b 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -339,6 +339,7 @@ void menuProcModelSelect(uint8_t event) #else if (g_eeGeneral.currModel != sub) { displayPopup(STR_LOADINGMODEL); + saveTimers(); eeCheck(true); // force writing of current model data before this is changed g_eeGeneral.currModel = sub; STORE_GENERALVARS; @@ -468,6 +469,7 @@ void menuProcModelSelect(uint8_t event) REFRESH(true); if (result == STR_SELECT_MODEL || result == STR_CREATE_MODEL) { displayPopup(STR_LOADINGMODEL); + saveTimers(); eeCheck(true); // force writing of current model data before this is changed if (g_eeGeneral.currModel != sub) { g_eeGeneral.currModel = sub; @@ -572,6 +574,12 @@ enum menuProcModelItems { ITEM_MODEL_PROTOCOL_PARAMS }; +#if defined(PCBARM) || defined(PCBV4) +#define FIELD_TIMER_MAX 3 +#else +#define FIELD_TIMER_MAX 2 +#endif + #define MODEL_PARAM_OFS (10*FW+2) void menuProcModel(uint8_t event) { @@ -584,7 +592,7 @@ void menuProcModel(uint8_t event) s_rangecheck_mode = 0; #endif - MENU(STR_MENUSETUP, menuTabModel, e_Model, ((protocol<=PROTO_PPMSIM||IS_DSM2_PROTOCOL(protocol)||IS_PXX_PROTOCOL(protocol)) ? 14 : 13), {0,ZCHAR|(sizeof(g_model.name)-1),2,2,0,0,0,0,0,0,0,NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS-1,1,2}); + MENU(STR_MENUSETUP, menuTabModel, e_Model, ((protocol<=PROTO_PPMSIM||IS_DSM2_PROTOCOL(protocol)||IS_PXX_PROTOCOL(protocol)) ? 14 : 13), {0,ZCHAR|(sizeof(g_model.name)-1),FIELD_TIMER_MAX,FIELD_TIMER_MAX,0,0,0,0,0,0,0,NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS-1,1,2}); uint8_t sub = m_posVert - 1; @@ -612,6 +620,9 @@ void menuProcModel(uint8_t event) putsTime(15*FW, y, timer->val, (attr && m_posHorz==1 ? blink:0), (attr && m_posHorz==2 ? blink:0) ); +#if defined(PCBARM) || defined(PCBV4) + lcd_putcAtt(20*FW+1, y, g_model.timersXtra[k-ITEM_MODEL_TIMER1].remanent ? 'R' : '-', (attr && m_posHorz==3) ? blink : 0); +#endif if (attr && (s_editMode>0 || p1valdiff)) { div_t qr = div(timer->val, 60); switch (m_posHorz) { @@ -619,18 +630,19 @@ void menuProcModel(uint8_t event) CHECK_INCDEC_MODELVAR(event, timer->mode, -2*(MAX_PSWITCH+NUM_CSW), TMR_VAROFS-1+2*(MAX_PSWITCH+NUM_CSW)); break; case 1: - { CHECK_INCDEC_MODELVAR(event, qr.quot, 0, 59); timer->val = qr.rem + qr.quot*60; break; - } case 2: - { qr.rem -= checkIncDecModel(event, qr.rem+2, 1, 62)-2; timer->val -= qr.rem ; if ((int16_t)timer->val < 0) timer->val=0; break; - } +#if defined(PCBARM) || defined(PCBV4) + case 3: + CHECK_INCDEC_MODELVAR(event, g_model.timersXtra[k-ITEM_MODEL_TIMER1].remanent, 0, 1); + break; +#endif } } break; @@ -807,6 +819,7 @@ void menuProcModel(uint8_t event) s_rangecheck_mode = (attr && m_posHorz==1 && s_editMode>0); // [MENU] key toggles range check mode } #endif + if (attr && (m_posHorz==0 && (s_editMode>0 || p1valdiff))) CHECK_INCDEC_MODELVAR(event, g_model.modelId, 0, 99); diff --git a/src/myeeprom.h b/src/myeeprom.h index f70c6f251..5eae6c5cb 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -95,15 +95,16 @@ enum BeeperMode { #define EXTRA_ARM_FIELDS \ uint8_t speakerVolume; \ uint8_t backlightBright; \ - int8_t currentCalib; + int8_t currentCalib #define EXTRA_GENERAL_FIELDS \ int8_t temperatureWarn; \ uint8_t mAhWarn; \ - uint16_t mAhUsed; + uint16_t mAhUsed; \ + uint32_t globalTimer #else #define EXTRA_ARM_FIELDS #define EXTRA_GENERAL_FIELDS \ - int8_t speakerVolume; + int8_t speakerVolume #endif enum AdcInput { @@ -162,11 +163,11 @@ PACK(typedef struct t_EEGeneral { uint8_t unexpectedShutdown:1; uint8_t speakerPitch; - EXTRA_ARM_FIELDS + EXTRA_ARM_FIELDS; uint8_t variants; - EXTRA_GENERAL_FIELDS + EXTRA_GENERAL_FIELDS; }) EEGeneral; @@ -692,6 +693,16 @@ enum Dsm2Variants { #define BeepANACenter uint8_t #endif +#if defined(PCBV4) || defined(PCBARM) +PACK(typedef struct t_TimerDataExtra { + uint16_t remanent:1; + uint16_t value:15; +}) TimerDataExtra; +#define EXTRA_MODEL_FIELDS TimerDataExtra timersXtra[MAX_TIMERS] +#else +#define EXTRA_MODEL_FIELDS +#endif + PACK(typedef struct t_ModelData { char name[10]; // must be first for eeLoadModelName TimerData timers[MAX_TIMERS]; @@ -727,6 +738,8 @@ PACK(typedef struct t_ModelData { TELEMETRY_DATA; ROTARY_ENCODER_ARRAY_EXTRA; + + EXTRA_MODEL_FIELDS; }) ModelData; extern EEGeneral g_eeGeneral; diff --git a/src/open9x.cpp b/src/open9x.cpp index da309ccb6..29fd88645 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -31,11 +31,14 @@ * */ -#if defined(PCBARM) && !defined(SIMU) +#include "open9x.h" + +#if defined(PCBARM) #define MIXER_STACK_SIZE 500 -#define MENUS_STACK_SIZE 1000 +#define MENUS_STACK_SIZE 2000 #define AUDIO_STACK_SIZE 500 -#define BT_STACK_SIZE 100 +#define BT_STACK_SIZE 500 +#define DEBUG_STACK_SIZE 500 OS_TID mixerTaskId; OS_STK mixerStack[MIXER_STACK_SIZE]; @@ -45,20 +48,24 @@ OS_STK menusStack[MENUS_STACK_SIZE]; OS_TID audioTaskId; OS_STK audioStack[AUDIO_STACK_SIZE]; + +#if defined(BLUETOOTH) +OS_TID btTaskId; +OS_STK btStack[BT_STACK_SIZE]; +#endif + +#if defined(DEBUG) +OS_TID debugTaskId; +OS_STK debugStack[DEBUG_STACK_SIZE]; +#endif + OS_TCID audioTimer; OS_FlagID audioFlag; OS_MutexID sdMutex; OS_MutexID audioMutex; OS_MutexID mixerMutex; - -#if defined(BLUETOOTH) -OS_TID btTaskId; -OS_STK btStack[BT_STACK_SIZE]; #endif -#endif - -#include "open9x.h" #if defined(SPLASH) const pm_uchar splashdata[] PROGMEM = { 'S','P','S',0, @@ -446,6 +453,12 @@ void applyExpos(int16_t *anas) } #if !defined(PCBARM) +int16_t calc100toRESX(int8_t x) +{ + // return (int16_t)x*10 + x/4 - x/64; + return ((x*41)>>2) - x/64; +} + int16_t calc1000toRESX(int16_t x) // improve calc time by Pat MacKenzie { // return x + x/32 - x/128 + x/512; @@ -1287,7 +1300,7 @@ uint16_t Current_analogue; uint16_t Current_max; uint32_t Current_accumulator; uint32_t Current_used; -uint16_t MAh_used; +uint16_t sessionTimer; #define NUMBER_ANALOG 9 #else #define NUMBER_ANALOG 8 @@ -1690,10 +1703,6 @@ void testFunc() #ifdef SIMU printf("testFunc\n"); fflush(stdout); #endif - - while(1) { - - } } #endif @@ -2384,7 +2393,7 @@ inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms) #if defined(PPM_LIMITS_SYMETRICAL) if (g_model.limitData[ch].symetrical) val -= calc1000toRESX(g_model.limitData[ch].offset); -#endif +#endif val = val * 10 / (10+(g_model.limitData[ch].max-g_model.limitData[ch].min)/20); val -= RESX; } @@ -2600,6 +2609,7 @@ void perMain() static uint32_t OneSecTimer; if (++OneSecTimer >= 100) { OneSecTimer -= 100 ; + sessionTimer += 1; Current_used += Current_accumulator / 100 ; // milliAmpSeconds (but scaled) Current_accumulator = 0 ; } @@ -2746,7 +2756,7 @@ void perMain() else if (temperature >= g_eeGeneral.temperatureWarn+80) { AUDIO_TX_TEMP_HIGH(); } - else if (g_eeGeneral.mAhWarn && (MAh_used + Current_used * (488 + g_eeGeneral.currentCalib)/8192/36) / 500 >= g_eeGeneral.mAhWarn) { + else if (g_eeGeneral.mAhWarn && (g_eeGeneral.mAhUsed + Current_used * (488 + g_eeGeneral.currentCalib)/8192/36) / 500 >= g_eeGeneral.mAhWarn) { AUDIO_TX_MAH_HIGH(); } #endif @@ -3093,6 +3103,20 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim AUDIO_WARNING2(); } +#if defined(PCBARM) || defined(PCBV4) +void saveTimers() +{ + for (uint8_t i=0; iPWM_CH_NUM[0].PWM_CDTYUPD = g_eeGeneral.backlightBright; - MAh_used = g_eeGeneral.mAhUsed; #endif #if defined(PCBARM) && defined(BLUETOOTH) @@ -3257,56 +3280,60 @@ void mixerTask(void * pdata) } } +#define MASSSTORAGE + #ifdef MASSSTORAGE extern "C" { -#define TRACE_DEBUG(...) -#define TRACE_DEBUG_WP(...) -#define TRACE_INFO(...) -#define TRACE_WARNING(...) -#define TRACE_WARNING_WP(...) -#define TRACE_INFO_WP(...) -#define TRACE_ERROR(...) -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/wdt.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/include/pio.h" -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/include/pio_capture.h" -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/pio_capture.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/pmc.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/pio_it.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/tc.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/memories/include/Media.h" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/include/MSDLun.h" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/include/MSDescriptors.h" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/include/MSD.h" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/include/USBDDriver.h" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/include/MSDDriver.h" -#include "../../Atmel/sam3s/sam3s-ek/examples_usb/usb_massstorage/device_descriptor.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/pio.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/MSDLun.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/MSDDriver.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/core/USBDDriver.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/core/USBD.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/USBD_HAL.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/common/core/USBDescriptors.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/MSDFunction.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/common/core/USBRequests.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/core/USBDDriverCallbacks.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/core/USBDCallbacks.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/MSDDStateMachine.c" -#include "../../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/SBCMethods.c" +#define TRACE_DEBUG(x, ...) debugPuts("-D- " x) +#define TRACE_DEBUG_WP(x, ...) debugPuts(x) +#define TRACE_INFO(x, ...) debugPuts("-I- " x) +#define TRACE_INFO_WP(x, ...) debugPuts(x) +#define TRACE_WARNING(x, ...) debugPuts("-W- " x) +#define TRACE_WARNING_WP(x, ...) debugPuts(x) +#define TRACE_ERROR(x, ...) debugPuts("-W- " x) + +//#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/wdt.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/libboard_sam3s-ek/source/syscalls.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/include/pio.h" +#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/include/pio_capture.h" +#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/pio_capture.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/pmc.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/pio_it.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/tc.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/memories/include/Media.h" +#include "../Atmel/sam3s/sam3s-ek/libraries/memories/Media.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/memories/MEDSdcard.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/include/MSDLun.h" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/include/MSDescriptors.h" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/include/MSD.h" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/include/USBDDriver.h" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/include/MSDDriver.h" +#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/pio.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/MSDLun.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/MSDDriver.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/core/USBDDriver.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/core/USBD.c" +// #include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/core/USBDCallbacks.c" +// #include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/core/USBDDriverCallbacks.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/libchip_sam3s/source/USBD_HAL.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/common/core/USBDescriptors.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/MSDFunction.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/common/core/USBRequests.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/MSDDStateMachine.c" +#include "../Atmel/sam3s/sam3s-ek/libraries/usb/device/massstorage/SBCMethods.c" + +#include "../Atmel/sam3s/sam3s-ek/examples_usb/usb_massstorage/device_descriptor.c" /*---------------------------------------------------------------------------- * Local definitions *----------------------------------------------------------------------------*/ /** Maximum number of LUNs which can be defined. */ -#define MAX_LUNS 2 +#define MAX_LUNS 1 /** Media index for different disks */ -#define DRV_RAMDISK 0 /** RAM disk */ -#define DRV_IFLASH 0 /** Internal flash */ #define DRV_SDMMC 0 /** SD card */ -#define DRV_NAND 1 /** Nand flash */ /** Delay for pushbutton debouncing (ms) */ #define DEBOUNCE_TIME 10 @@ -3340,7 +3367,7 @@ extern "C" { *----------------------------------------------------------------------------*/ /** MSD Driver Descriptors List */ -//extern const USBDDriverDescriptors msdDriverDescriptors; +extern const USBDDriverDescriptors msdDriverDescriptors; /** Available medias. */ Media medias[MAX_LUNS]; @@ -3382,12 +3409,6 @@ static const Pin nfCePin = BOARD_NF_CE_PIN; /** Nandflash ready/busy pin. */ static const Pin nfRbPin = BOARD_NF_RB_PIN; -/*---------------------------------------------------------------------------- - * VBus monitoring (optional) - *----------------------------------------------------------------------------*/ - -/** VBus pin instance. */ -static const Pin pinVbus = PIN_USB_VBUS; static void _ConfigureUsbClock(void) { @@ -3421,95 +3442,81 @@ static void _ConfigureTc0(void) TC_Start(TC0, 0); } + +/*----------------------------------------------------------------------------- + * Callback re-implementation + *-----------------------------------------------------------------------------*/ + /** - * Initialize Nand Flash for LUN + * Invoked after the USB driver has been initialized. By default, configures + * the UDP/UDPHS interrupt. */ -static void NandFlashInitialize(void) +void USBDCallbacks_Initialized(void) { - unsigned char nfRc; - unsigned short nfBaseBlock = 0; - struct RawNandFlash *pRaw = (struct RawNandFlash*)&translatedNf; - struct NandFlashModel *pModel = (struct NandFlashModel*)&translatedNf; - unsigned int nfMamagedSize; + TRACE_INFO("USBDCallbacks_Initialized\n\r"); + NVIC_EnableIRQ(UDP_IRQn); +} - /* Configure SMC for NandFlash (8-bit) */ - BOARD_ConfigureNandFlash(SMC); - /* Configure PIO for Nand Flash */ - PIO_Configure(pPinsNf, PIO_LISTSIZE(pPinsNf)); +/** + * Invoked when a new SETUP request is received from the host. Forwards the + * request to the Mass Storage device driver handler function. + * \param request Pointer to a USBGenericRequest instance. + */ +void USBDCallbacks_RequestReceived(const USBGenericRequest *request) +{ + TRACE_INFO("USBDCallbacks_RequestReceived\n\r"); + MSDDriver_RequestHandler(request); +} - /* Nand Flash Initialize (ALL flash mapped) */ - nfRc = RawNandFlash_Initialize(pRaw, - 0, - cmdBytesAddr, - addrBytesAddr, - dataBytesAddr, - nfCePin, - nfRbPin); - if (nfRc) { - printf("Nand not found\n\r"); - return; +/** + * Invoked when the configuration of the device changes. Resets the mass + * storage driver. + * \param cfgnum New configuration number. + */ +void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum) +{ + TRACE_INFO("USBDDriverCallbacks_ConfigurationChanged\n\r"); + MSDDriver_ConfigurationChangeHandler(cfgnum); +} + +void USBDDriverCallbacks_InterfaceSettingChanged( + uint8_t interface, + uint8_t setting) +{ + TRACE_INFO("USBDDriverCallbacks_InterfaceSettingChanged\n\r"); +} + +void USBDCallbacks_Suspended(void) +{ + TRACE_INFO("USBDCallbacks_Suspended"); +} + +void USBDCallbacks_Resumed(void) +{ + TRACE_INFO("USBDCallbacks_Resumed"); +} + +void USBDCallbacks_Reset(void) +{ + TRACE_INFO("USBDCallbacks_Reset"); +} + +void MSDCallbacks_Data(uint8_t flowDirection, + uint32_t dataLength, + uint32_t fifoNullCount, + uint32_t fifoFullCount) +{ + if (flowDirection) { + + msdReadTotal += dataLength; } else { - printf("NF\tNb Blocks %d\n\r", - NandFlashModel_GetDeviceSizeInBlocks(pModel)); - printf("\tBlock Size %dK\n\r", - NandFlashModel_GetBlockSizeInBytes(pModel)/1024); - printf("\tPage Size %d\n\r", - NandFlashModel_GetPageDataSize(pModel)); - nfBaseBlock = - NF_RESERVE_SIZE / NandFlashModel_GetBlockSizeInBytes(pModel); - } - printf("NF disk will use area from %dM(B%d)\n\r", - NF_RESERVE_SIZE/1024/1024, nfBaseBlock); - printf("!! Erase the NF Disk? (y/n):"); - updateDelay = INPUT_DELAY; - updateView = 0; - while(1) { - if(UART_IsRxReady()) { - char key = UART_GetChar(); - UART_PutChar(key); - if (key == 'y') { - if (nfRc == 0) { - unsigned int block; - printf(" Erase from %d ... ", nfBaseBlock); - for (block = nfBaseBlock; - block < NandFlashModel_GetDeviceSizeInBlocks(pModel); - block ++) { - RawNandFlash_EraseBlock(pRaw, block); - } - printf("OK"); - } - } - printf("\n\r"); - break; - } - if (updateView) { - printf("No\n\r"); - break; - } - } - nfMamagedSize = ((NandFlashModel_GetDeviceSizeInMBytes(pModel) - NF_RESERVE_SIZE/1024/1024) > NF_MANAGED_SIZE/1024/1024) ? \ - NF_MANAGED_SIZE/1024/1024 : (NandFlashModel_GetDeviceSizeInMBytes(pModel) - NF_RESERVE_SIZE/1024/1024); - if (TranslatedNandFlash_Initialize(&translatedNf, - 0, - cmdBytesAddr, - addrBytesAddr, - dataBytesAddr, - nfCePin, - nfRbPin, - nfBaseBlock, nfMamagedSize * 1024 * 1024/NandFlashModel_GetBlockSizeInBytes(pModel))) { - // printf("Nand init error\n\r"); - return; + + msdWriteTotal += dataLength; } - /* Media initialize */ - MEDNandFlash_Initialize(&medias[DRV_NAND], &translatedNf); - - /* Initialize LUN */ - LUN_Init(&(luns[DRV_NAND]), &(medias[DRV_NAND]), - msdBuffer, MSD_BUFFER_SIZE, - 0, 0, 0, 0, - MSDCallbacks_Data); + msdFullCnt += fifoFullCount; + msdNullCnt += fifoNullCount; } /** @@ -3519,93 +3526,70 @@ static void MemoryInitialization(void) { uint32_t i; for (i = 0; i < MAX_LUNS; i ++) - LUN_Init(&luns[i], 0, 0, 0, 0, 0, 0, 0, 0); + LUN_Init(&luns[i], 0, 0, 0, 0, 0, 0, 0, 0); - // TODO: Add LUN Init here - - /* Nand Flash Init */ - NandFlashInitialize(); -} - -static void ISR_Vbus(const Pin *pPin) -{ - /* Check current level on VBus */ - if (PIO_Get(&pinVbus)) { - - TRACE_INFO("VBUS conn\n\r"); - USBD_Connect(); + unsigned char rc; + if (1) { + // Blocked SD access function + rc = MEDSdcard_Initialize(&(medias[DRV_SDMMC]), 0); + if(1) { + LUN_Init(&(luns[DRV_SDMMC]), &(medias[DRV_SDMMC]), + msdBuffer, MSD_BUFFER_SIZE, + 0, 0, 0, 0, + MSDCallbacks_Data); + } } else { - - TRACE_INFO("VBUS discon\n\r"); - USBD_Disconnect(); - } -} - -static void VBus_Configure( void ) -{ - TRACE_INFO("VBus configuration\n\r"); - - /* Configure PIO */ - PIO_Configure(&pinVbus, 1); - PIO_ConfigureIt(&pinVbus, ISR_Vbus); - PIO_EnableIt(&pinVbus); - - /* Check current level on VBus */ - if (PIO_Get(&pinVbus)) { - lcd_putcAtt( 48, 24, 'O', DBLSIZE ) ; - lcd_putcAtt( 60, 24, 'K', DBLSIZE ) ; - refreshDisplay() ; - - /* if VBUS present, force the connect */ - TRACE_INFO("conn\n\r"); - USBD_Connect(); - } - else { - lcd_putcAtt( 48, 24, 'K', DBLSIZE ) ; - lcd_putcAtt( 60, 24, 'O', DBLSIZE ) ; - refreshDisplay() ; - USBD_Disconnect(); + LUN_Eject(&luns[DRV_SDMMC]); } } +char usbState; void usbMassStorage() { - /* Disable watchdog */ - WDT_Disable( WDT ) ; + static bool initialized = false; - /* If they are present, configure Vbus & Wake-up pins */ - PIO_InitializeInterrupts(0); + if (!initialized) { + /* Disable watchdog */ + // WDT_Disable( WDT ) ; - /* Enable UPLL for USB */ - _ConfigureUsbClock(); + /* If they are present, configure Vbus & Wake-up pins */ + // PIO_InitializeInterrupts(0); - /* Start TC for timing & status update */ - _ConfigureTc0(); + /* Enable UPLL for USB */ + _ConfigureUsbClock(); - /* Initialize memories and LUN */ - MemoryInitialization(); + /* Start TC for timing & status update */ + _ConfigureTc0(); - /* BOT driver initialization */ - MSDDriver_Initialize(&msdDriverDescriptors, - luns, MAX_LUNS); + /* Initialize memories and LUN */ + MemoryInitialization(); - /* connect if needed */ - VBus_Configure(); + /* BOT driver initialization */ + MSDDriver_Initialize(&msdDriverDescriptors, + luns, MAX_LUNS); - /* Infinite loop */ - updateDelay = UPDATE_DELAY; - updateView = 0; - while (1) { + /* connect if needed */ + USBD_Connect(); - /* Mass storage state machine */ - if (USBD_GetState() < USBD_STATE_CONFIGURED) { - } - else { - MSDDriver_StateMachine(); - } + /* Infinite loop */ + updateDelay = UPDATE_DELAY; + updateView = 0; + initialized = true; + } + + // while (1) { + + usbState = '0' + USBD_GetState(); + + /* Mass storage state machine */ + if (USBD_GetState() >= USBD_STATE_CONFIGURED) { + + MSDDriver_StateMachine(); + } +#if 0 /* Update status view */ if (updateView) { @@ -3626,54 +3610,23 @@ void usbMassStorage() msdNullCnt = 0; msdFullCnt = 0; } - } -} +#endif +// } } +} // extern "C" #endif void menusTask(void * pdata) { - register uint32_t shutdown_state = 0; -#ifdef MASSSTORAGE - uint8_t mass_storage = false; -#endif - open9xInit(); - while (1) { - shutdown_state = check_soft_power(); + while (check_soft_power() != e_power_off) { #ifdef MASSSTORAGE - if (shutdown_state == e_power_off) { - break; - } - else if (shutdown_state == e_power_usb) { - const char STR_SDCARD[] = "Massstorage"; // TODO translations - const char STR_BOOTLOADER[] = "Bootloader"; - lcd_clear(); - s_menu_count = 0; - s_menu[s_menu_count++] = STR_SDCARD; - s_menu[s_menu_count++] = STR_BOOTLOADER; - uint8_t event = getEvent(false); - const char * result = displayMenu(event); - if (result) { - if (result == STR_BOOTLOADER) - break; - else { - mass_storage = true; - break; - s_menu_count = 0; - } - } - refreshDisplay(); - } -#else - if (shutdown_state >= e_power_usb) { - break; + if (PIOC->PIO_PDSR & PIO_PC25) { + usbMassStorage(); } #endif - else { - perMain(); - } + perMain(); CoTickDelay(5); // 10ms for now } @@ -3687,56 +3640,27 @@ void menusTask(void * pdata) hapticOff(); #endif - lcd_clear() ; + lcd_clear(); - if (shutdown_state != e_power_usb) { - displayPopup(STR_SHUTDOWN); + displayPopup(STR_SHUTDOWN); + saveTimers(); - MAh_used += Current_used * (488 + g_eeGeneral.currentCalib) / 8192 / 36; - if (g_eeGeneral.mAhUsed != MAh_used) { - g_eeGeneral.mAhUsed = MAh_used; - STORE_GENERALVARS; - } + uint32_t mAhUsed = g_eeGeneral.mAhUsed + Current_used * (488 + g_eeGeneral.currentCalib) / 8192 / 36; + if (g_eeGeneral.mAhUsed != mAhUsed) + g_eeGeneral.mAhUsed = mAhUsed; + if (sessionTimer > 0) + g_eeGeneral.globalTimer += sessionTimer; + g_eeGeneral.unexpectedShutdown = 0; - g_eeGeneral.unexpectedShutdown = 0; + eeDirty(EE_GENERAL); + eeCheck(true); - eeDirty(EE_GENERAL); - eeCheck(true); - } + lcd_clear(); + refreshDisplay(); + lcdSetRefVolt(0); - soft_power_off(); // Only turn power off if necessary - - if (shutdown_state == e_power_usb) { - lcd_putcAtt( 48, 24, 'U', DBLSIZE ) ; - lcd_putcAtt( 60, 24, 'S', DBLSIZE ) ; - lcd_putcAtt( 72, 24, 'B', DBLSIZE ) ; - refreshDisplay() ; -#ifdef MASSSTORAGE - if (mass_storage) { - stop_rotary_encoder(); - endPdcUsartReceive() ; // Terminate any serial reception - end_bt_tx_interrupt() ; - end_ppm_capture() ; - end_spi() ; - end_sound() ; - TC0->TC_CHANNEL[2].TC_IDR = TC_IDR0_CPCS ; - NVIC_DisableIRQ(TC2_IRQn) ; - // PWM->PWM_IDR1 = PWM_IDR1_CHID0 ; - disable_main_ppm() ; - // PWM->PWM_IDR1 = PWM_IDR1_CHID3 ; - // NVIC_DisableIRQ(PWM_IRQn) ; - disable_ssc() ; - usbMassStorage(); - } - else -#endif - { - usb_mode(); - } - } - - lcdSetRefVolt(0); // TODO before soft_power_off? + soft_power_off(); // Only turn power off if necessary } extern void audioTimerHandle(void); @@ -3821,11 +3745,37 @@ int main(void) #endif #if defined(PCBARM) + if (check_soft_power() == e_power_usb) { + soft_power_off(); // Only turn power off if necessary + +#if defined(HAPTIC) + hapticOff(); +#endif + + BACKLIGHT_ON; + + g_eeGeneral.contrast = 25; + + lcd_clear(); + + lcd_putcAtt( 48, 24, 'U', DBLSIZE ) ; + lcd_putcAtt( 60, 24, 'S', DBLSIZE ) ; + lcd_putcAtt( 72, 24, 'B', DBLSIZE ) ; + refreshDisplay() ; + + usb_mode(); + } + CoInitOS(); -#if defined(BLUETOOTH) - btTaskId = CoCreateTask(btTask, NULL, 19, &btStack[BT_STACK_SIZE-1], BT_STACK_SIZE); +#if defined(DEBUG) + debugTaskId = CoCreateTaskEx(debugTask, NULL, 10, &debugStack[DEBUG_STACK_SIZE-1], DEBUG_STACK_SIZE, 1, false); #endif + +#if defined(BLUETOOTH) + btTaskId = CoCreateTask(btTask, NULL, 15, &btStack[BT_STACK_SIZE-1], BT_STACK_SIZE); +#endif + mixerTaskId = CoCreateTask(mixerTask, NULL, 5, &mixerStack[MIXER_STACK_SIZE-1], MIXER_STACK_SIZE); menusTaskId = CoCreateTask(menusTask, NULL, 10, &menusStack[MENUS_STACK_SIZE-1], MENUS_STACK_SIZE); @@ -3871,6 +3821,7 @@ int main(void) // Time to switch off lcd_clear() ; displayPopup(STR_SHUTDOWN); + saveTimers(); g_eeGeneral.unexpectedShutdown=0; eeDirty(EE_GENERAL); eeCheck(true); diff --git a/src/open9x.h b/src/open9x.h index 3fab6468b..847b226f5 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -59,7 +59,7 @@ extern uint16_t Current_analogue; extern uint16_t Current_max; extern uint32_t Current_accumulator; extern uint32_t Current_used; -extern uint16_t MAh_used; +extern uint16_t sessionTimer; #endif #if defined(SIMU) @@ -133,8 +133,10 @@ extern uint8_t s_bind_allowed; #if !defined(SIMU) #define assert(x) +#if !defined(PCBARM) || !defined(DEBUG) #define printf printf_not_allowed #endif +#endif // G: The following comments relate to the original stock PCB only // @@ -799,8 +801,12 @@ inline void resumeMixerCalculations() #define resumeMixerCalculations() #endif -/// Markiert einen EEPROM-Bereich als dirty. der Bereich wird dann in -/// eeCheck ins EEPROM zurueckgeschrieben. +#if defined(PCBARM) || defined(PCBV4) +void saveTimers(); +#else +#define saveTimers() +#endif + void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_t size); void eeDirty(uint8_t msk); void eeCheck(bool immediately=false); @@ -828,16 +834,12 @@ inline int16_t calc1000toRESX( register int32_t x) // improve calc time by Pat // return x + x/32 - x/128 + x/512; } #else -inline int16_t calc100toRESX(int8_t x) -{ - // return (int16_t)x*10 + x/4 - x/64; - return ((x*41)>>2) - x/64; -} - +extern int16_t calc100toRESX(int8_t x); extern int16_t calc1000toRESX(int16_t x); #endif // *1000/1024 = x - x/32 + x/128 +// TODO flash saving? #define GPERC(x) (x - x/32 + x/128) #if defined(PCBARM) diff --git a/src/simpgmspace.h b/src/simpgmspace.h index 3cc849383..3ff5463ae 100644 --- a/src/simpgmspace.h +++ b/src/simpgmspace.h @@ -297,6 +297,8 @@ void eeprom_read_block (void *pointer_ram, #define OS_MutexID int #define OS_FlagID int +#define OS_TID int +#define OS_STK char #define E_OK 0 diff --git a/src/statistics_views.cpp b/src/statistics_views.cpp index 5d138b6da..3332dc246 100644 --- a/src/statistics_views.cpp +++ b/src/statistics_views.cpp @@ -91,8 +91,11 @@ void menuProcDebug(uint8_t event) { #if defined(PCBARM) case EVT_KEY_LONG(KEY_MENU): - MAh_used = 0; + g_eeGeneral.mAhUsed = 0; + g_eeGeneral.globalTimer = 0; + eeDirty(EE_GENERAL); Current_used = 0; + sessionTimer = 0; killEvents(event); AUDIO_KEYPAD_UP(); break; @@ -138,7 +141,8 @@ void menuProcDebug(uint8_t event) uint32_t current_scale = 488 + g_eeGeneral.currentCalib; putsTelemetryValue(20*FW+2, 2*FH, Current_max*10*current_scale/8192, UNIT_RAW, 0); lcd_putsLeft(3*FH, STR_CPU_MAH); - putsTelemetryValue(MENU_DEBUG_COL_OFS, 3*FH, MAh_used + Current_used*current_scale/8192/36, UNIT_MAH, PREC1); + putsTelemetryValue(MENU_DEBUG_COL_OFS, 3*FH, g_eeGeneral.mAhUsed + Current_used*current_scale/8192/36, UNIT_MAH, PREC1); + putsTime(17*FW, 3*FH, g_eeGeneral.globalTimer + sessionTimer, 0, 0); #endif lcd_putsLeft(4*FH, STR_CPU_TEMP); diff --git a/src/translations/en.h b/src/translations/en.h index 9563d16f5..73d27a266 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -418,7 +418,7 @@ #define TR_SELECT_MODEL "Select Model" #define TR_CREATE_MODEL "Create Model" #define TR_BACKUP_MODEL "Backup Model" -#define TR_DELETE_MODEL "Delete Model" // TODO merged into DELETEMODEL? +#define TR_DELETE_MODEL "Delete Model" #define TR_RESTORE_MODEL "Restore Model" #define TR_SDCARD_ERROR "SDCARD Error" #define TR_NO_SDCARD "No SDCARD"