GCC Code Coverage Report


Directory: ./
File: firmware/controllers/algo/engine_cylinder.cpp
Date: 2025-12-30 16:19:43
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 5664 void OneCylinder::updateCylinderNumber(uint8_t index, uint8_t cylinderNumber) {
11 5664 m_cylinderIndex = index;
12 5664 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 5664 m_baseAngleOffset = engine->engineState.engineCycle * index / engineConfiguration->cylindersCount;
17
18 5664 m_valid = true;
19 5664 }
20
21 12396 void OneCylinder::invalidCylinder() {
22 12396 m_valid = false;
23 12396 }
24
25 352904 angle_t OneCylinder::getAngleOffset() const {
26
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 352903 times.
2/2
✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 352903 times.
352904 if (!m_valid) {
27 1 return 0;
28 }
29
30 // Plus or minus any adjustment if this is an odd-fire engine
31 352903 auto adjustment = engineConfiguration->timing_offset_cylinder[m_cylinderNumber];
32
33 352903 auto result = m_baseAngleOffset + adjustment;
34
35
2/4
✓ Branch 0 taken 352903 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 352903 times.
352903 assertAngleRange(result, "getAngleOffset", ObdCode::CUSTOM_ERR_CYL_ANGLE);
36
37 352903 return result;
38 }
39
40 1505 void EngineCylinders::updateCylinders() {
41 // Update valid cylinders with their position in the firing order
42 1505 uint16_t cylinderUpdateMask = 0;
43
2/2
✓ Branch 0 taken 5664 times.
✓ Branch 1 taken 1505 times.
2/2
✓ Decision 'true' taken 5664 times.
✓ Decision 'false' taken 1505 times.
7169 for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) {
44 5664 auto cylinderNumber = getCylinderNumberAtIndex(i);
45
46 5664 engine->cylinders[cylinderNumber].updateCylinderNumber(i, cylinderNumber);
47
48 5664 auto mask = 1 << cylinderNumber;
49 // Assert that this cylinder was not configured yet
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5664 times.
5664 efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, (cylinderUpdateMask & mask) == 0, "cylinder update err");
51 5664 cylinderUpdateMask |= mask;
52 }
53
54 // Assert that all cylinders were configured
55 1505 uint16_t expectedMask = (1 << (engineConfiguration->cylindersCount)) - 1;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1505 times.
1505 efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, cylinderUpdateMask == expectedMask, "cylinder update err");
57
58 // Invalidate the remaining cylinders
59
2/2
✓ Branch 1 taken 12396 times.
✓ Branch 2 taken 1505 times.
2/2
✓ Decision 'true' taken 12396 times.
✓ Decision 'false' taken 1505 times.
13901 for (size_t i = engineConfiguration->cylindersCount; i < efi::size(engine->cylinders); i++) {
60 12396 engine->cylinders[i].invalidCylinder();
61 }
62 }
63