Big MISRA cleanup

This commit is contained in:
Josh Stewart 2019-07-08 17:56:02 +10:00
parent 3ee8e11824
commit fa621ea071
11 changed files with 36 additions and 63 deletions

View File

@ -112,9 +112,9 @@
#define MAX_TIMER_PERIOD 262140UL //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 4, as each timer tick is 4uS)
#define MAX_TIMER_PERIOD_SLOW 1048560UL //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 16, as each timer tick is 16uS)
#define uS_TO_TIMER_COMPARE(uS1) (uS1 >> 2) //Converts a given number of uS into the required number of timer ticks until that time has passed
#define uS_TO_TIMER_COMPARE(uS1) ((uS1) >> 2) //Converts a given number of uS into the required number of timer ticks until that time has passed
//This is a hack until I make all the AVR timers run at the same speed
#define uS_TO_TIMER_COMPARE_SLOW(uS1) (uS1 >> 4)
#define uS_TO_TIMER_COMPARE_SLOW(uS1) ((uS1) >> 4)
/*
***********************************************************************************************************

View File

@ -74,13 +74,13 @@ void initBoard()
*/
#if defined (STM32F1) || defined(__STM32F1__)
//(CYCLES_PER_MICROSECOND == 72, APB2 at 72MHz, APB1 at 36MHz).
//Timer2 to 4 is on APB1, Timer1 on APB2. http://www.st.com/resource/en/datasheet/stm32f103cb.pdf sheet 12
//Timer2 to 4 is on APB1, Timer1 on APB2. www.st.com/resource/en/datasheet/stm32f103cb.pdf sheet 12
Timer1.setPrescaleFactor((72 * 2)-1); //2us resolution
Timer2.setPrescaleFactor((36 * 2)-1); //2us resolution
Timer3.setPrescaleFactor((36 * 2)-1); //2us resolution
#elif defined(STM32F4)
//(CYCLES_PER_MICROSECOND == 168, APB2 at 84MHz, APB1 at 42MHz).
//Timer2 to 14 is on APB1, Timers 1, 8, 9 and 10 on APB2. http://www.st.com/resource/en/datasheet/stm32f407vg.pdf sheet 120
//Timer2 to 14 is on APB1, Timers 1, 8, 9 and 10 on APB2. www.st.com/resource/en/datasheet/stm32f407vg.pdf sheet 120
Timer1.setPrescaleFactor((168 * 2)-1); //2us resolution
Timer2.setPrescaleFactor((84 * 2)-1); //2us resolution
Timer3.setPrescaleFactor((84 * 2)-1); //2us resolution

View File

@ -497,7 +497,7 @@ void sendValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portNum)
requestCount++;
}
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
@ -1209,9 +1209,9 @@ void sendPageASCII()
if (y == 2) { currentVar = configPage6.voltageCorrectionBins; }
else { currentVar = configPage6.injVoltageCorrectionValues; }
for (byte x = 6; x; x--)
for (byte i = 6; i; i--)
{
Serial.print(currentVar[6 - x]);
Serial.print(currentVar[6 - i]);
Serial.print(' ');
}
Serial.println();
@ -1222,9 +1222,9 @@ void sendPageASCII()
if (y == 2) { currentVar = configPage6.airDenBins; }
else { currentVar = configPage6.airDenRates; }
for (byte x = 9; x; x--)
for (byte i = 9; i; i--)
{
Serial.print(currentVar[9 - x]);
Serial.print(currentVar[9 - i]);
Serial.print(' ');
}
Serial.println();
@ -1250,9 +1250,9 @@ void sendPageASCII()
case 4: currentVar = configPage6.iacCLValues; break;
default: break;
}
for (byte x = 10; x; x--)
for (byte i = 10; i; i--)
{
Serial.print(currentVar[10 - x]);
Serial.print(currentVar[10 - i]);
Serial.print(' ');
}
Serial.println();
@ -1267,9 +1267,9 @@ void sendPageASCII()
case 3: currentVar = configPage6.iacCrankSteps; break;
default: break;
}
for (byte x = 4; x; x--)
for (byte i = 4; i; i--)
{
Serial.print(currentVar[4 - x]);
Serial.print(currentVar[4 - i]);
Serial.print(' ');
}
Serial.println();
@ -1299,9 +1299,9 @@ void sendPageASCII()
}
Serial.print(axisY);// Vertical Bins
Serial.write(" ");
for (int x = 0; x < currentTable.xSize; x++)
for (int i = 0; i < currentTable.xSize; i++)
{
byte value = currentTable.values[y][x];
byte value = currentTable.values[y][i];
if (value < 100)
{
Serial.write(" ");
@ -1356,8 +1356,8 @@ void sendPageASCII()
{
if (isMap)
{
do //This is a do while loop that kicks in for the boostvvtPage
{
//This is a do while loop that kicks in for the boostvvtPage
do {
const char spaceChar = ' ';
Serial.println((const __FlashStringHelper *)&pageTitles[currentTitleIndex]);// F macro hack
@ -1413,7 +1413,7 @@ void sendPageASCII()
currentTable = vvtTable;
}
else { currentTitleIndex = 0; }
}while(currentTitleIndex == 132); //Should never loop unless going to display vvtTable
} while(currentTitleIndex == 132); //Should never loop unless going to display vvtTable
} //is map
else
{

View File

@ -10,9 +10,9 @@
//#define fastDegreesToUS(targetDegrees) ((targetDegrees) * (unsigned long)timePerDegree)
#define fastDegreesToUS(targetDegrees) (((targetDegrees) * (unsigned long)timePerDegreex16) >> 4)
//#define fastTimeToAngle(time) (((unsigned long)time * degreesPeruSx2048) / 2048) //Divide by 2048 will be converted at compile time to bitshift
#define fastTimeToAngle(time) (((unsigned long)time * degreesPeruSx32768) / 32768) //Divide by 32768 will be converted at compile time to bitshift
#define fastTimeToAngle(time) (((unsigned long)(time) * degreesPeruSx32768) / 32768) //Divide by 32768 will be converted at compile time to bitshift
#define ignitionLimits(angle) ( (((int16_t)angle) >= CRANK_ANGLE_MAX_IGN) ? (angle - CRANK_ANGLE_MAX_IGN) : ( (angle < 0) ? (angle + CRANK_ANGLE_MAX_IGN) : angle) )
#define ignitionLimits(angle) ( (((int16_t)(angle)) >= CRANK_ANGLE_MAX_IGN) ? ((angle) - CRANK_ANGLE_MAX_IGN) : ( ((angle) < 0) ? ((angle) + CRANK_ANGLE_MAX_IGN) : (angle)) )
unsigned long angleToTime(int16_t, byte);

View File

@ -965,21 +965,6 @@ void triggerSetup_4G63()
triggerActualTeeth = 8;
}
/*
* forums.libreems.org/attachment.php?aid=34
toothAngles[0] = 715; //Falling edge of tooth #1
toothAngles[1] = 49; //Falling edge of wide cam
toothAngles[2] = 105; //Rising edge of tooth #2
toothAngles[3] = 175; //Falling edge of tooth #2
toothAngles[4] = 229; //Rising edge of narrow cam tooth (??)
toothAngles[5] = 285; //Rising edge of tooth #3
toothAngles[6] = 319; //Falling edge of narrow cam tooth
toothAngles[7] = 355; //falling edge of tooth #3
toothAngles[8] = 465; //Rising edge of tooth #4
toothAngles[9] = 535; //Falling edge of tooth #4
toothAngles[10] = 535; //Rising edge of wide cam tooth
toothAngles[11] = 645; //Rising edge of tooth #1
*/
triggerFilterTime = 1500; //10000 rpm, assuming we're triggering on both edges off the crank tooth.
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)

View File

@ -44,7 +44,7 @@ void initialiseAll()
Serial.begin(115200);
if (configPage9.enable_secondarySerial == 1) { CANSerial.begin(115200); }
#if defined(CORE_STM32) || defined(CORE_TEENSY)
configPage9.intcan_available = 1; // device has internal canbus
//Teensy onboard CAN not used currently
@ -250,7 +250,7 @@ void initialiseAll()
}
//Begin the main crank trigger interrupt pin setup
//The interrupt numbering is a bit odd - See here for reference: http://arduino.cc/en/Reference/AttachInterrupt
//The interrupt numbering is a bit odd - See here for reference: arduino.cc/en/Reference/AttachInterrupt
//These assignments are based on the Arduino Mega AND VARY BETWEEN BOARDS. Please confirm the board you are using and update acordingly.
currentStatus.RPM = 0;
currentStatus.hasSync = false;
@ -1014,7 +1014,7 @@ void setPinMapping(byte boardID)
pinCoil3 = 30;
pinO2 = A22;
#elif defined(STM32F4)
//Black F407VE http://wiki.stm32duino.com/index.php?title=STM32F407
//Black F407VE wiki.stm32duino.com/index.php?title=STM32F407
//PC8~PC12 SDio
//PA13~PA15 & PB4 SWD(debug) pins
//PB0 EEPROM CS pin
@ -1055,8 +1055,8 @@ void setPinMapping(byte boardID)
pinTrigger = PE3; //The CAS pin
pinTrigger2 = PE4; //The Cam Sensor pin
#elif defined(CORE_STM32)
//blue pill http://wiki.stm32duino.com/index.php?title=Blue_Pill
//Maple mini http://wiki.stm32duino.com/index.php?title=Maple_Mini
//blue pill wiki.stm32duino.com/index.php?title=Blue_Pill
//Maple mini wiki.stm32duino.com/index.php?title=Maple_Mini
//pins PA12, PA11 are used for USB or CAN couldn't be used for GPIO
pinInjector1 = PB7; //Output pin injector 1 is on
pinInjector2 = PB6; //Output pin injector 2 is on
@ -1464,7 +1464,7 @@ void setPinMapping(byte boardID)
default:
#if defined(STM32F4)
//Black F407VE http://wiki.stm32duino.com/index.php?title=STM32F407
//Black F407VE wiki.stm32duino.com/index.php?title=STM32F407
//PC8~PC12 SDio
//PA13~PA15 & PB4 SWD(debug) pins
//PB0 EEPROM CS pin

View File

@ -15,7 +15,7 @@ int fastMap(unsigned long x, int in_min, int in_max, int out_min, int out_max)
/*
The following are all fast versions of specific divisions
Ref: http://www.hackersdelight.org/divcMore.pdf
Ref: www.hackersdelight.org/divcMore.pdf
*/
//Unsigned divide by 10
@ -31,20 +31,6 @@ unsigned int divu10(unsigned int n)
return q + ((r + 6) >> 4);
}
//Signed divide by 10
int divs10(long n)
{
long q, r, p;
p = n + ( (n>>31) & 9);
q = (p >> 1) + (p >> 2);
q = q + (q >> 4);
q = q + (q >> 8);
q = q + (q >> 16);
q = q >> 3;
r = p - (q * 10);
return q + ((r + 6) >> 4);
}
//Signed divide by 100
int divs100(long n)
{

View File

@ -406,6 +406,9 @@ void readBat()
tempReading = fastMap1023toX(analogRead(pinBat), 245); //Get the current raw Battery value. Permissible values are from 0v to 24.5v (245)
#endif
//Apply the offset calibration value to the reading
tempReading += configPage4.batVoltCorrect;
//The following is a check for if the voltage has jumped up from under 5.5v to over 7v.
//If this occurs, it's very likely that the system has gone from being powered by USB to being powered from the 12v power source.
//Should that happen, we retrigger the fuel pump priming and idle homing (If using a stepper)

View File

@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef UNIT_TEST // Scope guard for unit testing
#include <stdint.h> //https://developer.mbed.org/handbook/C-Data-Types
#include <stdint.h> //developer.mbed.org/handbook/C-Data-Types
//************************************************
#include "globals.h"
#include "speeduino.h"
@ -465,7 +465,7 @@ void loop()
configPage2.inj4Ang = configPage2.inj1Ang;
}
unsigned int PWdivTimerPerDegree = div(currentStatus.PW1, timePerDegree).quot; //How many crank degrees the calculated PW will take at the current speed
//This is a little primitive, but is based on the idea that all fuel needs to be delivered before the inlet valve opens. See http://www.extraefi.co.uk/sequential_fuel.html for more detail
//This is a little primitive, but is based on the idea that all fuel needs to be delivered before the inlet valve opens. See www.extraefi.co.uk/sequential_fuel.html for more detail
if(configPage2.inj1Ang > PWdivTimerPerDegree) { injector1StartAngle = configPage2.inj1Ang - ( PWdivTimerPerDegree ); }
else { injector1StartAngle = configPage2.inj1Ang + CRANK_ANGLE_MAX_INJ - PWdivTimerPerDegree; } //Just incase
while(injector1StartAngle > CRANK_ANGLE_MAX_INJ) { injector1StartAngle -= CRANK_ANGLE_MAX_INJ; }

View File

@ -237,7 +237,11 @@ void doUpdates()
if(EEPROM.read(EEPROM_DATA_VERSION) == 11)
{
//A battery calibration offset value was introduced. Set default value to 0
configPage4.batVoltCorrect = 0;
writeAllConfig();
EEPROM.write(EEPROM_DATA_VERSION, 12);
}
//Final check is always for 255 and 0 (Brand new arduino)

View File

@ -4,11 +4,6 @@
A full copy of the license may be found in the projects root directory
*/
/*
Returns how much free dynamic memory exists (between heap and stack)
This function is one big MISRA violation. MISRA advisories forbid directly poking at memory addresses, however there is no other way of determining heap size on embedded systems.
*/
#include <avr/pgmspace.h>
#include "globals.h"
#include "utils.h"