From b6e8b73589807cd48c6198f47a2df2657f0219fa Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 14 Mar 2016 18:55:56 +0100 Subject: [PATCH] Sky9x simulator should now be OK --- radio/src/debug.cpp | 12 ++++++---- radio/src/gui/9x/menus.h | 3 ++- radio/src/gui/horus/widgets.cpp | 2 +- radio/src/opentx.cpp | 33 +++++++++++++++----------- radio/src/opentx.h | 7 ++++-- radio/src/targets/simu/simpgmspace.cpp | 32 +++++++++++++------------ radio/src/targets/simu/simpgmspace.h | 2 ++ 7 files changed, 53 insertions(+), 38 deletions(-) diff --git a/radio/src/debug.cpp b/radio/src/debug.cpp index da0e3854c..6ecd3abe4 100644 --- a/radio/src/debug.cpp +++ b/radio/src/debug.cpp @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -19,6 +19,7 @@ */ #include "opentx.h" +#include "stamp.h" #include #if defined(SIMU) @@ -31,7 +32,7 @@ void debugPrintf(const char * format, ...) { va_list arglist; char tmp[PRINTF_BUFFER_SIZE]; - + va_start(arglist, format); vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist); va_end(arglist); @@ -77,7 +78,6 @@ const struct TraceElement * getTraceElement(uint16_t idx) return 0; } -#include "stamp-opentx.h" void dumpTraceBuffer() { @@ -88,13 +88,15 @@ void dumpTraceBuffer() filltm(&traceBuffer[n].time, &tp); TRACE_INFO_WP("%02d ", n); TRACE_INFO_WP("%4d-%02d-%02d,%02d:%02d:%02d.%02d0", tp.tm_year+1900, tp.tm_mon+1, tp.tm_mday, tp.tm_hour, tp.tm_min, tp.tm_sec, traceBuffer[n].time_ms); - TRACE(" %03d 0x%08x", traceBuffer[n].event, traceBuffer[n].data); + TRACE(" %03d 0x%08x", traceBuffer[n].event, traceBuffer[n].data); if (traceBuffer[n].time == 0 && traceBuffer[n].time_ms == 0) break; +#if !defined(SIMU) if ((n % 5) == 0) { - while (!serial2TxFifo.empty()) { + while (!serial2TxFifo.empty()) { CoTickDelay(1); } } +#endif } TRACE("End of Trace Buffer dump"); } diff --git a/radio/src/gui/9x/menus.h b/radio/src/gui/9x/menus.h index af3fd8272..08cfb1016 100644 --- a/radio/src/gui/9x/menus.h +++ b/radio/src/gui/9x/menus.h @@ -82,7 +82,8 @@ void menuTelemetryMavlinkSetup(uint8_t event); void menuCustomFunctions(uint8_t event, CustomFunctionData * functions, CustomFunctionsContext * functionsContext); -enum EnumTabDiag { +enum EnumTabDiag +{ e_Setup, CASE_SDCARD(e_Sd) CASE_CPUARM(e_GeneralCustomFunctions) diff --git a/radio/src/gui/horus/widgets.cpp b/radio/src/gui/horus/widgets.cpp index 5724feb9a..cf4a83c6a 100644 --- a/radio/src/gui/horus/widgets.cpp +++ b/radio/src/gui/horus/widgets.cpp @@ -18,7 +18,7 @@ * GNU General Public License for more details. */ -#include "../../opentx.h" +#include "opentx.h" #include void drawColumnHeader(const char * const * headers, uint8_t index) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index d589ec7fa..2c7a97887 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1983,7 +1983,13 @@ void opentxStart() return; #endif - doSplash(); + bool display_alerts = (g_eeGeneral.chkSum == evalChkSum()); + +#if defined(GUI) + if (display_alerts) { + doSplash(); + } +#endif #if defined(DEBUG_TRACE_BUFFER) trace_event(trace_start, 0x12345678); @@ -1996,12 +2002,11 @@ void opentxStart() #endif #if defined(GUI) - checkAlarm(); - checkAll(); -#endif - -#if defined(GUI) - if (g_eeGeneral.chkSum != evalChkSum()) { + if (display_alerts) { + checkAlarm(); + checkAll(); + } + else { chainMenu(menuFirstCalib); } #endif @@ -2550,6 +2555,13 @@ void opentxInit(OPENTX_INIT_ARGS) TRACE("opentxInit()"); +#if defined(GUI) + menuHandlers[0] = menuMainView; + #if MENUS_LOCK != 2/*no menus*/ + menuHandlers[1] = menuModelSelect; + #endif +#endif + #if defined(RTCLOCK) && !defined(COPROCESSOR) rtcInit(); // RTC must be initialized before rambackupRestore() is called #endif @@ -2654,13 +2666,6 @@ void opentxInit(OPENTX_INIT_ARGS) startPulses(); wdt_enable(WDTO_500MS); - -#if defined(GUI) - menuHandlers[0] = menuMainView; - #if MENUS_LOCK != 2/*no menus*/ - menuHandlers[1] = menuModelSelect; - #endif -#endif } #if defined(SIMU) diff --git a/radio/src/opentx.h b/radio/src/opentx.h index c21dfd7a7..c75e8cca9 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -946,9 +946,12 @@ extern uint16_t lastMixerDuration; #define RESET_THR_TRACE() s_timeCum16ThrP = s_timeCumThr = 0 #endif -#if defined(CPUSTM32) +#if defined(SIMU) + uint16_t getTmr2MHz(); + uint16_t getTmr16KHz(); +#elif defined(CPUSTM32) static inline uint16_t getTmr2MHz() { return TIMER_2MHz_TIMER->CNT; } -#elif defined(CPUARM) +#elif defined(PCBSKY9X) static inline uint16_t getTmr2MHz() { return TC1->TC_CHANNEL[0].TC_CV; } #else uint16_t getTmr16KHz(); diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 7b50dc2df..9a7114179 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -23,9 +23,7 @@ #include #include #include -#if defined(RTCLOCK) - #include -#endif +#include #if defined WIN32 || !defined __GNUC__ #include @@ -96,6 +94,20 @@ void toplcdOff() { } +uint16_t getTmr16KHz() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_usec * 2 / 125; +} + +uint16_t getTmr2MHz() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_usec * 2; +} + void simuInit() { for (int i = 0; i <= 17; i++) { @@ -273,14 +285,9 @@ void simuSetSwitch(uint8_t swtch, int8_t state) } } -uint16_t getTmr16KHz() -{ - return get_tmr10ms() * 160; -} - #if !defined(PCBTARANIS) && !defined(PCBHORUS) bool eeprom_thread_running = true; -void *eeprom_write_function(void *) +void * eeprom_write_function(void *) { while (!sem_wait(eeprom_write_sem)) { if (!eeprom_thread_running) @@ -324,11 +331,6 @@ void *eeprom_write_function(void *) } #endif -#if defined WIN32 || !defined __GNUC__ -#define chdir _chdir -#define getcwd _getcwd -#endif - void StartSimu(bool tests) { s_current_protocol[0] = 255; @@ -1243,7 +1245,7 @@ uint32_t pwrPressed() { return false; } uint32_t pwrCheck() { return true; } #endif -#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) +#if defined(CPUSTM32) void pwrInit() { } void pwrOff() { } int usbPlugged() { return false; } diff --git a/radio/src/targets/simu/simpgmspace.h b/radio/src/targets/simu/simpgmspace.h index b506e83e9..f691feffc 100644 --- a/radio/src/targets/simu/simpgmspace.h +++ b/radio/src/targets/simu/simpgmspace.h @@ -28,6 +28,8 @@ extern int g_snapshot_idx; #define sleep(x) Sleep(x) #define strcasecmp _stricmp #define strncasecmp _tcsnicmp +#define chdir _chdir +#define getcwd _getcwd #else #include #define sleep(x) usleep(1000*x)