00001 /* Copyright 2008 Fred Cooke 00002 00003 This file is part of the FreeEMS project. 00004 00005 FreeEMS software is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 FreeEMS software is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00017 00018 We ask that if you make any changes to this file you email them upstream to 00019 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00020 00021 Thank you for choosing FreeEMS to run your engine! */ 00022 00023 00036 /* Header file multiple inclusion protection courtesy eclipse Header Template */ 00037 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */ 00038 #ifndef FILE_STRUCTS_H_SEEN 00039 #define FILE_STRUCTS_H_SEEN 00040 00041 00042 /* For noobs : http://www.space.unibe.ch/comp_doc/c_manual/C/SYNTAX/struct.html 00043 * http://en.wikipedia.org/wiki/Composite_type 00044 * http://www.cs.usfca.edu/~wolber/SoftwareDev/C/CStructs.htm 00045 * http://sandbox.mc.edu/~bennet/cs220/codeex/struct_c.html 00046 */ 00047 00048 00049 /* Naming should be in the singular form such that the instantiation can be the plural */ 00050 00051 00052 /* Types summary 00053 * 00054 * BEWARE : Be explicit!! 00055 * 00056 * char 8 bit (defaults to unsigned, but always specify signed/unsigned anyway) 00057 * short 16 bit (defaults to signed, but always specify signed/unsigned anyway) 00058 * int 16 bit DO NOT USE! (current compile flags make this 16 bits, but a change of flags could will change your program if you use this because they will all be 32 bit all of a sudden) 00059 * long 32 bit (defaults to signed, but always specify signed/unsigned anyway) 00060 * long long 64 bit (inefficient, avoid these, if using : defaults to signed, but always specify signed/unsigned anyway) 00061 * float 32 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math) 00062 * double 64 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math) 00063 */ 00064 00065 00066 // TODO various new structs 00067 // Status struct 00068 // Ignition struct 00069 // Injection struct 00070 // Engine position struct 00071 // Validity flags, or they should be in the status struct? 00072 00073 00080 typedef struct { 00081 unsigned char RAMPage; 00082 unsigned char FlashPage; 00083 void* RAMAddress; 00084 void* FlashAddress; 00085 unsigned short size; 00086 } blockDetails; 00087 00088 00089 #define DERIVED_VARS_SIZE sizeof(DerivedVar) 00090 #define DERIVED_VARS_WIDTH IN_OUT_BANKS /* How many elements per array currently 2 at 25/6/08 */ 00091 #define DERIVED_VARS_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */ 00092 /* Use this block to make it easy to manage the derived variables */ 00093 typedef struct { 00094 /* Calculated from core vars */ 00095 unsigned short LoadMain; /* Configurable unit of load */ 00096 // unsigned short LoadSecondary; 00097 00098 unsigned short VEMain; /* Divide by 512 to get % */ 00099 // unsigned short VESecondary; 00100 00101 unsigned short Lambda; /* Divide by 32768 to get Lamda */ 00102 unsigned short AirFlow; /* top half */ 00103 unsigned short densityAndFuel; /* bottom half */ 00104 00105 unsigned short BasePW; /* In timer ticks of 0.8us */ 00106 unsigned short IDT; /* 0.8us ticks */ 00107 unsigned short ETE; /* 0.8us ticks */ 00108 signed short TFCTotal; /* Transient fuel correction */ 00109 00110 unsigned short FinalPW; /* In timer ticks of 0.8us */ 00111 unsigned short RefPW; /* In timer ticks of 0.8us */ 00112 00113 unsigned short sp1; /* */ 00114 unsigned short sp2; /* */ 00115 unsigned short sp3; /* */ 00116 unsigned short sp4; /* */ 00117 unsigned short sp5; /* */ 00118 00119 // unsigned short ; /* */ 00120 } DerivedVar; 00121 00122 00123 #define RUNTIME_VARS_SIZE sizeof(RuntimeVar) 00124 #define RUNTIME_VARS_LENGTH 13 /* How many runtime vars */ 00125 #define RUNTIME_VARS_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */ 00126 /* Use this block to manage the execution time of various functions loops and ISRs etc */ 00127 typedef struct { 00128 /* Engine position and RPM code runtimes */ 00129 unsigned short primaryInputLeadingRuntime; 00130 unsigned short primaryInputTrailingRuntime; 00131 unsigned short secondaryInputLeadingRuntime; 00132 unsigned short secondaryInputTrailingRuntime; 00133 00134 /* Mathematics runtimes */ 00135 unsigned short calcsRuntime; 00136 unsigned short genCoreVarsRuntime; 00137 unsigned short genDerivedVarsRuntime; 00138 unsigned short mathTotalRuntime; 00139 unsigned short mathSumRuntime; 00140 00141 unsigned short RTCRuntime; 00142 00143 /* */ 00144 unsigned short mainLoopRuntime; 00145 unsigned short logSendingRuntime; 00146 unsigned short serialISRRuntime; 00147 } RuntimeVar; 00148 00149 00150 #define ISR_LATENCY_VARS_SIZE sizeof(ISRLatencyVar) 00151 #define ISR_LATENCY_VARS_LENGTH 2 /* How many latency vars */ 00152 #define ISR_LATENCY_VARS_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */ 00153 /* Use this block to manage the execution time of various functions loops and ISRs etc */ 00154 typedef struct { 00155 /* Engine position and RPM code latencies */ 00156 unsigned short primaryInputLatency; 00157 unsigned short secondaryInputLatency; 00158 00159 /* Injector latencies */ 00160 unsigned short Injector1Latency; 00161 unsigned short Injector2Latency; 00162 unsigned short Injector3Latency; 00163 unsigned short Injector4Latency; 00164 unsigned short Injector5Latency; 00165 unsigned short Injector6Latency; 00166 00167 unsigned short DwellLatency; 00168 unsigned short IgniteLatency; 00169 00170 /* Not an ISR, but important none the less */ 00171 unsigned short mathLatency; 00172 unsigned short mathSampleTimeStamp0; 00173 unsigned short mathSampleTimeStamp1; 00174 } ISRLatencyVar; 00175 00176 00177 #define CORE_VARS_SIZE sizeof(CoreVar) 00178 #define CORE_VARS_LENGTH 16 /* How many arrays */ 00179 #define CORE_VARS_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */ 00180 /* Use this block to make it easy to manage the core variables */ 00181 typedef struct { 00182 /* Calculated and averaged from ADC0 readings */ 00183 unsigned short IAT; /* Inlet Air Temperature (MAT JS) : 0.0 - 655.35 (0.01 Kelvin (/100)) */ 00184 unsigned short CHT; /* Coolant / Head Temperature (CLT JS) : 0.0 - 655.35 (0.01 Kelvin (/100)) */ 00185 unsigned short TPS; /* Throttle Position Sensor (TPS JS) : 0.0 - 102.39 (0.001? % (/640)) */ 00186 unsigned short EGO; /* Exhaust Gas Oxygen (O2 JS) : 0.000 - 1.999999 (0.0001? lambda (/32768)) */ 00187 unsigned short MAP; /* Manifold Absolute Pressure (5euroh1) : 0.0 - 655.35 (0.01 kPa (/100)) */ 00188 unsigned short AAP; /* Atmospheric Absolute Pressure (6euroh1) : 0.0 - 655.35 (0.01 kPa (/100)) */ 00189 unsigned short BRV; /* Battery Reference Voltage (4euroh1) : 0.000 - 65.535 (0.001 Volts (/1000)) */ 00190 unsigned short MAT; /* Manifold Air Temperature (Spare JS) : 0.0 - 655.35 (0.01 Kelvin (/100)) */ 00191 00192 /* Calculated and averaged from ADC1 readings */ 00193 unsigned short EGO2; /* Exhaust Gas Oxygen (NC) : 0.000 - 1.999999 (0.0001? lambda (/32768)) */ 00194 unsigned short IAP; /* Intercooler Absolute Pressure (NC) : 0.0 - 655.35 (0.01 kPa (/100)) */ 00195 unsigned short MAF; /* Mass Air Flow : 0.0 - 65535.0 (raw units from lookup) */ 00196 00197 /* Calculated from MAP and TPS history */ 00198 unsigned short DMAP; /* Delta MAP kPa/second or similar */ 00199 unsigned short DTPS; /* Delta TPS %/second or similar */ 00200 00201 /* Calculated from engine position data */ 00202 unsigned short RPM; /* Revolutions Per Minute (Calced) : 0 - 32767.5 (0.5 RPM (/2)) */ 00203 unsigned short DRPM; /* Delta RPM (Calced) : 0 - 32767.5 (0.5 RPM/Second (/2)) */ 00204 unsigned short DDRPM; /* Delta Delta RPM (Calced) : 0 - 32767.5 (0.5 RPM/Second^2 (/2)) */ 00205 } CoreVar; 00206 00207 00208 #define ADC_ARRAY_SIZE sizeof(ADCArray) 00209 #define ADC_ARRAY_LENGTH 16 /* How many arrays */ 00210 #define ADC_ARRAY_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */ 00211 /* Use this block to ensure that the components are contiguous and we can then reference them via offsets and pointers */ 00212 typedef struct { 00213 /* ADC0 raw readings */ 00214 unsigned short IAT; /* Inlet Air Temperature (MAT JS) */ /* COMPULSORY! */ 00215 unsigned short CHT; /* Coolant / Head Temperature (CLT JS) */ /* COMPULSORY! */ 00216 unsigned short TPS; /* Throttle Position Sensor (TPS JS) */ /* Reduced performance without */ 00217 unsigned short EGO; /* Exhaust Gas Oxygen (O2 JS) */ /* Recommended */ 00218 unsigned short BRV; /* Battery Reference Voltage (4euroh1) */ /* COMPULSORY! */ 00219 unsigned short MAP; /* Manifold Absolute Pressure (5euroh1) */ /* COMPULSORY OR TPS OR MAF */ 00220 unsigned short AAP; /* Atmospheric Absolute Pressure (6euroh1) */ /* Recommended */ 00221 unsigned short MAT; /* Manifold Air Temperature (Spare JS) */ /* Could help heat soak issues */ 00222 00223 /* ADC1 raw readings */ 00224 unsigned short EGO2; /* Exhaust Gas Oxygen (NC) */ /* V engine option */ 00225 unsigned short IAP; /* Intercooler Absolute Pressure (NC) */ /* Turbo engine option */ 00226 unsigned short MAF; /* Mass Air Flow (NC) */ /* OEM engine option */ 00227 unsigned short SpareADC3; /* Spare ADC1 port 3 (NC) */ 00228 unsigned short SpareADC4; /* Spare ADC1 port 4 (NC) */ 00229 unsigned short SpareADC5; /* Spare ADC1 port 5 (NC) */ 00230 unsigned short SpareADC6; /* Spare ADC1 port 6 (NC) */ 00231 unsigned short SpareADC7; /* Spare ADC1 port 7 (NC) */ 00232 } ADCArray; 00233 00234 00235 #define MAINTABLE_SIZE sizeof(mainTable) 00236 #define MAINTABLE_RPM_LENGTH 24 /* How many cells on the X axis */ 00237 #define MAINTABLE_LOAD_LENGTH 19 /* How many cells on the Y axis */ 00238 #define MAINTABLE_MAX_RPM_LENGTH 27 /* How many cells on the X axis max */ 00239 #define MAINTABLE_MAX_LOAD_LENGTH 21 /* How many cells on the Y axis max */ 00240 #define MAINTABLE_MAX_MAIN_LENGTH 462 /* 924B 462 shorts maximum main table length */ 00241 00242 00276 typedef struct { 00277 unsigned short RPMLength; /* The length of the RPM axis array */ 00278 unsigned short LoadLength; /* The length of the Load axis array */ 00279 unsigned short RPM[MAINTABLE_MAX_RPM_LENGTH]; /* The array of RPM (X) axis values */ 00280 unsigned short Load[MAINTABLE_MAX_LOAD_LENGTH]; /* The array of Load (Y) axis values */ 00281 unsigned short Table[MAINTABLE_MAX_MAIN_LENGTH]; /* The table as an array of values */ 00282 } mainTable; 00283 00284 00285 #define TWODTABLEUS_SIZE sizeof(twoDTableUS) 00286 #define TWODTABLEUS_LENGTH 16 00287 /* This block used for various curves */ 00288 typedef struct { 00289 unsigned short Axis[TWODTABLEUS_LENGTH]; 00290 unsigned short Values[TWODTABLEUS_LENGTH]; 00291 } twoDTableUS; 00292 00293 00294 #define TWODTABLESS_SIZE sizeof(twoDTableSS) 00295 #define TWODTABLESS_LENGTH 16 00296 /* This block used for various curves */ 00297 typedef struct { 00298 signed short Axis[TWODTABLESS_LENGTH]; 00299 signed short Values[TWODTABLESS_LENGTH]; 00300 } twoDTableSS; 00301 00302 00303 #define TWODTABLEMS_SIZE sizeof(twoDTableMS) 00304 #define TWODTABLEMS_LENGTH 16 00305 /* This block used for various curves */ 00306 typedef struct { 00307 unsigned short Axis[TWODTABLEMS_LENGTH]; 00308 signed short Values[TWODTABLEMS_LENGTH]; 00309 } twoDTableMS; 00310 00311 00312 #define TWODTABLEUC_SIZE sizeof(twoDTableUC) 00313 #define TWODTABLEUC_LENGTH 8 00314 /* This block used for various curves */ 00315 typedef struct { 00316 unsigned char Axis[TWODTABLEUC_LENGTH]; 00317 unsigned char Values[TWODTABLEUC_LENGTH]; 00318 } twoDTableUC; 00319 00320 00321 #define COUNTER_SIZE sizeof(Counter) 00322 #define COUNTER_LENGTH 21 /* How many counters */ 00323 #define COUNTER_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */ 00324 /* Use this block to manage the execution count of various functions loops and ISRs etc */ 00325 typedef struct { 00326 /* Event Counters (all require init to zero) */ 00327 unsigned short callsToUISRs; /* Counter to ensure we aren't accidentally triggering unused ISRs */ 00328 unsigned short lowVoltageConditions; /* Counter for low voltage conditions */ 00329 00330 unsigned short crankSyncLosses; /* Counter for number of lost crank syncs */ 00331 unsigned short camSyncLosses; /* Counter for number of lost cam syncs */ 00332 unsigned short RPMValidityLosses; /* Counter for number of lost RPM validity events */ 00333 unsigned short primaryTeethDroppedFromLackOfSync; /* Counter for number of primary teeth dropped due to no primary sync */ 00334 // TODO remove the one above this line about teeth dropped???? probably... 00335 00336 unsigned short primaryTeethSeen; /* Free running counters for number of teeth seen such that... */ 00337 unsigned short secondaryTeethSeen; /* ...tooth timing can be used to reconstruct the signal at lower rpm */ 00338 00339 unsigned short syncedADCreadings; /* Incremented each time a syncronous ADC reading is taken */ 00340 unsigned short timeoutADCreadings; /* Incremented for each ADC reading in RTC because of timeout */ 00341 00342 unsigned short calculationsPerformed; /* Incremented for each time the fuel and ign calcs are done */ 00343 unsigned short datalogsSent; /* Incremented for each time we send out a log entry */ 00344 00345 /* UART/serial specific counters */ 00346 unsigned short serialStartsInsideAPacket; /* Incremented when a start byte is found inside a packet */ 00347 unsigned short serialEscapePairMismatches; /* Incremented when an escape is found but not followed by an escapee */ 00348 unsigned short serialPacketsOverLength; /* Incremented when the buffer fills up before the end */ 00349 unsigned short serialNoiseErrors; /* Incremented when noise is detected */ 00350 unsigned short serialOverrunErrors; /* Incremented when an overrun occurs */ 00351 unsigned short serialFramingErrors; /* Incremented when a framing error occurs */ 00352 unsigned short serialParityErrors; /* Incremented when a parity error occurs */ 00353 00354 /* Generic com counters */ 00355 unsigned short commsChecksumMismatches; /* Incremented when calculated checksum did not match the received one */ 00356 unsigned short commsDebugMessagesNotSent; /* Incremented when a debug message can't be sent due to the TX buffer */ 00357 unsigned short commsErrorMessagesNotSent; /* Incremented when an error message can't be sent due to the TX buffer */ 00358 } Counter; 00359 00360 00361 #define CLOCK_SIZE sizeof(Clock) 00362 #define CLOCK_LENGTH 9 /* How many clocks */ 00363 #define CLOCK_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */ 00364 /* Use this block to manage the various clocks kept */ 00365 typedef struct { 00366 /* Real Time and other Clocks (all require init to zero) */ 00367 unsigned short realTimeClockMain; /* Variable to count RTI executions, 0.125ms exactly */ 00368 unsigned short realTimeClockMillis; /* Variable to count milliseconds exactly */ 00369 unsigned short realTimeClockTenths; /* Variable to count tenths of a second exactly */ 00370 unsigned short realTimeClockSeconds; /* Variable to count seconds exactly */ 00371 unsigned short realTimeClockMinutes; /* Variable to count minutes exactly */ 00372 00373 unsigned short millisToTenths; /* Rollover variable for counting tenths */ 00374 unsigned short tenthsToSeconds; /* Rollover variable for counting seconds */ 00375 unsigned short secondsToMinutes; /* Rollover variable for counting minutes */ 00376 00377 unsigned short timeoutADCreadingClock; /* Timeout clock/counter for synced ADC readings */ 00378 } Clock; 00379 00380 00381 #else 00382 /* let us know if we are being untidy with headers */ 00383 #warning "Header file STRUCTS_H seen before, sort it out!" 00384 /* end of the wrapper ifdef from the very top */ 00385 #endif