Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | #include "pch.h" | |||
2 | ||||
3 | #include "init.h" | |||
4 | #include "sent.h" | |||
5 | #include "adc_subscription.h" | |||
6 | #include "functional_sensor.h" | |||
7 | #include "proxy_sensor.h" | |||
8 | #include "linear_func.h" | |||
9 | ||||
10 | static LinearFunc oilpSensorFunc; | |||
11 | static FunctionalSensor oilpSensor(SensorType::OilPressure, /* timeout = */ MS2NT(50)); | |||
12 | ||||
13 | static LinearFunc fuelPressureFuncLow; | |||
14 | static FunctionalSensor fuelPressureSensorLow(SensorType::FuelPressureLow, /* timeout = */ MS2NT(50)); | |||
15 | ||||
16 | static LinearFunc fuelPressureFuncHigh; | |||
17 | static FunctionalSensor fuelPressureSensorHigh(SensorType::FuelPressureHigh, /* timeout = */ MS2NT(50)); | |||
18 | ||||
19 | static ProxySensor injectorPressure(SensorType::FuelPressureInjector); | |||
20 | ||||
21 | static LinearFunc acPressureFunc; | |||
22 | static FunctionalSensor acPressureSensor(SensorType::AcPressure, /* timeout = */ MS2NT(50)); | |||
23 | ||||
24 | static LinearFunc auxLinear1Func; | |||
25 | static FunctionalSensor auxLinear1Sensor(SensorType::AuxLinear1, /* timeout = */ MS2NT(50)); | |||
26 | ||||
27 | static LinearFunc auxLinear2Func; | |||
28 | static FunctionalSensor auxLinear2Sensor(SensorType::AuxLinear2, /* timeout = */ MS2NT(50)); | |||
29 | ||||
30 | static LinearFunc auxLinear3Func; | |||
31 | static FunctionalSensor auxLinear3Sensor(SensorType::AuxLinear3, /* timeout = */ MS2NT(50)); | |||
32 | ||||
33 | static LinearFunc auxLinear4Func; | |||
34 | static FunctionalSensor auxLinear4Sensor(SensorType::AuxLinear4, /* timeout = */ MS2NT(50)); | |||
35 | ||||
36 | /** | |||
37 | * @param bandwidth Hertz, used by low pass filter in to analog subscribers | |||
38 | */ | |||
39 | 32 | static void initFluidPressure(LinearFunc& func, FunctionalSensor& sensor, const linear_sensor_s& cfg, float bandwidth) { | ||
40 | 32 | auto channel = cfg.hwChannel; | ||
41 | ||||
42 | // Only register if we have a sensor | |||
43 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 2 taken 1 time.
|
2/2✓ Decision 'true' taken 31 times.
✓ Decision 'false' taken 1 time.
|
32 | if (!isAdcChannelValid(channel)) { |
44 | 31 | return; | ||
45 | } | |||
46 | ||||
47 | 1 | float val1 = cfg.value1; | ||
48 | 1 | float val2 = cfg.value2; | ||
49 | ||||
50 | // Limit to max given pressure - val1 or val2 could be larger | |||
51 | // (sensor may be backwards, high voltage = low pressure) | |||
52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | float greaterOutput = val1 > val2 ? val1 : val2; | |
53 | ||||
54 | // Allow slightly negative output (-5kpa) so as to not fail the sensor when engine is off | |||
55 | 1 | func.configure(cfg.v1, val1, cfg.v2, val2, /*minOutput*/ -5, greaterOutput); | ||
56 | ||||
57 | 1 | sensor.setFunction(func); | ||
58 | ||||
59 | 1 | AdcSubscription::SubscribeSensor(sensor, channel, bandwidth); | ||
60 | ||||
61 | 1 | sensor.Register(); | ||
62 | } | |||
63 | ||||
64 | #if EFI_SENT_SUPPORT | |||
65 | ✗ | static void initSentLinearSensor(LinearFunc& func, FunctionalSensor& sensor, int in1, float out1, int in2, float out2, float min, float max) | ||
66 | { | |||
67 | ✗ | func.configure(in1, out1, in2, out2, min, max); | ||
68 | ||||
69 | ✗ | sensor.setFunction(func); | ||
70 | ||||
71 | ✗ | sensor.Register(); | ||
72 | ✗ | } | ||
73 | #endif | |||
74 | ||||
75 | 4 | void initFluidPressure() { | ||
76 | 4 | initFluidPressure(oilpSensorFunc, oilpSensor, engineConfiguration->oilPressure, 10); | ||
77 | 4 | initFluidPressure(fuelPressureFuncLow, fuelPressureSensorLow, engineConfiguration->lowPressureFuel, 10); | ||
78 | ||||
79 | #if EFI_SENT_SUPPORT | |||
80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 4 times.
|
4 | if ((engineConfiguration->FuelHighPressureSentType != SentFuelHighPressureType::NONE) && |
81 | ✗ | (engineConfiguration->FuelHighPressureSentInput != SentInput::NONE)) { | ||
82 | ✗ | if (engineConfiguration->FuelHighPressureSentType == SentFuelHighPressureType::GM_TYPE) { | ||
83 | /* This sensor sends two pressure signals: | |||
84 | * Sig0 occupies 3 first nibbles | |||
85 | * Sig1 occupies next 3 nibbles | |||
86 | * Signals are close, but not identical. | |||
87 | * Sig0 shows about 197..198 at 1 Atm (open air) and 282 at 1000 KPa (10 Bar) | |||
88 | * Sig1 shows abour 202..203 at 1 Atm (open air) and 283 at 1000 KPa (10 Bar) | |||
89 | */ | |||
90 | ✗ | initSentLinearSensor(fuelPressureFuncHigh, fuelPressureSensorHigh, | ||
91 | 200, BAR2KPA(1), | |||
92 | 283, BAR2KPA(10), | |||
93 | BAR2KPA(0), BAR2KPA(1000) /* What is limit of this sensor? */); | |||
94 | } | |||
95 | } else | |||
96 | #endif | |||
97 | { | |||
98 | 4 | initFluidPressure(fuelPressureFuncHigh, fuelPressureSensorHigh, engineConfiguration->highPressureFuel, 100); | ||
99 | } | |||
100 | 4 | initFluidPressure(acPressureFunc, acPressureSensor, engineConfiguration->acPressure, 10); | ||
101 | 4 | initFluidPressure(auxLinear1Func, auxLinear1Sensor, engineConfiguration->auxLinear1, 10); | ||
102 | 4 | initFluidPressure(auxLinear2Func, auxLinear2Sensor, engineConfiguration->auxLinear2, 10); | ||
103 | 4 | initFluidPressure(auxLinear3Func, auxLinear3Sensor, engineConfiguration->auxLinear3, 10); | ||
104 | 4 | initFluidPressure(auxLinear4Func, auxLinear4Sensor, engineConfiguration->auxLinear4, 10); | ||
105 | ||||
106 | 4 | injectorPressure.setProxiedSensor( | ||
107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | engineConfiguration->injectorPressureType == IPT_High | |
108 | ? SensorType::FuelPressureHigh | |||
109 | : SensorType::FuelPressureLow | |||
110 | ); | |||
111 | ||||
112 | 4 | injectorPressure.Register(); | ||
113 | 4 | } | ||
114 | ||||
115 | ✗ | void deinitFluidPressure() { | ||
116 | ✗ | AdcSubscription::UnsubscribeSensor(oilpSensor, engineConfiguration->oilPressure.hwChannel); | ||
117 | ✗ | AdcSubscription::UnsubscribeSensor(fuelPressureSensorLow, engineConfiguration->lowPressureFuel.hwChannel); | ||
118 | ✗ | AdcSubscription::UnsubscribeSensor(fuelPressureSensorHigh, engineConfiguration->highPressureFuel.hwChannel); | ||
119 | ✗ | AdcSubscription::UnsubscribeSensor(auxLinear1Sensor, engineConfiguration->auxLinear1.hwChannel); | ||
120 | ✗ | AdcSubscription::UnsubscribeSensor(auxLinear2Sensor, engineConfiguration->auxLinear2.hwChannel); | ||
121 | ✗ | AdcSubscription::UnsubscribeSensor(auxLinear3Sensor, engineConfiguration->auxLinear3.hwChannel); | ||
122 | ✗ | AdcSubscription::UnsubscribeSensor(auxLinear4Sensor, engineConfiguration->auxLinear4.hwChannel); | ||
123 | ✗ | } | ||
124 | ||||
125 | #if EFI_PROD_CODE | |||
126 | #if EFI_SENT_SUPPORT | |||
127 | /* init_ file is not correct place for following code, but pressure sensor is defined here and static */ | |||
128 | /* TODO: move? */ | |||
129 | ||||
130 | void sentPressureDecode(SentInput sentCh) { | |||
131 | if (engineConfiguration->FuelHighPressureSentInput != sentCh) { | |||
132 | return; | |||
133 | } | |||
134 | ||||
135 | if (engineConfiguration->FuelHighPressureSentType == SentFuelHighPressureType::GM_TYPE) { | |||
136 | uint16_t sig0, sig1; | |||
137 | int ret = getSentValues(sentCh, &sig0, &sig1); | |||
138 | ||||
139 | if (ret) { | |||
140 | return; | |||
141 | } | |||
142 | ||||
143 | /* This sensor sends two pressure signals - average */ | |||
144 | fuelPressureSensorHigh.postRawValue(((float)sig0 + (float)sig1) / 2, getTimeNowNt()); | |||
145 | } | |||
146 | } | |||
147 | ||||
148 | #endif /* EFI_SENT_SUPPORT */ | |||
149 | #endif /* EFI_PROD_CODE */ | |||
150 |