Speeduino
Loading...
Searching...
No Matches
auxiliaries.h
Go to the documentation of this file.
1#ifndef AUX_H
2#define AUX_H
3
4#include BOARD_H //Note that this is not a real file, it is defined in globals.h.
5
6#include <SimplyAtomic.h>
7
8void initialiseAuxPWM(void);
9void boostControl(void);
10void boostDisable(void);
11void boostByGear(void);
12void vvtControl(void);
13void initialiseFan(void);
14void initialiseAirCon(void);
15void nitrousControl(void);
16void fanControl(void);
17void airConControl(void);
18bool READ_AIRCON_REQUEST(void);
19void wmiControl(void);
20
21#define SIMPLE_BOOST_P 1
22#define SIMPLE_BOOST_I 1
23#define SIMPLE_BOOST_D 1
24
25#if(defined(CORE_TEENSY) || defined(CORE_STM32))
26#define BOOST_PIN_LOW() (digitalWrite(pinBoost, LOW))
27#define BOOST_PIN_HIGH() (digitalWrite(pinBoost, HIGH))
28#define VVT1_PIN_LOW() (digitalWrite(pinVVT_1, LOW))
29#define VVT1_PIN_HIGH() (digitalWrite(pinVVT_1, HIGH))
30#define VVT2_PIN_LOW() (digitalWrite(pinVVT_2, LOW))
31#define VVT2_PIN_HIGH() (digitalWrite(pinVVT_2, HIGH))
32#define FAN_PIN_LOW() (digitalWrite(pinFan, LOW))
33#define FAN_PIN_HIGH() (digitalWrite(pinFan, HIGH))
34#define N2O_STAGE1_PIN_LOW() (digitalWrite(configPage10.n2o_stage1_pin, LOW))
35#define N2O_STAGE1_PIN_HIGH() (digitalWrite(configPage10.n2o_stage1_pin, HIGH))
36#define N2O_STAGE2_PIN_LOW() (digitalWrite(configPage10.n2o_stage2_pin, LOW))
37#define N2O_STAGE2_PIN_HIGH() (digitalWrite(configPage10.n2o_stage2_pin, HIGH))
38#define AIRCON_PIN_LOW() (digitalWrite(pinAirConComp, LOW))
39#define AIRCON_PIN_HIGH() (digitalWrite(pinAirConComp, HIGH))
40#define AIRCON_FAN_PIN_LOW() (digitalWrite(pinAirConFan, LOW))
41#define AIRCON_FAN_PIN_HIGH() (digitalWrite(pinAirConFan, HIGH))
42#define FUEL_PUMP_ON() (digitalWrite(pinFuelPump, HIGH))
43#define FUEL_PUMP_OFF() (digitalWrite(pinFuelPump, LOW))
44
45#else
46
47#define BOOST_PIN_LOW() ATOMIC() { *boost_pin_port &= ~(boost_pin_mask); }
48#define BOOST_PIN_HIGH() ATOMIC() { *boost_pin_port |= (boost_pin_mask); }
49#define VVT1_PIN_LOW() ATOMIC() { *vvt1_pin_port &= ~(vvt1_pin_mask); }
50#define VVT1_PIN_HIGH() ATOMIC() { *vvt1_pin_port |= (vvt1_pin_mask); }
51#define VVT2_PIN_LOW() ATOMIC() { *vvt2_pin_port &= ~(vvt2_pin_mask); }
52#define VVT2_PIN_HIGH() ATOMIC() { *vvt2_pin_port |= (vvt2_pin_mask); }
53#define N2O_STAGE1_PIN_LOW() ATOMIC() { *n2o_stage1_pin_port &= ~(n2o_stage1_pin_mask); }
54#define N2O_STAGE1_PIN_HIGH() ATOMIC() { *n2o_stage1_pin_port |= (n2o_stage1_pin_mask); }
55#define N2O_STAGE2_PIN_LOW() ATOMIC() { *n2o_stage2_pin_port &= ~(n2o_stage2_pin_mask); }
56#define N2O_STAGE2_PIN_HIGH() ATOMIC() { *n2o_stage2_pin_port |= (n2o_stage2_pin_mask); }
57#define FUEL_PUMP_ON() ATOMIC() { *pump_pin_port |= (pump_pin_mask); }
58#define FUEL_PUMP_OFF() ATOMIC() { *pump_pin_port &= ~(pump_pin_mask); }
59
60//Note the below macros cannot use ATOMIC() as they are called from within ternary operators. The ATOMIC is instead placed around the ternary call below
61#define FAN_PIN_LOW() *fan_pin_port &= ~(fan_pin_mask)
62#define FAN_PIN_HIGH() *fan_pin_port |= (fan_pin_mask)
63#define AIRCON_PIN_LOW() *aircon_comp_pin_port &= ~(aircon_comp_pin_mask)
64#define AIRCON_PIN_HIGH() *aircon_comp_pin_port |= (aircon_comp_pin_mask)
65#define AIRCON_FAN_PIN_LOW() *aircon_fan_pin_port &= ~(aircon_fan_pin_mask)
66#define AIRCON_FAN_PIN_HIGH() *aircon_fan_pin_port |= (aircon_fan_pin_mask)
67
68#endif
69
70#define AIRCON_ON() ATOMIC() { ((((configPage15.airConCompPol)==1)) ? AIRCON_PIN_LOW() : AIRCON_PIN_HIGH()); BIT_SET(currentStatus.airConStatus, BIT_AIRCON_COMPRESSOR); }
71#define AIRCON_OFF() ATOMIC() { ((((configPage15.airConCompPol)==1)) ? AIRCON_PIN_HIGH() : AIRCON_PIN_LOW()); BIT_CLEAR(currentStatus.airConStatus, BIT_AIRCON_COMPRESSOR); }
72#define AIRCON_FAN_ON() ATOMIC() { ((((configPage15.airConFanPol)==1)) ? AIRCON_FAN_PIN_LOW() : AIRCON_FAN_PIN_HIGH()); BIT_SET(currentStatus.airConStatus, BIT_AIRCON_FAN); }
73#define AIRCON_FAN_OFF() ATOMIC() { ((((configPage15.airConFanPol)==1)) ? AIRCON_FAN_PIN_HIGH() : AIRCON_FAN_PIN_LOW()); BIT_CLEAR(currentStatus.airConStatus, BIT_AIRCON_FAN); }
74
75#define FAN_ON() ATOMIC() { ((configPage6.fanInv) ? FAN_PIN_LOW() : FAN_PIN_HIGH()); }
76#define FAN_OFF() ATOMIC() { ((configPage6.fanInv) ? FAN_PIN_HIGH() : FAN_PIN_LOW()); }
77
78#define READ_N2O_ARM_PIN() ((*n2o_arming_pin_port & n2o_arming_pin_mask) ? true : false)
79
80#define VVT1_PIN_ON() VVT1_PIN_HIGH();
81#define VVT1_PIN_OFF() VVT1_PIN_LOW();
82#define VVT2_PIN_ON() VVT2_PIN_HIGH();
83#define VVT2_PIN_OFF() VVT2_PIN_LOW();
84#define VVT_TIME_DELAY_MULTIPLIER 50
85
86#define WMI_TANK_IS_EMPTY() ((configPage10.wmiEmptyEnabled) ? ((configPage10.wmiEmptyPolarity) ? digitalRead(pinWMIEmpty) : !digitalRead(pinWMIEmpty)) : 1)
87
88extern volatile PORT_TYPE *vvt1_pin_port;
89extern volatile PINMASK_TYPE vvt1_pin_mask;
90extern volatile PORT_TYPE *vvt2_pin_port;
91extern volatile PINMASK_TYPE vvt2_pin_mask;
92extern volatile PORT_TYPE *fan_pin_port;
93extern volatile PINMASK_TYPE fan_pin_mask;
94
95#if defined(PWM_FAN_AVAILABLE)//PWM fan not available on Arduino MEGA
96extern uint16_t fan_pwm_max_count; //Used for variable PWM frequency
97void fanInterrupt(void);
98#endif
99
100extern uint16_t vvt_pwm_max_count; //Used for variable PWM frequency
101extern uint16_t boost_pwm_max_count; //Used for variable PWM frequency
102
103void boostInterrupt(void);
104void vvtInterrupt(void);
105
106#endif
volatile PORT_TYPE * fan_pin_port
Definition auxiliaries.cpp:47
void initialiseAirCon(void)
Definition auxiliaries.cpp:88
void initialiseFan(void)
Definition auxiliaries.cpp:315
void vvtInterrupt(void)
Definition auxiliaries.cpp:1146
volatile PINMASK_TYPE vvt1_pin_mask
Definition auxiliaries.cpp:44
uint16_t vvt_pwm_max_count
Definition auxiliaries.cpp:72
void vvtControl(void)
Definition auxiliaries.cpp:779
volatile PINMASK_TYPE vvt2_pin_mask
Definition auxiliaries.cpp:46
void airConControl(void)
Definition auxiliaries.cpp:137
void boostControl(void)
Definition auxiliaries.cpp:682
volatile PORT_TYPE * vvt2_pin_port
Definition auxiliaries.cpp:45
void wmiControl(void)
Definition auxiliaries.cpp:1032
bool READ_AIRCON_REQUEST(void)
Definition auxiliaries.cpp:213
void fanControl(void)
Definition auxiliaries.cpp:335
volatile PINMASK_TYPE fan_pin_mask
Definition auxiliaries.cpp:48
volatile PORT_TYPE * vvt1_pin_port
Definition auxiliaries.cpp:43
void initialiseAuxPWM(void)
Definition auxiliaries.cpp:448
void nitrousControl(void)
Definition auxiliaries.cpp:975
uint16_t boost_pwm_max_count
Definition auxiliaries.cpp:73
void boostByGear(void)
Definition auxiliaries.cpp:542
void boostInterrupt(void)
Definition auxiliaries.cpp:1116
void boostDisable(void)
Definition auxiliaries.cpp:1104