From 43ccaa60e6194f118d4a1b42e16f59734f84c5e7 Mon Sep 17 00:00:00 2001 From: bsongis Date: Fri, 16 Dec 2011 19:06:28 +0000 Subject: [PATCH] Now it compiles without a warning under Visual C++ ... Why? Only because I wanted to have exceptions catched under Windows as we have on Linux. Most users are Windows. They will be all testers :) --- src/file.cpp | 12 +++---- src/gruvin9x.cpp | 5 ++- src/gruvin9x.h | 14 +++++--- src/main_views.cpp | 19 +++++------ src/menus.h | 8 ++--- src/model_menus.cpp | 12 +++---- src/myeeprom.h | 81 ++++++++++++++++++++++++--------------------- src/pulses.cpp | 2 +- src/simpgmspace.cpp | 15 ++++++--- src/simpgmspace.h | 2 +- 10 files changed, 93 insertions(+), 77 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 8c78888e4..375bbbb7b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -32,19 +32,19 @@ uint8_t s_sync_write = false; #define BLOCKS (EESIZE/BS) #define EEFS_VERS 4 -struct DirEnt{ +PACK(struct DirEnt{ uint8_t startBlk; uint16_t size:12; uint16_t typ:4; -}__attribute__((packed)); +}); #define MAXFILES (1+MAX_MODELS+3) -struct EeFs{ +PACK(struct EeFs{ uint8_t version; uint8_t mySize; uint8_t freeList; uint8_t bs; DirEnt files[MAXFILES]; -}__attribute__((packed)) eeFs; +}) eeFs; static uint8_t EeFsRead(uint8_t blk, uint8_t ofs) @@ -163,10 +163,6 @@ void EeFsFormat() { s_sync_write = true; - if (sizeof(eeFs) != RESV){ - extern void eeprom_RESV_mismatch(); - eeprom_RESV_mismatch(); - } memset(&eeFs,0, sizeof(eeFs)); eeFs.version = EEFS_VERS; eeFs.mySize = sizeof(eeFs); diff --git a/src/gruvin9x.cpp b/src/gruvin9x.cpp index 7690a21b2..843473413 100644 --- a/src/gruvin9x.cpp +++ b/src/gruvin9x.cpp @@ -290,7 +290,7 @@ void applyExpos(int16_t *anas, uint8_t phase) } bool s_noStickInputs = false; -inline int16_t __attribute__ ((always_inline)) getValue(uint8_t i) +FORCEINLINE int16_t getValue(uint8_t i) { if(i inline t __attribute__ ((always_inline)) abs(t a){ return a>0?a:-a; } +template FORCEINLINE t abs(t a){ return a>0?a:-a; } /// liefert das Minimum der Argumente -template inline t __attribute__ ((always_inline)) min(t a, t b){ return a FORCEINLINE t min(t a, t b){ return a inline t __attribute__ ((always_inline)) max(t a, t b){ return a>b?a:b; } -template inline int8_t __attribute__ ((always_inline)) sgn(t a){ return a>0 ? 1 : (a < 0 ? -1 : 0); } -template inline t __attribute__ ((always_inline)) limit(t mi, t x, t ma){ return min(max(mi,x),ma); } +template FORCEINLINE t max(t a, t b){ return a>b?a:b; } +template FORCEINLINE t sgn(t a){ return a>0 ? 1 : (a < 0 ? -1 : 0); } +template FORCEINLINE t limit(t mi, t x, t ma){ return min(max(mi,x),ma); } /// Markiert einen EEPROM-Bereich als dirty. der Bereich wird dann in /// eeCheck ins EEPROM zurueckgeschrieben. diff --git a/src/main_views.cpp b/src/main_views.cpp index ec401adaa..fa27c1d13 100644 --- a/src/main_views.cpp +++ b/src/main_views.cpp @@ -21,8 +21,7 @@ #include "menus.h" -#undef ALTERNATE -#define ALTERNATE 0x10 +#define ALTERNATE_VIEW 0x10 enum MainViews { e_outputValues, @@ -90,7 +89,7 @@ void menuMainView(uint8_t event) #ifdef FRSKY bool telemViewSw = isFunctionActive(FUNC_VIEW_TELEMETRY); - if (switchView == 255 && telemViewSw) { view = switchView = e_telemetry + ALTERNATE; } + if (switchView == 255 && telemViewSw) { view = switchView = e_telemetry + ALTERNATE_VIEW; } if (switchView != 255 && !telemViewSw) { view = g_eeGeneral.view; switchView = 255; } #endif @@ -111,7 +110,7 @@ void menuMainView(uint8_t event) case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_BREAK(KEY_LEFT): if (switchView != 255) break; - g_eeGeneral.view = (view + (event == EVT_KEY_BREAK(KEY_RIGHT) ? ALTERNATE : tabViews[view_base]*ALTERNATE-ALTERNATE)) % (tabViews[view_base]*ALTERNATE); + g_eeGeneral.view = (view + (event == EVT_KEY_BREAK(KEY_RIGHT) ? ALTERNATE_VIEW : tabViews[view_base]*ALTERNATE_VIEW-ALTERNATE_VIEW)) % (tabViews[view_base]*ALTERNATE_VIEW); eeDirty(EE_GENERAL); beepKey(); break; @@ -197,7 +196,7 @@ void menuMainView(uint8_t event) trim2OfsSwLock = trimSw; #ifdef FRSKY - if (view_base == e_telemetry && view > ALTERNATE) { + if (view_base == e_telemetry && view > ALTERNATE_VIEW) { putsModelName(0, 0, g_model.name, g_eeGeneral.currModel, 0); uint8_t att = (g_vbat100mV < g_eeGeneral.vBatWarn ? BLINK : 0); putsVBat(14*FW,0,att); @@ -323,7 +322,7 @@ void menuMainView(uint8_t event) } } displayCount = (displayCount+1) % 50; - if (view == e_telemetry+ALTERNATE) { + if (view == e_telemetry+ALTERNATE_VIEW) { if (g_model.frsky.channels[0].ratio || g_model.frsky.channels[1].ratio) { x0 = 0; for (int i=0; i<2; i++) { @@ -388,7 +387,7 @@ void menuMainView(uint8_t event) lcd_outdezAtt(17 * FW - 2, 7*FH, frskyRSSI[1].max, LEFT); } #ifdef FRSKY_HUB - else if (g_eeGeneral.view == e_telemetry+2*ALTERNATE) { // if on second alternate telemetry view + else if (g_eeGeneral.view == e_telemetry+2*ALTERNATE_VIEW) { // if on second alternate telemetry view // Date lcd_outdezNAtt(1*FW, 1*FH, frskyHubData.year+2000, LEFT, 4); lcd_putc(lcd_lastPos, 1*FH, '-'); @@ -441,7 +440,7 @@ void menuMainView(uint8_t event) lcd_outdezAtt(lcd_lastPos+2, 7*FH, frskyHubData.gpsAltitude_ap, LEFT|UNSIGN); // after '.' lcd_putc(lcd_lastPos, 7*FH, 'm'); } - else if (g_eeGeneral.view == e_telemetry+3*ALTERNATE) { // if on second alternate telemetry view + else if (g_eeGeneral.view == e_telemetry+3*ALTERNATE_VIEW) { // if on second alternate telemetry view uint8_t y = 2*FH; @@ -527,8 +526,8 @@ void menuMainView(uint8_t event) #endif else if (view_base= s_maxLines-1) m_posVert = s_maxLines-1; - displayWarning(__event); + displayWarning(_event_); } void menuProcExposAll(uint8_t event) diff --git a/src/myeeprom.h b/src/myeeprom.h index 2637e6d1f..0182286a0 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -43,23 +43,27 @@ #define EEPROM_VER_r751 5 #define EEPROM_VER 201 -typedef struct t_TrainerMix { +#ifndef PACK +#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) +#endif + +PACK(typedef struct t_TrainerMix { uint8_t srcChn:6; // 0-7 = ch1-8 uint8_t mode:2; // off,add-mode,subst-mode int8_t studWeight; -} __attribute__((packed)) TrainerMix; // +}) TrainerMix; // -typedef struct t_TrainerData { +PACK(typedef struct t_TrainerData { int16_t calib[4]; TrainerMix mix[4]; -} __attribute__((packed)) TrainerData; +}) TrainerData; -typedef struct t_FrSkyRSSIAlarm { +PACK(typedef struct t_FrSkyRSSIAlarm { uint8_t level:2; int8_t value:6; -} __attribute__((packed)) FrSkyRSSIAlarm; +}) FrSkyRSSIAlarm; -typedef struct t_EEGeneral { +PACK(typedef struct t_EEGeneral { uint8_t myVers; int16_t calibMid[7]; int16_t calibSpanNeg[7]; @@ -91,11 +95,11 @@ typedef struct t_EEGeneral { uint8_t templateSetup; //RETA order according to chout_ar array int8_t PPM_Multiplier; FrSkyRSSIAlarm frskyRssiAlarms[2]; -} __attribute__((packed)) EEGeneral; +}) EEGeneral; // eeprom modelspec -typedef struct t_ExpoData { +PACK(typedef struct t_ExpoData { uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both uint8_t chn:2; uint8_t curve:4; // 0=no curve, 1-6=std curves, 7-10=CV1-CV4, 11-15=CV9-CV13 @@ -104,18 +108,15 @@ typedef struct t_ExpoData { uint8_t negPhase:1; uint8_t weight:7; int8_t expo; -} __attribute__((packed)) ExpoData; +}) ExpoData; -typedef struct t_LimitData { +PACK(typedef struct t_LimitData { int8_t min; int8_t max; bool revert; int16_t offset; -} __attribute__((packed)) LimitData; +}) LimitData; -typedef struct t_MixData { - uint8_t destCh:5; // 0, 1..NUM_CHNOUT - uint8_t mixWarn:3; // mixer warning #define MIX_P1 5 #define MIX_P2 6 #define MIX_P3 7 @@ -124,6 +125,14 @@ typedef struct t_MixData { #define MIX_CYC1 10 #define MIX_CYC2 11 #define MIX_CYC3 12 + +#define MLTPX_ADD 0 +#define MLTPX_MUL 1 +#define MLTPX_REP 2 + +PACK(typedef struct t_MixData { + uint8_t destCh:5; // 0, 1..NUM_CHNOUT + uint8_t mixWarn:3; // mixer warning uint8_t srcRaw; // int8_t weight; int8_t swtch; @@ -133,24 +142,21 @@ typedef struct t_MixData { uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) uint8_t speedDown:4; // 0 nichts uint8_t carryTrim:1; -#define MLTPX_ADD 0 -#define MLTPX_MUL 1 -#define MLTPX_REP 2 uint8_t mltpx:3; // multiplex method 0=+ 1=* 2=replace int8_t phase:4; // -5=!FP4, 0=normal, 5=FP4 int8_t sOffset; -} __attribute__((packed)) MixData; +}) MixData; -typedef struct t_CustomSwData { // Custom Switches data +PACK(typedef struct t_CustomSwData { // Custom Switches data int8_t v1; //input int8_t v2; //offset uint8_t func; -} __attribute__((packed)) CustomSwData; +}) CustomSwData; -typedef struct t_SafetySwData { // Safety Switches data +PACK(typedef struct t_SafetySwData { // Safety Switches data int8_t swtch; int8_t val; -} __attribute__((packed)) SafetySwData; +}) SafetySwData; #define FUNC_TRAINER 1 #define FUNC_TRAINER_RUD 2 @@ -162,12 +168,12 @@ typedef struct t_SafetySwData { // Safety Switches data #define FUNC_VIEW_TELEMETRY 8 #define FUNC_LAST 8 -typedef struct t_FuncSwData { // Function Switches data +PACK(typedef struct t_FuncSwData { // Function Switches data int8_t swtch; //input uint8_t func; -} __attribute__((packed)) FuncSwData; +}) FuncSwData; -typedef struct t_FrSkyChannelData { +PACK(typedef struct t_FrSkyChannelData { uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. uint8_t type:4; // channel unit (0=volts, ...) int8_t offset:4; // calibration offset. Signed 0.1V steps. EG. -4 to substract 0.4V @@ -177,13 +183,13 @@ typedef struct t_FrSkyChannelData { uint8_t spare:2; int8_t barMin; // minimum for bar display uint8_t barMax; // ditto for max display (would usually = ratio) -} __attribute__((packed)) FrSkyChannelData; +}) FrSkyChannelData; -typedef struct t_FrSkyData { +PACK(typedef struct t_FrSkyData { FrSkyChannelData channels[2]; -} __attribute__((packed)) FrSkyData; +}) FrSkyData; -typedef struct t_SwashRingData { // Swash Ring data +PACK(typedef struct t_SwashRingData { // Swash Ring data uint8_t invertELE:1; uint8_t invertAIL:1; uint8_t invertCOL:1; @@ -195,20 +201,21 @@ typedef struct t_SwashRingData { // Swash Ring data uint8_t lim; // 0 mean off 100 full deflection uint8_t chX; // 2 channels to limit uint8_t chY; // 2 channels to limit */ -} __attribute__((packed)) SwashRingData; +}) SwashRingData; -typedef struct t_PhaseData { #define TRIM_EXTENDED_MAX 500 #define TRIM_EXTENDED_MIN (-TRIM_EXTENDED_MAX) #define TRIM_MAX 125 #define TRIM_MIN (-TRIM_MAX) + +PACK(typedef struct t_PhaseData { int8_t trim[4]; // -500..500 => trim value, 501 => use trim of phase 0, 502, 503, 504 => use trim of phases 1|2|3|4 instead int8_t trim_ext:8; // 2 less significant extra bits per trim (10bits trims) int8_t swtch; // swtch of phase[0] is not used char name[6]; uint8_t fadeIn:4; uint8_t fadeOut:4; -} __attribute__((packed)) PhaseData; +}) PhaseData; #define MAX_MODELS 16 #define MAX_PHASES 5 @@ -221,14 +228,14 @@ typedef struct t_PhaseData { #define NUM_CSW 12 // number of custom switches #define NUM_FSW 12 // number of functions assigned to switches -typedef struct t_TimerData { +PACK(typedef struct t_TimerData { int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw uint16_t val:14; uint8_t persistent:1; uint8_t dir:1; // 0=>Count Down, 1=>Count Up -} __attribute__((packed)) TimerData; +}) TimerData; -typedef struct t_ModelData { +PACK(typedef struct t_ModelData { char name[10]; // 10 must be first for eeLoadModelName TimerData timer1; // TODO timers array uint8_t protocol:3; @@ -255,7 +262,7 @@ typedef struct t_ModelData { PhaseData phaseData[MAX_PHASES]; FrSkyData frsky; int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments -} __attribute__((packed)) ModelData; +}) ModelData; extern EEGeneral g_eeGeneral; extern ModelData g_model; diff --git a/src/pulses.cpp b/src/pulses.cpp index e20ffda37..7481a64f6 100644 --- a/src/pulses.cpp +++ b/src/pulses.cpp @@ -129,7 +129,7 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation //uint16_t PPM_gap = 300 * 2; //Stoplen *2 //uint16_t PPM_frame ; -inline void __attribute__ ((always_inline)) setupPulsesPPM() // changed 10/05/2010 by dino Issue 128 +FORCEINLINE void setupPulsesPPM() // changed 10/05/2010 by dino Issue 128 { #define PPM_CENTER 1200*2 int16_t PPM_range = g_model.extendedLimits ? 640*2 : 512*2; //range of 0.7..1.7msec diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index 9f63f9d97..2e99a9e28 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -19,8 +19,14 @@ * */ +#ifndef __GNUC__ +#include +#define sleep(x) Sleep(x) +#else #include -#include +#define sleep(x) usleep(1000*x) +#endif + #include #include "simpgmspace.h" #include "lcd.h" @@ -75,7 +81,7 @@ void *eeprom_write_function(void *) perror("error in fseek"); if (fwrite(eeprom_buffer_data, 1, 1, fp) != 1) perror("error in fwrite"); - usleep(5000/*5ms*/); + sleep(5/*ms*/); } else { memcpy(&eeprom[eeprom_pointer], eeprom_buffer_data, 1); @@ -117,15 +123,16 @@ void *main_thread(void *) while (main_thread_running) { perMain(); - usleep(1000); + sleep(1/*ms*/); } - return NULL; #ifdef SIMU_EXCEPTIONS } catch (...) { main_thread_running = 0; } #endif + + return NULL; } pthread_t main_thread_pid; diff --git a/src/simpgmspace.h b/src/simpgmspace.h index dafd0478f..786fdb670 100644 --- a/src/simpgmspace.h +++ b/src/simpgmspace.h @@ -27,7 +27,7 @@ extern char * main_thread_error; #include #include #include -#ifdef WIN32 +#if defined(WIN32) || !defined(__GNUC__) #define write_backtrace(output) #else #include