28#include <SimplyAtomic.h>
34#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
35 #define BOARD_MAX_DIGITAL_PINS 54
36 #define BOARD_MAX_IO_PINS 70
37 #define BOARD_MAX_ADC_PINS 15
39 #define LED_BUILTIN 13
42 #define BOARD_H "board_avr2560.h"
44 #define INJ_CHANNELS 4
47 #define IGN_CHANNELS 5
50 #if defined(__AVR_ATmega2561__)
65#elif defined(CORE_TEENSY)
66 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
68 #define BOARD_H "board_teensy35.h"
69 #elif defined(__IMXRT1062__)
71 #define BOARD_H "board_teensy41.h"
73 #define INJ_CHANNELS 8
74 #define IGN_CHANNELS 8
76#elif defined(STM32_MCU_SERIES) || defined(ARDUINO_ARCH_STM32) || defined(STM32)
77 #define BOARD_H "board_stm32_official.h"
80 #define BOARD_MAX_ADC_PINS NUM_ANALOG_INPUTS-1
81 #if defined(STM32F407xx)
82 #define INJ_CHANNELS 8
83 #define IGN_CHANNELS 8
85 #define INJ_CHANNELS 4
86 #define IGN_CHANNELS 5
88#elif defined(__SAMD21G18A__)
89 #define BOARD_H "board_samd21.h"
92 #define INJ_CHANNELS 4
93 #define IGN_CHANNELS 4
94#elif defined(__SAMC21J18A__)
95 #define BOARD_H "board_samc21.h"
98#elif defined(__SAME51J19A__)
99 #define BOARD_H "board_same51.h"
102 #define INJ_CHANNELS 8
103 #define IGN_CHANNELS 8
105 #error Incorrect board selected. Please select the correct board (Usually Mega 2560) and upload again
111#define CRANK_ANGLE_MAX (max(CRANK_ANGLE_MAX_IGN, CRANK_ANGLE_MAX_INJ))
113#define interruptSafe(c) (noInterrupts(); {c} interrupts();)
115#define MICROS_PER_SEC INT32_C(1000000)
116#define MICROS_PER_MIN INT32_C(MICROS_PER_SEC*60U)
117#define MICROS_PER_HOUR INT32_C(MICROS_PER_MIN*60U)
119#define SERIAL_PORT_PRIMARY 0
120#define SERIAL_PORT_SECONDARY 3
122#define BIT_TIMER_1HZ 0
123#define BIT_TIMER_4HZ 1
124#define BIT_TIMER_10HZ 2
125#define BIT_TIMER_15HZ 3
126#define BIT_TIMER_30HZ 4
127#define BIT_TIMER_50HZ 5
128#define BIT_TIMER_200HZ 6
129#define BIT_TIMER_1KHZ 7
132#define TOOTH_LOG_SIZE 127U
134#define TOOTH_LOG_SIZE 1U
139#define O2_CALIBRATION_PAGE 2U
140#define IAT_CALIBRATION_PAGE 1U
141#define CLT_CALIBRATION_PAGE 0U
144#define COMPOSITE_LOG_PRI 0
145#define COMPOSITE_LOG_SEC 1
146#define COMPOSITE_LOG_THIRD 2
147#define COMPOSITE_LOG_TRIG 3
148#define COMPOSITE_LOG_SYNC 4
149#define COMPOSITE_ENGINE_CYCLE 5
151#define OUTPUT_CONTROL_DIRECT 0
152#define OUTPUT_CONTROL_MC33810 10
154#define INJ1_CMD_BIT 0
155#define INJ2_CMD_BIT 1
156#define INJ3_CMD_BIT 2
157#define INJ4_CMD_BIT 3
158#define INJ5_CMD_BIT 4
159#define INJ6_CMD_BIT 5
160#define INJ7_CMD_BIT 6
161#define INJ8_CMD_BIT 7
163#define IGN1_CMD_BIT 0
164#define IGN2_CMD_BIT 1
165#define IGN3_CMD_BIT 2
166#define IGN4_CMD_BIT 3
167#define IGN5_CMD_BIT 4
168#define IGN6_CMD_BIT 5
169#define IGN7_CMD_BIT 6
170#define IGN8_CMD_BIT 7
172#define CALIBRATION_TABLE_SIZE 512
173#define CALIBRATION_TEMPERATURE_OFFSET 40
175#define OFFSET_FUELTRIM 127U
176#define OFFSET_IGNITION 40
178#define SERIAL_BUFFER_THRESHOLD 32
180#define LOGGER_CSV_SEPARATOR_SEMICOLON 0
181#define LOGGER_CSV_SEPARATOR_COMMA 1
182#define LOGGER_CSV_SEPARATOR_TAB 2
183#define LOGGER_CSV_SEPARATOR_SPACE 3
185#define LOGGER_DISABLED 0
187#define LOGGER_BINARY 2
189#define LOGGER_RATE_1HZ 0
190#define LOGGER_RATE_4HZ 1
191#define LOGGER_RATE_10HZ 2
192#define LOGGER_RATE_30HZ 3
194#define LOGGER_FILENAMING_OVERWRITE 0
195#define LOGGER_FILENAMING_DATETIME 1
196#define LOGGER_FILENAMING_SEQENTIAL 2
319#if defined(CORE_SAMD21)
The tune page structs and related defines.
volatile PINMASK_TYPE pump_pin_mask
Definition globals.cpp:93
byte pinTrigger3
the 2nd cam sensor pin
Definition globals.cpp:169
byte pinStepperEnable
Definition globals.cpp:210
volatile uint16_t ignitionCount
Definition globals.cpp:119
byte pinMC33810_2_CS
Definition globals.cpp:223
int CRANK_ANGLE_MAX_IGN
Definition globals.cpp:129
int CRANK_ANGLE_MAX_INJ
The number of crank degrees that the system track over. 360 for wasted / timed batch and 720 for sequ...
Definition globals.cpp:130
byte pinVSS
Definition globals.cpp:214
struct table2D PrimingPulseTable
4 bin Priming pulsewidth map (2D)
Definition globals.cpp:31
byte pinSpareLOut4
Definition globals.cpp:202
byte pinSpareLOut2
Definition globals.cpp:200
byte pinFuelPump
Definition globals.cpp:181
table3d6RpmLoad trimTable3d
Definition globals.h:210
byte pinSpareOut6
Definition globals.cpp:196
byte pinCoil4
Pin for coil 4.
Definition globals.cpp:160
volatile PORT_TYPE * inj7_pin_port
Definition globals.cpp:68
volatile PINMASK_TYPE ign7_pin_mask
Definition globals.cpp:86
struct table3d8RpmLoad stagingTable
8x8 fuel staging table
Definition globals.cpp:11
struct table2D flexFuelTable
6 bin flex fuel correction table for fuel adjustments (2D)
Definition globals.cpp:43
struct table2D fuelTempTable
6 bin flex fuel correction table for fuel adjustments (2D)
Definition globals.cpp:46
struct table2D flexBoostTable
6 bin flex fuel correction table for boost adjustments (2D)
Definition globals.cpp:45
byte pinTrigger2
RPM2 (Typically the Cam Sensor) pin.
Definition globals.cpp:168
volatile PORT_TYPE * inj4_pin_port
Definition globals.cpp:62
byte pinTPS
Definition globals.cpp:170
uint16_t o2Calibration_bins[32]
Definition globals.cpp:251
byte injectorOutputControl
Definition globals.cpp:155
byte maxIgnOutputs
Definition globals.cpp:137
volatile PINMASK_TYPE ign2_pin_mask
Definition globals.cpp:76
struct statuses currentStatus
Definition auxiliaries.cpp:77
trimTable3d trim5Table
6x6 Fuel trim 5 map
Definition globals.cpp:21
volatile PORT_TYPE * flex_pin_port
Definition globals.cpp:95
byte pinFan
Cooling fan output (on/off? See: auxiliaries.ino)
Definition globals.cpp:207
volatile byte TIMER_mask
Definition globals.cpp:143
struct table2D fanPWMTable
Definition globals.cpp:52
struct table2D o2CalibrationTable
Definition globals.cpp:253
trimTable3d trim3Table
6x6 Fuel trim 3 map
Definition globals.cpp:19
byte pinBat
Definition globals.cpp:178
volatile uint32_t seclx10
Definition globals.cpp:132
byte pinTachOut
Definition globals.cpp:180
volatile PINMASK_TYPE inj5_pin_mask
Definition globals.cpp:65
byte pinO2_2
Definition globals.cpp:177
volatile PINMASK_TYPE flex_pin_mask
Definition globals.cpp:96
volatile PORT_TYPE * inj1_pin_port
volatile inj*_pin_port and inj*_pin_mask vars are for the direct port manipulation of the injectors,...
Definition globals.cpp:56
volatile PORT_TYPE * tach_pin_port
Definition globals.cpp:90
byte pinVVT_2
vvt (variable valve timing) output 2
Definition globals.cpp:206
struct table3d8RpmLoad vvt2Table
8x8 vvt2 map
Definition globals.cpp:15
struct table2D iatCalibrationTable
Definition globals.cpp:250
volatile unsigned int toothHistoryIndex
Current index to toothHistory array.
Definition globals.cpp:117
trimTable3d trim4Table
6x6 Fuel trim 4 map
Definition globals.cpp:20
byte pinAirConComp
Definition globals.cpp:228
struct table2D flexAdvTable
6 bin flex fuel correction table for timing advance (2D)
Definition globals.cpp:44
volatile PORT_TYPE * inj5_pin_port
Definition globals.cpp:64
volatile PINMASK_TYPE ign6_pin_mask
Definition globals.cpp:84
unsigned long currentLoopTime
Definition globals.cpp:118
volatile PINMASK_TYPE ign4_pin_mask
Definition globals.cpp:80
byte ignitionOutputControl
Definition globals.cpp:165
byte pinAirConFan
Definition globals.cpp:229
volatile uint32_t runSecsX10
Definition globals.cpp:131
volatile PINMASK_TYPE inj8_pin_mask
Definition globals.cpp:71
#define TOOTH_LOG_SIZE
Definition globals.h:132
uint16_t fixedCrankingOverride
Definition globals.cpp:112
struct table3d16RpmLoad afrTable
16x16 afr target map
Definition globals.cpp:10
volatile PORT_TYPE * inj2_pin_port
Definition globals.cpp:58
byte pinInjector3
Output pin injector 3.
Definition globals.cpp:149
byte pinInjector2
Output pin injector 2.
Definition globals.cpp:148
struct table2D idleAdvanceTable
6 bin idle advance adjustment table based on RPM difference (2D)
Definition globals.cpp:40
volatile byte HWTest_IGN_Pulsed
Definition globals.cpp:136
byte fpPrimeTime
The time (in seconds, based on statuses::secl) that the fuel pump started priming.
Definition globals.cpp:106
struct table3d16RpmLoad ignitionTable2
16x16 ignition map
Definition globals.cpp:9
volatile PORT_TYPE * ign8_pin_port
Definition globals.cpp:87
byte pinCTPS
Definition globals.cpp:186
byte pinMAP
Definition globals.cpp:171
byte pinCoil5
Pin for coil 5.
Definition globals.cpp:161
volatile PINMASK_TYPE inj4_pin_mask
Definition globals.cpp:63
bool pinIsOutput(byte pin)
Definition globals.cpp:256
byte pinWMIEnabled
Definition globals.cpp:221
byte maxInjOutputs
Definition globals.cpp:138
byte pinResetControl
Definition globals.cpp:216
byte secondaryTriggerEdge
Definition globals.cpp:126
byte pinSpareOut5
Definition globals.cpp:195
byte pinBoost
Definition globals.cpp:204
volatile PINMASK_TYPE ign5_pin_mask
Definition globals.cpp:82
byte resetControl
resetControl needs to be here (as global) because using the config page (4) directly can prevent burn...
Definition globals.cpp:141
byte pinIdleUp
Definition globals.cpp:184
byte pinIgnBypass
Definition globals.cpp:212
byte pinSpareTemp2
Definition globals.cpp:190
byte pinSpareOut3
Definition globals.cpp:193
byte pinCoil3
Pin for coil 3.
Definition globals.cpp:159
struct table2D knockWindowStartTable
Definition globals.cpp:47
volatile PORT_TYPE * pump_pin_port
Definition globals.cpp:92
volatile byte HWTest_INJ
Definition globals.cpp:133
byte pinBaro
Definition globals.cpp:215
byte pinCoil8
Pin for coil 8.
Definition globals.cpp:164
uint8_t o2Calibration_values[32]
Definition globals.cpp:252
volatile PORT_TYPE * ign5_pin_port
Definition globals.cpp:81
byte pinCLT
Definition globals.cpp:175
struct table3d16RpmLoad fuelTable2
16x16 fuel map
Definition globals.cpp:7
byte pinLaunch
Definition globals.cpp:211
struct table2D crankingEnrichTable
4 bin cranking Enrichment map (2D)
Definition globals.cpp:32
volatile PORT_TYPE * ign7_pin_port
Definition globals.cpp:85
uint16_t iatCalibration_bins[32]
Definition globals.cpp:248
trimTable3d trim6Table
6x6 Fuel trim 6 map
Definition globals.cpp:22
byte pinEMAP
Definition globals.cpp:172
struct table2D ASECountTable
4 bin After Start duration map (2D)
Definition globals.cpp:30
byte pinO2
Definition globals.cpp:176
byte pinTrigger
RPM1 (Typically CAS=crankshaft angle sensor) pin.
Definition globals.cpp:167
struct table2D CLTAdvanceTable
6 bin ignition adjustment based on coolant temperature (2D)
Definition globals.cpp:41
byte pinInjector6
Output pin injector 6.
Definition globals.cpp:152
struct table2D dwellVCorrectionTable
6 bin dwell voltage correction (2D)
Definition globals.cpp:33
byte pinStepperDir
Definition globals.cpp:208
byte pinSpareTemp1
Definition globals.cpp:189
byte pinSpark2Input
Definition globals.cpp:188
struct table2D oilPressureProtectTable
Definition globals.cpp:49
byte pinFlex
Definition globals.cpp:213
struct table2D injectorVCorrectionTable
6 bin injector voltage correction (2D)
Definition globals.cpp:34
byte pinCoil1
Pin for coil 1.
Definition globals.cpp:157
byte pinIAT
Definition globals.cpp:174
byte pinWMIEmpty
Definition globals.cpp:219
byte pinSpareHOut2
Definition globals.cpp:198
struct config15 configPage15
Definition globals.cpp:239
struct table3d8RpmLoad wmiTable
8x8 wmi map
Definition globals.cpp:16
byte pinInjector1
Various pin numbering (Injectors, Ign outputs, CAS, Cam, Sensors. etc.) assignments.
Definition globals.cpp:147
struct config10 configPage10
Definition globals.cpp:237
volatile byte LOOP_TIMER
Definition globals.cpp:144
volatile PORT_TYPE * inj6_pin_port
Definition globals.cpp:66
volatile PORT_TYPE * triggerSec_pin_port
Definition globals.cpp:100
byte pinWMIIndicator
Definition globals.cpp:220
byte pinSpareLOut1
Definition globals.cpp:199
byte pinInjector5
Output pin injector 5.
Definition globals.cpp:151
byte pinStepperStep
Definition globals.cpp:209
volatile unsigned long timer5_overflow_count
Definition globals.cpp:110
trimTable3d trim7Table
6x6 Fuel trim 7 map
Definition globals.cpp:23
struct table2D knockWindowDurationTable
Definition globals.cpp:48
byte pinSpareLOut5
Definition globals.cpp:203
byte pinSpareOut4
Definition globals.cpp:194
byte pinIdle1
Definition globals.cpp:182
volatile PINMASK_TYPE inj6_pin_mask
Definition globals.cpp:67
volatile byte HWTest_IGN
Definition globals.cpp:135
struct table3d4RpmLoad dwellTable
4x4 Dwell map
Definition globals.cpp:25
byte pinDisplayReset
Definition globals.cpp:179
struct table2D wmiAdvTable
Definition globals.cpp:50
byte pinVVT_1
vvt (variable valve timing) output 1
Definition globals.cpp:205
struct table3d8RpmLoad boostTable
8x8 boost map
Definition globals.cpp:12
struct config9 configPage9
Definition globals.cpp:236
struct table2D rotarySplitTable
8 bin ignition split curve for rotary leading/trailing (2D)
Definition globals.cpp:42
volatile PINMASK_TYPE inj3_pin_mask
Definition globals.cpp:61
struct table2D IATDensityCorrectionTable
9 bin inlet air temperature density correction (2D)
Definition globals.cpp:36
struct table2D IATRetardTable
6 bin ignition adjustment based on inlet air temperature (2D)
Definition globals.cpp:38
struct table2D coolantProtectTable
Definition globals.cpp:51
struct table2D injectorAngleTable
4 bin injector angle curve (2D)
Definition globals.cpp:35
volatile PORT_TYPE * ign3_pin_port
Definition globals.cpp:77
uint8_t softLimitTime
Definition globals.cpp:107
struct table2D taeTable
4 bin TPS Acceleration Enrichment map (2D)
Definition globals.cpp:26
byte pinIdle2
Definition globals.cpp:183
struct table3d16RpmLoad fuelTable
16x16 fuel map
Definition globals.cpp:6
volatile PINMASK_TYPE triggerThird_pin_mask
Definition globals.cpp:103
volatile PINMASK_TYPE triggerPri_pin_mask
Definition globals.cpp:99
volatile PINMASK_TYPE triggerSec_pin_mask
Definition globals.cpp:101
volatile PORT_TYPE * inj3_pin_port
Definition globals.cpp:60
volatile PORT_TYPE * inj8_pin_port
Definition globals.cpp:70
uint16_t cltCalibration_values[32]
Definition globals.cpp:246
byte pinSpareOut1
Definition globals.cpp:191
volatile byte HWTest_INJ_Pulsed
Definition globals.cpp:134
byte pinCoil6
Pin for coil 6.
Definition globals.cpp:162
volatile uint8_t compositeLogHistory[TOOTH_LOG_SIZE]
Definition globals.cpp:116
byte pinInjector8
Output pin injector 8.
Definition globals.cpp:154
struct table2D maeTable
Definition globals.cpp:27
byte pinInjector7
Output pin injector 7.
Definition globals.cpp:153
volatile PINMASK_TYPE inj7_pin_mask
Definition globals.cpp:69
byte pinAirConRequest
Definition globals.cpp:230
struct config13 configPage13
Definition globals.cpp:238
byte pinSpareLOut3
Definition globals.cpp:201
volatile unsigned long ms_counter
Definition globals.cpp:111
byte primaryTriggerEdge
Definition globals.cpp:125
struct config6 configPage6
Definition globals.cpp:235
volatile uint16_t mainLoopCount
Definition globals.cpp:108
byte pinMAP2
Definition globals.cpp:173
byte pinSpareOut2
Definition globals.cpp:192
struct table2D idleTargetTable
10 bin idle target table for idle timing (2D)
Definition globals.cpp:39
struct config2 configPage2
Definition globals.cpp:233
byte pinMC33810_1_CS
Definition globals.cpp:222
volatile PORT_TYPE * ign2_pin_port
Definition globals.cpp:75
struct table3d8RpmLoad boostTableLookupDuty
8x8 boost map lookup table
Definition globals.cpp:13
byte pinFuel2Input
Definition globals.cpp:187
volatile PORT_TYPE * ign4_pin_port
Definition globals.cpp:79
byte pinFuelPressure
Definition globals.cpp:217
byte pinSDEnable
Definition globals.cpp:224
volatile uint32_t toothHistory[TOOTH_LOG_SIZE]
Tooth trigger history - delta time (in uS) from last tooth (Indexed by toothHistoryIndex)
Definition globals.cpp:115
volatile PINMASK_TYPE inj2_pin_mask
Definition globals.cpp:59
volatile PINMASK_TYPE ign1_pin_mask
Definition globals.cpp:74
bool pinIsUsed(byte pin)
Definition globals.cpp:311
trimTable3d trim2Table
6x6 Fuel trim 2 map
Definition globals.cpp:18
uint16_t cltCalibration_bins[32]
Definition globals.cpp:245
struct config4 configPage4
Definition globals.cpp:234
volatile PINMASK_TYPE tach_pin_mask
Definition globals.cpp:91
byte tertiaryTriggerEdge
Definition globals.cpp:127
volatile PORT_TYPE * ign6_pin_port
Definition globals.cpp:83
byte pinCoil2
Pin for coil 2.
Definition globals.cpp:158
byte pinSpareHOut1
Definition globals.cpp:197
volatile PINMASK_TYPE ign3_pin_mask
Definition globals.cpp:78
volatile PINMASK_TYPE ign8_pin_mask
Definition globals.cpp:88
byte pinOilPressure
Definition globals.cpp:218
volatile PORT_TYPE * triggerThird_pin_port
Definition globals.cpp:102
volatile PORT_TYPE * ign1_pin_port
Definition globals.cpp:73
byte pinIdleUpOutput
Definition globals.cpp:185
struct table2D WUETable
10 bin Warm Up Enrichment map (2D)
Definition globals.cpp:28
volatile PORT_TYPE * triggerPri_pin_port
Definition globals.cpp:98
byte pinInjector4
Output pin injector 4.
Definition globals.cpp:150
struct table2D cltCalibrationTable
Definition globals.cpp:247
struct table3d16RpmLoad ignitionTable
16x16 ignition map
Definition globals.cpp:8
volatile PINMASK_TYPE inj1_pin_mask
Definition globals.cpp:57
byte pinCoil7
Pin for coil 7.
Definition globals.cpp:163
trimTable3d trim1Table
6x6 Fuel trim 1 map
Definition globals.cpp:17
struct table2D rollingCutTable
Definition globals.cpp:53
uint16_t iatCalibration_values[32]
Definition globals.cpp:249
struct table2D ASETable
4 bin After Start Enrichment map (2D)
Definition globals.cpp:29
uint32_t revolutionTime
Definition globals.cpp:109
trimTable3d trim8Table
6x6 Fuel trim 8 map
Definition globals.cpp:24
struct table2D baroFuelTable
8 bin baro correction curve (2D)
Definition globals.cpp:37
struct table3d8RpmLoad vvtTable
8x8 vvt map
Definition globals.cpp:14
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:349
The statuses struct and related defines.
Definition config_pages.h:712
Definition config_pages.h:906
Definition config_pages.h:959
Definition config_pages.h:249
Definition config_pages.h:425
Definition config_pages.h:528
Definition config_pages.h:630
The status struct with current values for all 'live' variables.
Definition statuses.h:98
3D table data types and functions