From 0de3a231c96b3e29bb8d6c65eb310ff0d73ee612 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 7 Nov 2017 22:05:23 +1100 Subject: [PATCH] Minor cleanups before release --- speeduino/maths.h | 7 ++++++- speeduino/sensors.h | 6 ++++-- speeduino/sensors.ino | 6 +++--- speeduino/speeduino.ino | 18 ++++++++++-------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/speeduino/maths.h b/speeduino/maths.h index a1796e86..48e799b6 100644 --- a/speeduino/maths.h +++ b/speeduino/maths.h @@ -4,8 +4,13 @@ int fastMap1023toX(int, int); unsigned long percentage(byte, unsigned long); -#define degreesToUS(degrees) (decoderIsLowRes == true ) ? ((degrees * 166666UL) / currentStatus.RPM) : degrees * (unsigned long)timePerDegree +//#define degreesToUS(degrees) (decoderIsLowRes == true ) ? ((degrees * 166666UL) / currentStatus.RPM) : (degrees * (unsigned long)timePerDegree) +#define degreesToUS(degrees) ((degrees * revolutionTime) / 360) +//#define degreesToUS(degrees) ((degrees * revolutionTime * 3054198967ULL) >> 40) //Fast version of divide by 360 +//#define degreesToUS(degrees) (degrees * (unsigned long)timePerDegree) + #define uSToDegrees(time) (((unsigned long)time * currentStatus.RPM) / 166666) +//#define uSToDegrees(time) ( (((uint64_t)time * currentStatus.RPM * 211107077ULL) >> 45) ) //Crazy magic numbers method from Hackers delight (www.hackersdelight.org/magic.htm) #define DIV_ROUND_CLOSEST(n, d) ((((n) < 0) ^ ((d) < 0)) ? (((n) - (d)/2)/(d)) : (((n) + (d)/2)/(d))) //This is a dedicated function that specifically handles the case of mapping 0-1023 values into a 0 to X range diff --git a/speeduino/sensors.h b/speeduino/sensors.h index 785c5d52..0a59efb1 100644 --- a/speeduino/sensors.h +++ b/speeduino/sensors.h @@ -37,10 +37,12 @@ uint16_t MAPcurRev; //Tracks which revolution we're sampling on */ #define ADC_FILTER(input, alpha, prior) (((long)input * (256 - alpha) + ((long)prior * alpha))) >> 8 -void instanteneousMAPReading(); -void readMAP(); +static inline void instanteneousMAPReading() __attribute__((always_inline)); +static inline void readMAP() __attribute__((always_inline)); +void readTPS(); void flexPulse(); + #if defined(ANALOG_ISR) //Analog ISR interrupt routine /* diff --git a/speeduino/sensors.ino b/speeduino/sensors.ino index 35346524..ce61b43d 100644 --- a/speeduino/sensors.ino +++ b/speeduino/sensors.ino @@ -48,7 +48,7 @@ void initialiseADC() MAPrunningValue = 0; } -void instanteneousMAPReading() +static inline void instanteneousMAPReading() { unsigned int tempReading; //Instantaneous MAP readings @@ -71,7 +71,7 @@ void instanteneousMAPReading() } -void readMAP() +static inline void readMAP() { unsigned int tempReading; //MAP Sampling system @@ -119,7 +119,7 @@ void readMAP() if(currentStatus.MAP < 0) { currentStatus.MAP = 0; } //Sanity check } else { instanteneousMAPReading(); } - + MAPcurRev = currentStatus.startRevolutions; //Reset the current rev count MAPrunningValue = 0; MAPcount = 0; diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index 3d754b9a..4d3c428e 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -811,12 +811,12 @@ void loop() #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3 //if Can interface is enabled then check for external data requests. if (configPage10.enable_candata_in) //if external data input is enabled - { + { if (configPage10.enable_canbus == 1) // megas only support can via secondary serial { for (byte caninChan = 0; caninChan <16 ; caninChan++) { - currentStatus.current_caninchannel = caninChan; + currentStatus.current_caninchannel = caninChan; //currentStatus.canin[14] = currentStatus.current_caninchannel; currentStatus.canin[13] = ((configPage10.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+0x100); if (BIT_CHECK(configPage10.caninput_sel,currentStatus.current_caninchannel)) //if current input channel bit is enabled @@ -827,7 +827,7 @@ void loop() } } } - + #elif defined(CORE_STM32) || defined(CORE_TEENSY) //if serial3io is enabled then check for serial3 requests. if (configPage10.enable_candata_in) @@ -839,11 +839,11 @@ void loop() { if (configPage10.enable_canbus == 1) //can via secondary serial { - sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage10.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+256)); //send an R command for data from paramgroup[currentStatus.current_caninchannel] - } + sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage10.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+256)); //send an R command for data from paramgroup[currentStatus.current_caninchannel] + } else if (configPage10.enable_canbus == 2) // can via internal can module - { - sendCancommand(3,configPage10.speeduino_tsCanId,currentStatus.current_caninchannel,0,configPage10.caninput_source_can_address[currentStatus.current_caninchannel]); //send via localcanbus the command for data from paramgroup[currentStatus.current_caninchannel] + { + sendCancommand(3,configPage10.speeduino_tsCanId,currentStatus.current_caninchannel,0,configPage10.caninput_source_can_address[currentStatus.current_caninchannel]); //send via localcanbus the command for data from paramgroup[currentStatus.current_caninchannel] } } } @@ -1339,11 +1339,13 @@ void loop() ign1EndFunction ); } + /* if(ignition1EndAngle > crankAngle && configPage2.StgCycles == 0) { unsigned long uSToEnd = degreesToUS( (ignition1EndAngle - crankAngle) ); - //refreshIgnitionSchedule1( uSToEnd + fixedCrankingOverride ); + refreshIgnitionSchedule1( uSToEnd + fixedCrankingOverride ); } + */ tempCrankAngle = crankAngle - channel2IgnDegrees; if( tempCrankAngle < 0) { tempCrankAngle += CRANK_ANGLE_MAX_IGN; }