Skip to content
Permalink
Browse files

MISRA cleanup

  • Loading branch information
noisymime committed Dec 2, 2019
1 parent 8cb7876 commit df22b1d41bcfae95836475683b5983b32303119d
@@ -94,7 +94,7 @@ No text specified
Rule 9.5
No text specified
Rule 10.1
Arguments of a conditional operation must be of an essentially boolean type
Operations must be of an essentially correct type (Eg no shift on signed values, comparison is not boolean, incrementing/decrementing a bool etc)
Rule 10.2
No text specified
Rule 10.3
@@ -38,14 +38,14 @@ void fanControl()
if ( configPage2.fanWhenOff ) { fanPermit = true; }
else { fanPermit = BIT_CHECK(currentStatus.engine, BIT_ENGINE_RUN); }

if ( currentStatus.coolant >= onTemp && fanPermit )
if ( (currentStatus.coolant >= onTemp) && (fanPermit == true) )
{
//Fan needs to be turned on. Checked for normal or inverted fan signal
if( configPage6.fanInv == 0 ) { FAN_PIN_HIGH(); }
else { FAN_PIN_LOW(); }
currentStatus.fanOn = true;
}
else if ( currentStatus.coolant <= offTemp || !fanPermit )
else if ( (currentStatus.coolant <= offTemp) || (!fanPermit) )
{
//Fan needs to be turned off. Checked for normal or inverted fan signal
if( configPage6.fanInv == 0 ) { FAN_PIN_LOW(); }
@@ -245,11 +245,12 @@ void vvtControl()

if(currentStatus.vvtTargetAngle > 0)
{
vvtPID.Compute(false);
bool PID_compute = vvtPID.Compute(false);
//vvtPID.Compute2(currentStatus.vvtTargetAngle, currentStatus.vvtAngle, false);
//vvt_pwm_target_value = percentage(40, vvt_pwm_max_count);
//if (currentStatus.vvtAngle > currentStatus.vvtTargetAngle) { vvt_pwm_target_value = 0; }
currentStatus.vvtDuty = (vvt_pwm_value * 100) / vvt_pwm_max_count;
if(PID_compute == true) { currentStatus.vvtDuty = (vvt_pwm_value * 100) / vvt_pwm_max_count; }

}
else
{
@@ -160,7 +160,7 @@ void sendcanValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portTy
}
#endif

currentStatus.spark ^= (-currentStatus.hasSync ^ currentStatus.spark) & (1 << BIT_SPARK_SYNC); //Set the sync bit of the Spark variable to match the hasSync variable
currentStatus.spark ^= (-currentStatus.hasSync ^ currentStatus.spark) & (1U << BIT_SPARK_SYNC); //Set the sync bit of the Spark variable to match the hasSync variable

fullStatus[0] = currentStatus.secl; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
fullStatus[1] = currentStatus.status1; //status1 Bitfield
@@ -11,7 +11,7 @@ static inline byte correctionsFuel() __attribute__((always_inline));
static inline byte correctionWUE() __attribute__((always_inline)); //Warmup enrichment
static inline byte correctionCranking() __attribute__((always_inline)); //Cranking enrichment
static inline byte correctionASE() __attribute__((always_inline)); //After Start Enrichment
static inline int16_t correctionAccel() __attribute__((always_inline)); //Acceleration Enrichment
static inline uint16_t correctionAccel() __attribute__((always_inline)); //Acceleration Enrichment
static inline byte correctionFloodClear() __attribute__((always_inline)); //Check for flood clear on cranking
static inline byte correctionAFRClosedLoop() __attribute__((always_inline)); //Closed loop AFR adjustment
static inline byte correctionFlex() __attribute__((always_inline)); //Flex fuel adjustment
@@ -107,7 +107,6 @@ static inline byte correctionWUE()
{
//This prevents us doing the 2D lookup if we're already up to temp
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_WARMUP);
//WUEValue = WUETable.values[9]; //Set the current value to be whatever the final value on the curve is.
WUEValue = table2D_getRawValue(&WUETable, 9);
}
else
@@ -169,10 +168,10 @@ static inline byte correctionASE()
* Calculates the % change of the throttle over time (%/second) and performs a lookup based on this
* When the enrichment is turned on, it runs at that amount for a fixed period of time (taeTime)
*
* @return int16_t The Acceleration enrichment modifier as a %. 100% = No modification.
* As the maximum enrichment amount is +255%, the overall return value from this function can be 100+255=355. Hence this function returns a int16_t rather than byte
* @return uint16_t The Acceleration enrichment modifier as a %. 100% = No modification.
* As the maximum enrichment amount is +255%, the overall return value from this function can be 100+255=355. Hence this function returns a uint16_t rather than byte
*/
static inline int16_t correctionAccel()
static inline uint16_t correctionAccel()
{
int16_t accelValue = 100;
//First, check whether the accel. enrichment is already running
@@ -452,9 +451,10 @@ static inline byte correctionAFRClosedLoop()
PID_O2 = (long)(currentStatus.O2);
PID_AFRTarget = (long)(currentStatus.afrTarget);

egoPID.Compute();
bool PID_compute = egoPID.Compute();
//currentStatus.egoCorrection = 100 + PID_output;
AFRValue = 100 + PID_output;
if(PID_compute == true) { AFRValue = 100 + PID_output; }

}
else { AFRValue = 100; } // Occurs if the egoAlgorithm is set to 0 (No Correction)
} //Ignition count check
@@ -538,20 +538,20 @@ static inline int8_t correctionIdleAdvance(int8_t advance)

int8_t ignIdleValue = advance;
//Adjust the advance based on idle target rpm.
if( (configPage2.idleAdvEnabled) >= 1 && (currentStatus.runSecs >= configPage2.IdleAdvDelay))
if( (configPage2.idleAdvEnabled >= 1) && (currentStatus.runSecs >= configPage2.IdleAdvDelay))
{
currentStatus.CLIdleTarget = (byte)table2D_getValue(&idleTargetTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //All temps are offset by 40 degrees
int idleRPMdelta = (currentStatus.CLIdleTarget - currentStatus.RPM / 10) + 50;
int idleRPMdelta = (currentStatus.CLIdleTarget - (currentStatus.RPM / 10) ) + 50;
// Limit idle rpm delta between -500rpm - 500rpm
if(idleRPMdelta > 100) { idleRPMdelta = 100; }
if(idleRPMdelta < 0) { idleRPMdelta = 0; }
if(configPage2.idleAdvAlgorithm == 0 && ((currentStatus.RPM < (unsigned int)(configPage2.idleAdvRPM * 100)) && (currentStatus.TPS < configPage2.idleAdvTPS))) // TPS based idle state
if( (configPage2.idleAdvAlgorithm == 0) && ((currentStatus.RPM < (unsigned int)(configPage2.idleAdvRPM * 100)) && (currentStatus.TPS < configPage2.idleAdvTPS))) // TPS based idle state
{
int8_t advanceIdleAdjust = (int16_t)(table2D_getValue(&idleAdvanceTable, idleRPMdelta)) - 15;
if(configPage2.idleAdvEnabled == 1) { ignIdleValue = (advance + advanceIdleAdjust); }
else if(configPage2.idleAdvEnabled == 2) { ignIdleValue = advanceIdleAdjust; }
}
else if(configPage2.idleAdvAlgorithm == 1 && (currentStatus.RPM < (unsigned int)(configPage2.idleAdvRPM * 100) && currentStatus.CTPSActive == 1)) // closed throttle position sensor (CTPS) based idle state
else if( (configPage2.idleAdvAlgorithm == 1) && (currentStatus.RPM < (unsigned int)(configPage2.idleAdvRPM * 100) && (currentStatus.CTPSActive == 1) )) // closed throttle position sensor (CTPS) based idle state
{
int8_t advanceIdleAdjust = (int16_t)(table2D_getValue(&idleAdvanceTable, idleRPMdelta)) - 15;
if(configPage2.idleAdvEnabled == 1) { ignIdleValue = (advance + advanceIdleAdjust); }
@@ -109,8 +109,8 @@ void doCrankSpeedCalcs()
}
else { angle1 = triggerToothAngle; angle2 = triggerToothAngle; }

long toothDeltaV = (1000000L * angle2 / toothHistory[toothHistoryIndex]) - (1000000L * angle1 / toothHistory[toothHistoryIndex-1]);
long toothDeltaT = toothHistory[toothHistoryIndex];
uint32_t toothDeltaV = (1000000L * angle2 / toothHistory[toothHistoryIndex]) - (1000000L * angle1 / toothHistory[toothHistoryIndex-1]);
uint32_t toothDeltaT = toothHistory[toothHistoryIndex];
//long timeToLastTooth = micros() - toothLastToothTime;

rpmDelta = (toothDeltaV << 10) / (6 * toothDeltaT);
@@ -153,7 +153,7 @@ volatile unsigned long lastGap;
volatile unsigned long targetGap;
volatile unsigned long compositeLastToothTime;

volatile int toothCurrentCount = 0; //The current number of teeth (Onec sync has been achieved, this can never actually be 0
volatile uint16_t toothCurrentCount = 0; //The current number of teeth (Onec sync has been achieved, this can never actually be 0
volatile byte toothSystemCount = 0; //Used for decoders such as Audi 135 where not every tooth is used for calculating crank angle. This variable stores the actual number of teeth, not the number being used to calculate crank angle
volatile unsigned long toothSystemLastToothTime = 0; //As below, but used for decoders where not every tooth count is used for calculation
volatile unsigned long toothLastToothTime = 0; //The time (micros()) that the last tooth was registered
@@ -171,7 +171,7 @@ volatile unsigned int secondaryToothCount; //Used for identifying the current se
volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input)
volatile unsigned long secondaryLastToothTime1 = 0; //The time (micros()) that the last tooth was registered (Cam input)

volatile int triggerActualTeeth;
volatile uint16_t triggerActualTeeth;
volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
volatile unsigned long triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input
volatile bool validTrigger; //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)
@@ -189,10 +189,10 @@ unsigned long lastCrankAngleCalc;
int16_t lastToothCalcAdvance = 99; //Invalid value here forces calculation of this on first main loop
unsigned long lastVVTtime; //The time between the vvt reference pulse and the last crank pulse

int16_t ignition1EndTooth = 0;
int16_t ignition2EndTooth = 0;
int16_t ignition3EndTooth = 0;
int16_t ignition4EndTooth = 0;
uint16_t ignition1EndTooth = 0;
uint16_t ignition2EndTooth = 0;
uint16_t ignition3EndTooth = 0;
uint16_t ignition4EndTooth = 0;

int16_t toothAngles[24]; //An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style

@@ -741,7 +741,7 @@ uint16_t getRPM_BasicDistributor()
uint16_t tempRPM;
if( currentStatus.RPM < currentStatus.crankRPM)
{
tempRPM = crankingGetRPM(triggerActualTeeth) << 1; //crankGetRPM uses teeth per 360 degrees. As triggerActualTeeh is total teeth in 720 degrees, we divide the tooth count by 2
tempRPM = crankingGetRPM(triggerActualTeeth) / 2; //crankGetRPM uses teeth per 360 degrees. As triggerActualTeeh is total teeth in 720 degrees, we divide the tooth count by 2
revolutionTime = revolutionTime >> 1; //Revolution time has to be divided by 2 as otherwise it would be over 720 degrees (triggerActualTeeth = nCylinders)
}
else { tempRPM = stdGetRPM(720); } //Multiply RPM by 2 due to tracking over 720 degrees now rather than 360
@@ -2251,7 +2251,7 @@ void triggerSetup_non360()
{
triggerToothAngle = (360 * configPage4.TrigAngMul) / configPage4.triggerTeeth; //The number of degrees that passes from tooth to tooth multiplied by the additional multiplier
toothCurrentCount = 255; //Default value
triggerFilterTime = (int)(1000000 / (MAX_RPM / 60 * configPage4.triggerTeeth)); //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise
triggerFilterTime = (uint32_t)(1000000 / (MAX_RPM / 60 * configPage4.triggerTeeth)); //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise
triggerSecFilterTime = (int)(1000000 / (MAX_RPM / 60 * 2)) / 2; //Same as above, but fixed at 2 teeth on the secondary input and divided by 2 (for cam speed)
secondDerivEnabled = false;
decoderIsSequential = true;
@@ -2513,7 +2513,7 @@ int getCrankAngle_Nissan360()
interrupts();

crankAngle = ( (tempToothCurrentCount - 1) * 2) + configPage4.triggerAngle;
unsigned long halfTooth = (tempToothLastToothTime - tempToothLastMinusOneToothTime) >> 1;
unsigned long halfTooth = (tempToothLastToothTime - tempToothLastMinusOneToothTime) / 2;
if (elapsedTime > halfTooth)
{
//Means we're over halfway to the next tooth, so add on 1 degree
@@ -2530,15 +2530,15 @@ int getCrankAngle_Nissan360()
void triggerSetEndTeeth_Nissan360()
{
//This uses 4 prior teeth, just to ensure there is sufficient time to set the schedule etc
ignition1EndTooth = ( (ignition1EndAngle - configPage4.triggerAngle) / 2 ) - 4;
ignition2EndTooth = ( (ignition2EndAngle - configPage4.triggerAngle) / 2 ) - 4;
ignition3EndTooth = ( (ignition3EndAngle - configPage4.triggerAngle) / 2 ) - 4;
ignition4EndTooth = ( (ignition4EndAngle - configPage4.triggerAngle) / 2 ) - 4;

if(ignition1EndTooth < 0) { ignition1EndTooth += 360; }
if(ignition2EndTooth < 0) { ignition2EndTooth += 360; }
if(ignition3EndTooth < 0) { ignition3EndTooth += 360; }
if(ignition4EndTooth < 0) { ignition4EndTooth += 360; }
byte offset_teeth = 4;
if((ignition1EndAngle - offset_teeth) > configPage4.triggerAngle) { ignition1EndTooth = ( (ignition1EndAngle - configPage4.triggerAngle) / 2 ) - offset_teeth; }
else { ignition1EndTooth = ( (ignition1EndAngle + 720 - configPage4.triggerAngle) / 2 ) - offset_teeth; }
if((ignition2EndAngle - offset_teeth) > configPage4.triggerAngle) { ignition2EndTooth = ( (ignition2EndAngle - configPage4.triggerAngle) / 2 ) - offset_teeth; }
else { ignition2EndTooth = ( (ignition2EndAngle + 720 - configPage4.triggerAngle) / 2 ) - offset_teeth; }
if((ignition3EndAngle - offset_teeth) > configPage4.triggerAngle) { ignition3EndTooth = ( (ignition3EndAngle - configPage4.triggerAngle) / 2 ) - offset_teeth; }
else { ignition3EndTooth = ( (ignition3EndAngle + 720 - configPage4.triggerAngle) / 2 ) - offset_teeth; }
if((ignition4EndAngle - offset_teeth) > configPage4.triggerAngle) { ignition4EndTooth = ( (ignition4EndAngle - configPage4.triggerAngle) / 2 ) - offset_teeth; }
else { ignition4EndTooth = ( (ignition4EndAngle + 720 - configPage4.triggerAngle) / 2 ) - offset_teeth; }

lastToothCalcAdvance = currentStatus.advance;
}
@@ -425,7 +425,7 @@ struct statuses {
byte battery10; /**< The current BRV in volts (multiplied by 10. Eg 12.5V = 125) */
int8_t advance; /**< Signed 8 bit as advance can now go negative (ATDC) */
byte corrections; /**< The total current corrections % amount */
int16_t AEamount; /**< The amount of accleration enrichment currently being applied */
uint16_t AEamount; /**< The amount of accleration enrichment currently being applied. 100=No change. Varies above 255 */
byte egoCorrection; /**< The amount of closed loop AFR enrichment currently being applied */
byte wueCorrection; /**< The amount of warmup enrichment currently being applied */
byte batCorrection; /**< The amount of battery voltage enrichment currently being applied */
@@ -38,7 +38,7 @@ struct table2D iacCrankDutyTable;
struct StepperIdle idleStepper;
bool idleOn; //Simply tracks whether idle was on last time around
byte idleInitComplete = 99; //TRacks which idle method was initialised. 99 is a method that will never exist
unsigned int iacStepTime;
unsigned int iacStepTime_uS;
unsigned int iacCoolTime;
unsigned int completedHomeSteps;

0 comments on commit df22b1d

Please sign in to comment.
You can’t perform that action at this time.