diff --git a/comms.h b/comms.h index b685f1c..a0f93c6 100644 --- a/comms.h +++ b/comms.h @@ -1,3 +1,6 @@ +#ifndef COMMS_H +#define COMMS_H + #define vePage 1 #define ignPage 2 #define afrPage 3 @@ -12,3 +15,5 @@ void sendPage(); void receiveCalibration(byte tableID); void sendToothLog(bool useChar); void testComm(); + +#endif // COMMS_H diff --git a/comms.ino b/comms.ino index 3e9cda1..f79efed 100644 --- a/comms.ino +++ b/comms.ino @@ -3,6 +3,10 @@ This is called when a command is received over serial from TunerStudio / Megatun It parses the command and calls the relevant function A detailed description of each call can be found at: http://www.msextra.com/doc/ms1extra/COM_RS232.htm */ +#include "comms.h" +#include "globals.h" +#include "storage.h" + void command() { switch (Serial.read()) diff --git a/corrections.h b/corrections.h index 3e24b0a..0fd54ba 100644 --- a/corrections.h +++ b/corrections.h @@ -2,6 +2,9 @@ All functions in the gamma file return */ +#ifndef CORRECTIONS_H +#define CORRECTIONS_H + //static byte numCorrections = 2; byte correctionsTotal(); @@ -10,3 +13,5 @@ byte correctionASE(); //After Start Enrichment byte correctionAccel(); //Acceleration Enrichment byte correctionsFloodClear(); //Check for flood clear on cranking byte correctionsAFRClosedLoop(); //Closed loop AFR adjustment + +#endif // CORRECTIONS_H diff --git a/corrections.ino b/corrections.ino index f003c30..78dcbc6 100644 --- a/corrections.ino +++ b/corrections.ino @@ -7,6 +7,8 @@ Flood clear mode etc. */ //************************************************************************************************************ +#include "corrections.h" +#include "globals.h" /* correctionsTotal() calls all the other corrections functions and combines their results. diff --git a/fastAnalog.h b/fastAnalog.h index af6fbb1..b1b0ef9 100644 --- a/fastAnalog.h +++ b/fastAnalog.h @@ -1,3 +1,6 @@ +#ifndef FASTANALOG_H +#define FASTANALOG_H + #ifndef cbi #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif @@ -5,4 +8,5 @@ #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif +#endif // FASTANALOG_H diff --git a/globals.h b/globals.h index 7ba915a..a6d6207 100644 --- a/globals.h +++ b/globals.h @@ -1,3 +1,5 @@ +#ifndef GLOBALS_H +#define GLOBALS_H #include const byte ms_version = 20; @@ -270,3 +272,25 @@ struct config3 { #define pinCLT A3 //CLS sensor pin #define pinO2 A4 //O2 Sensor pin */ + +// global variables // from speeduino.ino +extern struct statuses currentStatus; // from speeduino.ino +extern struct table3D fuelTable; //8x8 fuel map +extern struct table3D ignitionTable; //8x8 ignition map +extern struct table3D afrTable; //8x8 afr target map +extern struct table2D taeTable; //4 bin TPS Acceleration Enrichment map +extern struct table2D WUETable; //10 bin Warm Up Enrichment map (2D) +extern struct config1 configPage1; +extern struct config2 configPage2; +extern struct config3 configPage3; +extern unsigned long currentLoopTime; //The time the current loop started (uS) +extern unsigned long previousLoopTime; //The time the previous loop started (uS) +extern byte ignitionCount; +extern byte cltCalibrationTable[CALIBRATION_TABLE_SIZE]; +extern byte iatCalibrationTable[CALIBRATION_TABLE_SIZE]; +extern byte o2CalibrationTable[CALIBRATION_TABLE_SIZE]; +extern volatile int toothHistory[512]; +extern volatile int toothHistoryIndex; + + +#endif // GLOBALS_H diff --git a/math.h b/math.h index fe25096..316ac60 100644 --- a/math.h +++ b/math.h @@ -1,3 +1,5 @@ +#ifndef MATH_H +#define MATH_H //Replace the standard arduino map() function to use the div function instead int fastMap(int x, int in_min, int in_max, int out_min, int out_max) @@ -49,3 +51,5 @@ int divs100(int n) { return q + ((r + 28) >> 7); // return q + (r > 99); } + +#endif // MATH_H diff --git a/scheduler.h b/scheduler.h index 4d3e9eb..d6257c0 100644 --- a/scheduler.h +++ b/scheduler.h @@ -22,6 +22,8 @@ See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pd 256 prescale gives overflow every 1048576uS (This means maximum wait time is 1.0485 seconds) */ +#ifndef SCHEDULER_H +#define SCHEDULER_H #include #include @@ -54,3 +56,5 @@ Schedule ignitionSchedule1; Schedule ignitionSchedule2; Schedule ignitionSchedule3; Schedule ignitionSchedule4; + +#endif // SCHEDULER_H diff --git a/scheduler.ino b/scheduler.ino index 5a20889..2c74e71 100644 --- a/scheduler.ino +++ b/scheduler.ino @@ -1,4 +1,5 @@ - +#include "scheduler.h" +#include "globals.h" void initialiseSchedulers() diff --git a/speeduino.ino b/speeduino.ino index 7b99565..7129c9e 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -540,7 +540,7 @@ void endCoil4Charge() { digitalWrite(pinCoil4, coilLOW); BIT_CLEAR(currentStatus //The trigger function is called everytime a crank tooth passes the sensor volatile unsigned long curTime; -volatile int curGap; +volatile unsigned int curGap; volatile unsigned int targetGap; void trigger() { @@ -550,7 +550,7 @@ void trigger() curTime = micros(); curGap = curTime - toothLastToothTime; - if ( curGap < triggerFilterTime) { interrupts(); return; } //Debounce check. Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS) + if ( curGap < triggerFilterTime ) { interrupts(); return; } //Debounce check. Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS) toothCurrentCount++; //Increment the tooth counter //High speed tooth logging history diff --git a/storage.h b/storage.h index 1100d27..499d46f 100644 --- a/storage.h +++ b/storage.h @@ -1,3 +1,5 @@ +#ifndef STORAGE_H +#define STORAGE_H #include void writeConfig(); @@ -59,3 +61,4 @@ Current layout of EEPROM data (Version 2) is as follows (All sizes are in bytes) #define EEPROM_CALIBRATION_IAT 3071 #define EEPROM_CALIBRATION_CLT 3583 +#endif // STORAGE_H diff --git a/storage.ino b/storage.ino index bd97061..39df0c2 100644 --- a/storage.ino +++ b/storage.ino @@ -1,6 +1,9 @@ #include +#include "storage.h" +#include "globals.h" //#include "table.h" + /* Takes the current configuration (config pages and maps) and writes them to EEPROM as per the layout defined in storage.h diff --git a/table.h b/table.h index 66166f4..8170abc 100644 --- a/table.h +++ b/table.h @@ -1,6 +1,8 @@ /* This file is used for everything related to maps/tables including their definition, functions etc */ +#ifndef TABLE_H +#define TABLE_H #include /* @@ -46,3 +48,5 @@ Eg: 2x2 table */ int get3DTableValue(struct table3D, int, int); int table2D_getValue(struct table2D, int); + +#endif // TABLE_H diff --git a/table.ino b/table.ino index 909d004..1f38228 100644 --- a/table.ino +++ b/table.ino @@ -2,6 +2,9 @@ Because the size of the table is dynamic, this functino is required to reallocate the array sizes Note that this may clear some of the existing values of the table */ +#include "table.h" +#include "globals.h" + void table2D_setSize(struct table2D* targetTable, byte newSize) { //2D tables can contain either bytes or ints, depending on the value of the valueSize field diff --git a/testing.h b/testing.h index 2f9633e..53b6473 100644 --- a/testing.h +++ b/testing.h @@ -1,7 +1,8 @@ /* This file has a few functions that are helpful for testing such as creating dummy maps and faking interrupts */ - +#ifndef TESTING_H +#define TESTING_H /* Aim is to create an 8x8 table that looks like the below: MAP @@ -105,3 +106,5 @@ void dummyIgnitionTable(struct table3D *mySparkTable) for (byte x = 0; x< mySparkTable->xSize; x++) { mySparkTable->values[7][x] = tempRow8[x]; } } + +#endif // TESTING_H diff --git a/timers.h b/timers.h index 5660c31..41d0671 100644 --- a/timers.h +++ b/timers.h @@ -16,6 +16,8 @@ We're after a 1ms interval so we'll need 131 intervals to reach this ( 1ms / 0.0 Hence we will preload the timer with 131 cycles to leave 125 until overflow (1ms). */ +#ifndef TIMERS_H +#define TIMERS_H volatile int loop250ms; volatile int loopSec; @@ -24,4 +26,4 @@ volatile unsigned long targetOverdwellTime; void initialiseTimers(); - +#endif // TIMERS_H diff --git a/timers.ino b/timers.ino index 552a113..12eb189 100644 --- a/timers.ino +++ b/timers.ino @@ -4,6 +4,8 @@ They should not be confused with Schedulers, which are for performing an action Timers are typically low resolution (Compared to Schedulers), with maximum frequency currently being approximately every 10ms */ +#include "timers.h" +#include "globals.h" void initialiseTimers() { diff --git a/utils.h b/utils.h index b44b396..49746fa 100644 --- a/utils.h +++ b/utils.h @@ -1,6 +1,9 @@ /* These are some utility functions and variables used through the main code */ +#ifndef UTILS_H +#define UTILS_H + #include #define MS_IN_MINUTE 60000 #define US_IN_MINUTE 60000000 @@ -10,3 +13,5 @@ int AIRDEN(); unsigned int PW(); unsigned int PW_SD(); unsigned int PW_AN(); + +#endif // UTILS_H diff --git a/utils.ino b/utils.ino index 8a184e7..6f23a14 100644 --- a/utils.ino +++ b/utils.ino @@ -1,6 +1,8 @@ /* Returns how much free dynamic memory exists (between heap and stack) */ +#include "utils.h" + int freeRam () { extern int __heap_start, *__brkval;