GCC Code Coverage Report


Directory: ./
File: firmware/hw_layer/board_overrides.h
Date: 2025-11-16 14:52:24
Coverage Exec Excl Total
Lines: 60.0% 6 0 10
Functions: 100.0% 2 0 2
Branches: 50.0% 2 0 4
Decisions: 50.0% 2 - 4

Line Branch Decision Exec Source
1 /*
2 * @file board_overrides.h
3 * @brief Board-specific override mechanism
4 *
5 * This header provides a centralized way to define and manage board-specific overrides.
6 * Custom boards can implement their own specialized behavior by overriding these function pointers.
7 *
8 * Usage Example:
9 *
10 * 1. Define your custom function:
11 * void myBoardCustomHello() {
12 * // Your custom implementation
13 * }
14 *
15 * 2. Set up the override in your board_configuration.cpp:
16 * void setup_custom_board_overrides() {
17 * custom_board_boardSayHello = myBoardCustomHello;
18 * }
19 *
20 *
21 * @date: jul 09, 2025
22 * @author FDSoftware
23 */
24
25 #pragma once
26 #include <functional>
27 #include <optional>
28 #include "engine_configuration.h"
29
30 // function with no parameters and returning void
31 using setup_custom_board_overrides_type = void (*)();
32 using setup_custom_board_config_type = void (*)(engine_configuration_s * /*previousConfiguration*/);
33 using setup_custom_board_output_type = int (*)();
34 using setup_custom_board_engine_type_type = void (*)(engine_type_e);
35
36 // todo: migrate 'validateBoardConfig'
37 using custom_validate_config_type = bool (*)();
38
39 using setup_custom_board_ts_command_override_type = void (*)(uint16_t /*subsystem*/, uint16_t /*index*/);
40 extern std::optional<setup_custom_board_ts_command_override_type> custom_board_ts_command;
41
42 #if EFI_CAN_SUPPORT
43 #include "can_msg_tx.h"
44 using board_can_rx_type = void (*)(const size_t, const CANRxFrame &, efitick_t);
45 extern std::optional<board_can_rx_type> custom_board_can_rx;
46
47 using board_can_update_dash_type = void (*)(CanCycle cycle);
48 extern std::optional<board_can_update_dash_type> custom_board_update_dash;
49 #endif // EFI_CAN_SUPPORT
50
51 /**
52 * @brief Pre-HAL initialization override point
53 * Allows boards to perform custom initialization before HAL is initialized
54 */
55 extern std::optional<setup_custom_board_overrides_type> custom_board_preHalInit;
56
57 extern std::optional<setup_custom_board_overrides_type> custom_board_boardSayHello;
58
59 // Called before configuration is loaded
60 extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardwareEarly;
61 extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardware;
62 extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardwareExtra;
63 extern std::optional<setup_custom_board_config_type> custom_board_OnConfigurationChange;
64
65 extern std::optional<setup_custom_board_overrides_type> custom_board_BeforeTuneDefaults;
66 extern std::optional<setup_custom_board_engine_type_type> custom_board_AfterTuneDefaults;
67 extern std::optional<setup_custom_board_engine_type_type> custom_board_applyUnknownType;
68
69 extern std::optional<setup_custom_board_overrides_type> custom_board_periodicSlowCallback;
70 extern std::optional<setup_custom_board_overrides_type> custom_board_periodicFastCallback;
71
72 // Board hardware related:
73 extern std::optional<setup_custom_board_output_type> custom_board_getMetaOutputsCount;
74 extern std::optional<setup_custom_board_output_type> custom_board_getMetaLowSideOutputs;
75
76 // LTFT to VE table custom apply algo
77 extern std::optional<setup_custom_board_overrides_type> custom_board_LtftTrimToVeApply;
78
79 // specific firmware builds are meant for specific hardware. In order to provide best user experience on well-known boards sometimes we reduce user flexibility.
80 extern std::optional<setup_custom_board_overrides_type> custom_board_DefaultConfiguration;
81 extern std::optional<setup_custom_board_overrides_type> custom_board_ConfigOverrides;
82
83 /**
84 * This function checks if an override is present and calls it if available.
85 * Return true if override is present and was called
86 */
87 template<typename FuncType, typename... Args>
88 93681 static inline bool call_board_override(std::optional<FuncType> board_override, Args&&... args){
89
2/4
bool call_board_override<void (*)()>(std::optional<void (*)()>):
✗ Branch 1 not taken.
✓ Branch 2 taken 93088 times.
bool call_board_override<void (*)(engine_type_e), engine_type_e&>(std::optional<void (*)(engine_type_e)>, engine_type_e&):
✗ Branch 1 not taken.
✓ Branch 2 taken 593 times.
2/4
bool call_board_override<void (*)()>(std::optional<void (*)()>):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 93088 times.
bool call_board_override<void (*)(engine_type_e), engine_type_e&>(std::optional<void (*)(engine_type_e)>, engine_type_e&):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 593 times.
93681 if (board_override.has_value()) {
90 std::invoke(board_override.value(), std::forward<Args>(args)...);
91 return true;
92 }
93 93681 return false;
94 }
95