GCC Code Coverage Report


Directory: ./
File: firmware/controllers/algo/engine_cylinder.cpp
Date: 2025-11-16 14:52:24
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 5672 void OneCylinder::updateCylinderNumber(uint8_t index, uint8_t cylinderNumber) {
11 5672 m_cylinderIndex = index;
12 5672 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 5672 m_baseAngleOffset = engine->engineState.engineCycle * index / engineConfiguration->cylindersCount;
17
18 5672 m_valid = true;
19 5672 }
20
21 12412 void OneCylinder::invalidCylinder() {
22 12412 m_valid = false;
23 12412 }
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 1507 void EngineCylinders::updateCylinders() {
41 // Update valid cylinders with their position in the firing order
42 1507 uint16_t cylinderUpdateMask = 0;
43
2/2
✓ Branch 0 taken 5672 times.
✓ Branch 1 taken 1507 times.
2/2
✓ Decision 'true' taken 5672 times.
✓ Decision 'false' taken 1507 times.
7179 for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) {
44 5672 auto cylinderNumber = getCylinderNumberAtIndex(i);
45
46 5672 engine->cylinders[cylinderNumber].updateCylinderNumber(i, cylinderNumber);
47
48 5672 auto mask = 1 << cylinderNumber;
49 // Assert that this cylinder was not configured yet
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5672 times.
5672 efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, (cylinderUpdateMask & mask) == 0, "cylinder update err");
51 5672 cylinderUpdateMask |= mask;
52 }
53
54 // Assert that all cylinders were configured
55 1507 uint16_t expectedMask = (1 << (engineConfiguration->cylindersCount)) - 1;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1507 times.
1507 efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, cylinderUpdateMask == expectedMask, "cylinder update err");
57
58 // Invalidate the remaining cylinders
59
2/2
✓ Branch 1 taken 12412 times.
✓ Branch 2 taken 1507 times.
2/2
✓ Decision 'true' taken 12412 times.
✓ Decision 'false' taken 1507 times.
13919 for (size_t i = engineConfiguration->cylindersCount; i < efi::size(engine->cylinders); i++) {
60 12412 engine->cylinders[i].invalidCylinder();
61 }
62 }
63