GCC Code Coverage Report


Directory: ./
File: firmware/controllers/sensors/frequency_sensor.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 75.0% 15 0 20
Functions: 66.7% 2 0 3
Branches: 50.0% 4 0 8
Decisions: 50.0% 4 - 8

Line Branch Decision Exec Source
1 /**
2 * @file frequency_sensor.cpp
3 */
4
5 #include "pch.h"
6
7 #include "frequency_sensor.h"
8
9 #include "digital_input_exti.h"
10
11 #if EFI_PROD_CODE
12 // Callback adapter since we can't pass a member function to a callback
13 static void freqSensorExtiCallback(void* arg, efitick_t nowNt) {
14 reinterpret_cast<FrequencySensor*>(arg)->onEdge(nowNt);
15 }
16 #endif // EFI_PROD_CODE
17
18 11 void FrequencySensor::initIfValid(brain_pin_e pin, SensorConverter &converter, float filterParameter) {
19
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 1 time.
2/2
✓ Decision 'true' taken 10 times.
✓ Decision 'false' taken 1 time.
11 if (!isBrainPinValid(pin)) {
20 10 return;
21 }
22
23 // Filter parameter greater than or equal to 0.5 impossible as it causes filter instability, clamp
24 // far under that value.
25
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 1 time.
1 if (filterParameter > 0.35f) {
26 filterParameter = 0.35f;
27 }
28
29 1 m_filter.configureLowpass(1, filterParameter);
30
31 1 setFunction(converter);
32
33 #if EFI_PROD_CODE
34 if (efiExtiEnablePin(getSensorName(), pin, PAL_EVENT_MODE_FALLING_EDGE,
35 freqSensorExtiCallback, reinterpret_cast<void*>(this)) < 0) {
36 return;
37 }
38 #endif // EFI_PROD_CODE
39
40 1 m_pin = pin;
41
42 1 Register();
43 }
44
45 void FrequencySensor::deInit() {
46 if (!isBrainPinValid(m_pin)) {
47 return;
48 }
49
50 #if EFI_PROD_CODE
51 efiExtiDisablePin(m_pin);
52 #endif
53
54 m_pin = Gpio::Unassigned;
55 }
56
57 1000 void FrequencySensor::onEdge(efitick_t nowNt) {
58 // diagnostics
59 1000 eventCounter++;
60 1000 float frequency = 1 / m_edgeTimer.getElapsedSecondsAndReset(nowNt);
61
62
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1/2
✓ Decision 'true' taken 1000 times.
✗ Decision 'false' not taken.
1000 if (useBiQuad) {
63 1000 frequency = m_filter.filter(frequency);
64 }
65
66 1000 postRawValue(frequency, nowNt);
67 1000 }
68