Skip to content

Commit

Permalink
MISRA fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adbancroft committed Sep 30, 2024
1 parent 313f198 commit f6ce42a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
32 changes: 16 additions & 16 deletions speeduino/corrections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ There are 2 top level functions that call more detailed corrections for Fuel and

#define IGN_IDLE_THRESHOLD 200 //RPM threshold (below CL idle target) for when ign based idle control will engage

long PID_O2, PID_output, PID_AFRTarget;
static long PID_O2, PID_output, PID_AFRTarget;
/** Instance of the PID object in case that algorithm is used (Always instantiated).
* Needs to be global as it maintains state outside of each function call.
* Comes from Arduino (?) PID library.
*/
PID egoPID(&PID_O2, &PID_output, &PID_AFRTarget, configPage6.egoKP, configPage6.egoKI, configPage6.egoKD, REVERSE);
static PID egoPID(&PID_O2, &PID_output, &PID_AFRTarget, configPage6.egoKP, configPage6.egoKI, configPage6.egoKD, REVERSE);

byte activateMAPDOT; //The mapDOT value seen when the MAE was activated.
byte activateTPSDOT; //The tpsDOT value seen when the MAE was activated.
static byte activateMAPDOT; //The mapDOT value seen when the MAE was activated.
static byte activateTPSDOT; //The tpsDOT value seen when the MAE was activated.

bool idleAdvActive = false;
static bool idleAdvActive = false;
uint16_t AFRnextCycle;
unsigned long knockStartTime;
uint8_t knockLastRecoveryStep;
static unsigned long knockStartTime;
static uint8_t knockLastRecoveryStep;
//int16_t knockWindowMin; //The current minimum crank angle for a knock pulse to be valid
//int16_t knockWindowMax;//The current maximum crank angle for a knock pulse to be valid
uint8_t aseTaper;
uint8_t dfcoDelay;
uint8_t idleAdvTaper;
uint8_t crankingEnrichTaper;
uint8_t dfcoTaper;
static uint8_t aseTaper;
uint8_t dfcoDelay; // Non-static for unit testing
static uint8_t idleAdvTaper;
static uint8_t crankingEnrichTaper;
uint8_t dfcoTaper; // Non-static for unit testing

/** Initialise instances and vars related to corrections (at ECU boot-up).
*/
Expand Down Expand Up @@ -369,15 +369,15 @@ uint16_t correctionAccel(void)
//If CLT is less than taper min temp, apply full modifier on top of accelValue
if ( currentStatus.coolant <= (int)(configPage2.aeColdTaperMin - CALIBRATION_TEMPERATURE_OFFSET) )
{
uint16_t accelValue_uint = percentage(configPage2.aeColdPct, (uint16_t)accelValue);
uint16_t accelValue_uint = (uint16_t)percentage(configPage2.aeColdPct, (uint16_t)accelValue);
accelValue = (int16_t) accelValue_uint;
}
//If CLT is between taper min and max, taper the modifier value and apply it on top of accelValue
else
{
int16_t taperRange = (int16_t) configPage2.aeColdTaperMax - configPage2.aeColdTaperMin;
int16_t taperPercent = (int)((currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET - configPage2.aeColdTaperMin) * 100) / taperRange;
int16_t coldPct = (int16_t) 100 + percentage((uint8_t) (100U-taperPercent), (configPage2.aeColdPct-100U) );
int16_t coldPct = (int16_t) 100 + (int16_t)percentage((uint8_t) (100U-taperPercent), (configPage2.aeColdPct-100U) );
uint16_t accelValue_uint = (uint16_t) accelValue * coldPct / 100; //Potential overflow (if AE is large) without using uint16_t (percentage() may overflow)
accelValue = (int16_t) accelValue_uint;
}
Expand Down Expand Up @@ -441,8 +441,8 @@ uint16_t correctionAccel(void)
else
{
int16_t taperRange = (int16_t) configPage2.aeColdTaperMax - configPage2.aeColdTaperMin;
int16_t taperPercent = (int)((currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET - configPage2.aeColdTaperMin) * 100) / taperRange;
int16_t coldPct = (int16_t)100 + percentage((uint8_t) (100 - taperPercent), (uint16_t)(configPage2.aeColdPct-100) );
uint16_t taperPercent = (int)((currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET - configPage2.aeColdTaperMin) * 100) / taperRange;
uint16_t coldPct = 100U + (uint16_t)percentage((uint8_t) (100U - taperPercent), configPage2.aeColdPct-100U);
uint16_t accelValue_uint = (uint16_t) accelValue * coldPct / 100; //Potential overflow (if AE is large) without using uint16_t
accelValue = (int16_t) accelValue_uint;
}
Expand Down
1 change: 0 additions & 1 deletion speeduino/corrections.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ uint16_t correctionsDwell(uint16_t dwell);
bool isFixedTimingOn(void);

extern uint16_t AFRnextCycle;
extern uint8_t aseTaper;

#endif // CORRECTIONS_H
4 changes: 4 additions & 0 deletions speeduino/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ struct config2 {
byte crkngAddCLTAdv : 1;
byte includeAFR : 1; //< Enable AFR compensation ? (See also @ref config2.incorporateAFR)
byte hardCutType : 1;
// cppcheck-suppress misra-c2012-6.1
LoadSource ignAlgorithm : 3;
byte indInjAng : 1;
byte injOpen; ///< Injector opening time (ms * 10)
Expand All @@ -528,6 +529,7 @@ struct config2 {
byte nCylinders : 4; ///< Number of cylinders

//config2 in ini
// cppcheck-suppress misra-c2012-6.1
LoadSource fuelAlgorithm : 3;///< Fuel algorithm - 0=Manifold pressure/MAP (LOAD_SOURCE_MAP, default, proven), 1=Throttle/TPS (LOAD_SOURCE_TPS), 2=IMAP/EMAP (LOAD_SOURCE_IMAPEMAP)
byte fixAngEnable : 1; ///< Whether fixed/locked timing is enabled (0=disable, 1=enable, See @ref configPage4.FixAng)
byte nInjectors : 4; ///< Number of injectors
Expand Down Expand Up @@ -1026,6 +1028,7 @@ struct config10 {
byte knock_recoveryStep; //Byte 121

//Byte 122
// cppcheck-suppress misra-c2012-6.1
LoadSource fuel2Algorithm : 3;
byte fuel2Mode : 3;
byte fuel2SwitchVariable : 2;
Expand Down Expand Up @@ -1099,6 +1102,7 @@ struct config10 {
byte fuelTempValues[6]; //180

//Byte 186
// cppcheck-suppress misra-c2012-6.1
LoadSource spark2Algorithm : 3;
byte spark2Mode : 3;
byte spark2SwitchVariable : 2;
Expand Down
8 changes: 8 additions & 0 deletions speeduino/statuses.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ using byte = uint8_t;
* unit based values in similar variable(s) without ADC part in name (see sensors.ino for reading of sensors).
*/
struct statuses {
// cppcheck-suppress misra-c2012-6.1 ; False positive - MISRA C:2012 Rule (R 6.1) permits the use of boolean for bit fields.
volatile bool hasSync : 1; /**< Flag for crank/cam position being known by decoders (See decoders.ino).
This is used for sanity checking e.g. before logging tooth history or reading some sensors and computing readings. */
// cppcheck-suppress misra-c2012-6.1
bool initialisationComplete : 1; //Tracks whether the setup() function has run completely
// cppcheck-suppress misra-c2012-6.1
bool clutchTrigger : 1;
// cppcheck-suppress misra-c2012-6.1
bool previousClutchTrigger : 1;
// cppcheck-suppress misra-c2012-6.1
volatile bool fpPrimed : 1; //Tracks whether or not the fuel pump priming has been completed yet
// cppcheck-suppress misra-c2012-6.1
volatile bool injPrimed : 1; //Tracks whether or not the injector priming has been completed yet
// cppcheck-suppress misra-c2012-6.1
volatile bool tachoSweepEnabled : 1;
// cppcheck-suppress misra-c2012-6.1
volatile bool tachoAlt : 1;

uint16_t RPM; ///< RPM - Current Revs per minute
Expand Down

0 comments on commit f6ce42a

Please sign in to comment.