GCC Code Coverage Report


Directory: ./
File: firmware/controllers/algo/engine_cylinder.cpp
Date: 2025-10-24 14:26:41
Coverage Exec Excl Total
Lines: 100.0% 28 0 28
Functions: 100.0% 4 0 4
Branches: 71.4% 10 0 14
Decisions: 100.0% 6 - 6

Line Branch Decision Exec Source
1 /*
2 * @file engine_cylinder.cpp
3 *
4 * @date: may 25, 2025
5 * @author Matthew Kennedy, FDSoftware
6 */
7 #include "pch.h"
8 #include "engine_cylinder.hpp"
9
10 5624 void OneCylinder::updateCylinderNumber(uint8_t index, uint8_t cylinderNumber) {
11 5624 m_cylinderIndex = index;
12 5624 m_cylinderNumber = cylinderNumber;
13
14 // base = position of this cylinder in the firing order.
15 // We get a cylinder every n-th of an engine cycle where N is the number of cylinders
16 5624 m_baseAngleOffset = engine->engineState.engineCycle * index / engineConfiguration->cylindersCount;
17
18 5624 m_valid = true;
19 5624 }
20
21 12316 void OneCylinder::invalidCylinder() {
22 12316 m_valid = false;
23 12316 }
24
25 4456 angle_t OneCylinder::getAngleOffset() const {
26
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 4455 times.
2/2
✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 4455 times.
4456 if (!m_valid) {
27 1 return 0;
28 }
29
30 // Plus or minus any adjustment if this is an odd-fire engine
31 4455 auto adjustment = engineConfiguration->timing_offset_cylinder[m_cylinderNumber];
32
33 4455 auto result = m_baseAngleOffset + adjustment;
34
35
2/4
✓ Branch 0 taken 4455 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4455 times.
4455 assertAngleRange(result, "getAngleOffset", ObdCode::CUSTOM_ERR_CYL_ANGLE);
36
37 4455 return result;
38 }
39
40 1495 void EngineCylinders::updateCylinders() {
41 // Update valid cylinders with their position in the firing order
42 1495 uint16_t cylinderUpdateMask = 0;
43
2/2
✓ Branch 0 taken 5624 times.
✓ Branch 1 taken 1495 times.
2/2
✓ Decision 'true' taken 5624 times.
✓ Decision 'false' taken 1495 times.
7119 for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) {
44 5624 auto cylinderNumber = getCylinderNumberAtIndex(i);
45
46 5624 engine->cylinders[cylinderNumber].updateCylinderNumber(i, cylinderNumber);
47
48 5624 auto mask = 1 << cylinderNumber;
49 // Assert that this cylinder was not configured yet
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5624 times.
5624 efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, (cylinderUpdateMask & mask) == 0, "cylinder update err");
51 5624 cylinderUpdateMask |= mask;
52 }
53
54 // Assert that all cylinders were configured
55 1495 uint16_t expectedMask = (1 << (engineConfiguration->cylindersCount)) - 1;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1495 times.
1495 efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, cylinderUpdateMask == expectedMask, "cylinder update err");
57
58 // Invalidate the remaining cylinders
59
2/2
✓ Branch 1 taken 12316 times.
✓ Branch 2 taken 1495 times.
2/2
✓ Decision 'true' taken 12316 times.
✓ Decision 'false' taken 1495 times.
13811 for (size_t i = engineConfiguration->cylindersCount; i < efi::size(engine->cylinders); i++) {
60 12316 engine->cylinders[i].invalidCylinder();
61 }
62 }
63