GCC Code Coverage Report


Directory: ./
File: firmware/config/engines/harley.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 37 0 37
Functions: 100.0% 2 0 2
Branches: 100.0% 2 0 2
Decisions: 100.0% 2 - 2

Line Branch Decision Exec Source
1 #include "pch.h"
2 #include "proteus_meta.h"
3 #include "harley_canned.cpp"
4 #include "harley.h"
5
6 9 static void harleyEngine() {
7 9 engineConfiguration->cylindersCount = 2;
8 9 engineConfiguration->firingOrder = FO_1_2;
9 9 strcpy(engineConfiguration->engineMake, "Harley");
10 9 }
11
12 /**
13 * HARLEY
14 * set engine_type 6
15 */
16 9 void setHarley() {
17 9 harleyEngine();
18 9 engineConfiguration->displacement = 1.9;
19 9 engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS;
20 9 engineConfiguration->injectionMode = IM_SEQUENTIAL;
21
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 9 times.
2/2
✓ Decision 'true' taken 90 times.
✓ Decision 'false' taken 9 times.
99 for (size_t i = engineConfiguration->cylindersCount;i < MAX_CYLINDER_COUNT;i++) {
22 90 engineConfiguration->injectionPins[i] = Gpio::Unassigned;
23 90 engineConfiguration->ignitionPins[i] = Gpio::Unassigned;
24 }
25
26 9 strcpy(engineConfiguration->scriptSettingName[0], "compReleaseRpm");
27 9 engineConfiguration->scriptSetting[0] = 300;
28 9 strcpy(engineConfiguration->scriptSettingName[1], "compReleaseDur");
29 9 engineConfiguration->scriptSetting[1] = 5000;
30 9 engineConfiguration->afr.hwChannel = EFI_ADC_NONE;
31 9 engineConfiguration->enableAemXSeries = true;
32
33 // total 45 degree odd fire, split across two cylinders mostly for fun
34 9 engineConfiguration->timing_offset_cylinder[0] = -HARLEY_V_TWIN / 2;
35 9 engineConfiguration->timing_offset_cylinder[1] = +HARLEY_V_TWIN / 2;
36
37 // work-around for https://github.com/rusefi/rusefi/issues/5894 todo: fix it!
38 9 engineConfiguration->maximumIgnitionTiming = 90;
39 9 engineConfiguration->minimumIgnitionTiming = -90;
40
41 9 engineConfiguration->trigger.type = trigger_type_e::TT_TOOTHED_WHEEL_32_2;
42 9 engineConfiguration->overrideTriggerGaps = true;
43 9 engineConfiguration->gapTrackingLengthOverride = 3;
44 9 engineConfiguration->triggerGapOverrideFrom[0] = 0.75;
45 9 engineConfiguration->triggerGapOverrideTo[0] = 1.25;
46 9 engineConfiguration->triggerGapOverrideFrom[1] = 0.05; // this one is custom
47 9 engineConfiguration->triggerGapOverrideTo[1] = 0.5;
48 9 engineConfiguration->triggerGapOverrideFrom[2] = 1.850; // this one is custom
49 9 engineConfiguration->triggerGapOverrideTo[2] = 6;
50
51 9 engineConfiguration->vvtMode[0] = VVT_MAP_V_TWIN;
52
53 9 engineConfiguration->mainRelayPin = Gpio::Unassigned;
54 9 engineConfiguration->mapCamDetectionAnglePosition = 50;
55
56 9 setCustomMap(/*lowValue*/ 20, /*mapLowValueVoltage*/ 0.79, /*highValue*/ 101.3, /*mapHighValueVoltage*/ 4);
57
58 #if HW_PROTEUS && EFI_PROD_CODE
59 engineConfiguration->acrPin = Gpio::PROTEUS_IGN_8;
60 engineConfiguration->acrPin2 = Gpio::PROTEUS_IGN_9;
61
62 engineConfiguration->triggerInputPins[0] = PROTEUS_VR_1;
63 // for now we need non wired camInput to keep TS field enable/disable logic happy
64 #if EFI_PROD_CODE
65 engineConfiguration->camInputs[0] = PROTEUS_DIGITAL_6;
66 #else
67 engineConfiguration->camInputs[0] = Gpio::Unassigned;
68 #endif
69
70 engineConfiguration->luaOutputPins[0] = Gpio::PROTEUS_LS_12;
71
72 setTPS1Inputs(PROTEUS_IN_TPS, PROTEUS_IN_TPS1_2);
73
74 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_5);
75
76
77 strncpy(config->luaScript, R"(
78 --outputIndex = 0
79 --startPwm(outputIndex, 100, 0)
80
81 rpmLimitSetting = findSetting("compReleaseRpm", 300)
82 compReleaseDulationLimit = findSetting("compReleaseDur", 6000)
83
84 every200msTimer = Timer.new();
85 everySecondTimer = Timer.new();
86 every50msTimer = Timer.new();
87 offCounter = 0
88 -- cranking!
89 packet542 = {0x20, 0x82, 0x81, 0xd9, 0x00, 0x00, 0x00, 0x00}
90 packet543 = {0x13, 0x57, 0x13, 0x45, 0x00, 0xe8, 0x00, 0x00}
91 packet541 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0xFF}
92
93 -- every 200ms
94 packet540 = {0x00, 0x00, 0x5a, 0x4c, 0xff, 0x00, 0x00, 0x00}
95
96 -- every 1000ms
97 packet502 = {0x01}
98 packet546 = {0x35, 0x48, 0x44, 0x31, 0x46, 0x48}
99 packet547 = {0x50, 0x41, 0x31, 0x4b, 0x42, 0x36}
100 packet548 = {0x33, 0x34, 0x38, 0x32, 0x32, 0x00}
101
102 counter543 = 0;
103 setTickRate(66);
104
105 canRxAdd(0x570)
106 canRxAdd(0x500)
107
108 function onCanRx(bus, id, dlc, data)
109 --print('got CAN id=' .. id .. ' dlc=' .. dlc)
110
111 if id == 0x500 then --Check can state of BCM
112 canState = data[1]
113 if canState == 01 then
114 packet502[1] = 0x01
115 else
116 packet502[1] = 0x00
117 end
118 if id == 0x570 then
119 curState = data[1]
120 if curState == 06 then -- Cranking TODO: MUST ONLY DO THIS ON RPM TILL STARt
121 packet542[2] = 0x82
122 end
123 if curState == 04 then -- Kill off
124 packet542[2] = 0x82
125 end
126 if curState == 01 then -- Kill
127 packet542[2] = 0xA2
128 end
129 end
130 end
131 end
132
133
134 function onTick()
135
136 if packet502[1] == 01 then
137 offCounter = 0
138 counter543 = (counter543 + 1) % 64
139 packet543[7] = 64 + counter543
140 packet543[8] = crc8_j1850(packet543, 7)
141 APP = getSensor("AcceleratorPedal")
142 if APP == nil then
143 packet543[5] = 0
144 else
145 packet543[5] = APP *2
146 end
147
148 txCan(1, 0x543, 0, packet543)
149 txCan(1, 0x541, 0, packet541)
150
151 if every200msTimer:getElapsedSeconds() > 0.2 then
152 every200msTimer:reset();
153 txCan(1, 0x540, 0, packet540)
154 end
155
156 if every50msTimer:getElapsedSeconds() > 0.05 then
157 every50msTimer:reset();
158 txCan(1, 0x542, 0, packet542)
159 end
160
161 if everySecondTimer:getElapsedSeconds() > 1 then
162 everySecondTimer:reset();
163 txCan(1, 0x502, 0, packet502)
164 txCan(1, 0x546, 0, packet546)
165 txCan(1, 0x547, 0, packet547)
166 txCan(1, 0x548, 0, packet548)
167 end
168
169
170 rpm = getSensor("RPM")
171 -- handle nil RPM, todo: change firmware to avoid nil RPM
172 rpm = (rpm == nil and 0 or rpm)
173 --print('Rpm ' .. rpm)
174 --print('getTimeSinceTriggerEventMs ' .. getTimeSinceTriggerEventMs())
175 enableCompressionReleaseSolenoid = getTimeSinceTriggerEventMs() < compReleaseDulationLimit and rpm < rpmLimitSetting
176 duty = enableCompressionReleaseSolenoid and 1 or 0
177 -- print("Compression release solenoid " .. duty)
178 -- setPwmDuty(outputIndex, duty)
179 else
180 if offCounter == 0 then --goodbye sweet love
181 txCan(1, 0x502, 0, packet502) --goodbye
182 offCounter = 1 --One shot
183 end
184 end
185 end
186 )", efi::size(config->luaScript));
187 #endif
188 9 }
189