Engine modules participate in the build system (#452)

* infrastructure for engine modules in the build

* fully move fuel pump

* fan

* gear detector

* gear detect

* fan control cleanup

* trip odometer

* shuffle makefiles around a little

* minor format
This commit is contained in:
Matthew Kennedy 2024-07-23 18:05:43 -07:00 committed by GitHub
parent c641a685b7
commit ff5e47c95d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
36 changed files with 86 additions and 27 deletions

5
.gitignore vendored
View File

@ -23,8 +23,9 @@ err.txt
log.txt
*.rusefi_binary
*.msq
gitversion.h
gitversion.h.gen
gitversion.h*
engine_modules_generated.h*
modules_list_generated.h*
# Eclipse
.metadata/

View File

@ -200,6 +200,7 @@ endif
include $(PROJECT_DIR)/hw_layer/mass_storage/mass_storage.mk
include $(PROJECT_DIR)/common.mk
include $(PROJECT_DIR)/controllers/modules/modules.mk
ifeq ($(USE_OPENBLT),yes)
# Reserve start of flash for OpenBLT
@ -239,6 +240,7 @@ CPPSRC = \
$(HW_LAYER_DRIVERS_CORE_CPP) \
$(HW_LAYER_DRIVERS_CPP) \
$(CONSOLE_SRC_CPP) \
$(MODULES_CPPSRC) \
$(RUSEFI_LIB_CPP) \
rusefi.cpp \
main.cpp
@ -275,6 +277,7 @@ INCDIR = \
$(PCH_DIR) \
$(BOARDINC) \
$(ALLINC) \
$(MODULES_INC) \
$(TESTINC) \
$(CHIBIOS)/os/various \
$(RUSEFI_LIB_INC) \
@ -360,6 +363,7 @@ include $(RULESFILE)
include $(PROJECT_DIR)/rusefi_pch.mk
include $(PROJECT_DIR)/fome_generated.mk
include $(PROJECT_DIR)/gitversion.mk
include $(PROJECT_DIR)/controllers/modules/modules_header_gen.mk
.PHONY: CLEAN_RULE_HOOK CLEAN_PCH_HOOK CLEAN_BUNDLE_HOOK

View File

@ -341,6 +341,7 @@ include $(RULESFILE)
include $(PROJECT_DIR)/rusefi_pch.mk
include $(PROJECT_DIR)/fome_generated.mk
include $(PROJECT_DIR)/gitversion.mk
include $(PROJECT_DIR)/controllers/modules/modules_header_gen.mk
.PHONY: CLEAN_RULE_HOOK CLEAN_PCH_HOOK CLEAN_BUNDLE_HOOK

View File

@ -344,9 +344,12 @@ static void updateVvtSensors() {
static void updateVehicleSpeed() {
#if EFI_VEHICLE_SPEED
engine->outputChannels.vehicleSpeedKph = Sensor::getOrZero(SensorType::VehicleSpeed);
#endif // EFI_VEHICLE_SPEED
#ifdef MODULE_GEAR_DETECT
engine->outputChannels.speedToRpmRatio = engine->module<GearDetector>()->getGearboxRatio();
engine->outputChannels.detectedGear = Sensor::getOrZero(SensorType::DetectedGear);
#endif /* EFI_VEHICLE_SPEED */
#endif // MODULE_GEAR_DETECT
}
static void updateRawSensors() {
@ -424,6 +427,7 @@ static void updateFuelCorrections() {
}
static void updateFuelResults() {
#ifdef MODULE_TRIP_ODO
engine->outputChannels.fuelFlowRate = engine->module<TripOdometer>()->getConsumptionGramPerSecond();
engine->outputChannels.totalFuelConsumption = engine->module<TripOdometer>()->getConsumedGrams();
engine->outputChannels.ignitionOnTime = engine->module<TripOdometer>()->getIgnitionOnTime();
@ -431,6 +435,7 @@ static void updateFuelResults() {
// output channel in km
engine->outputChannels.distanceTraveled = 0.001f * engine->module<TripOdometer>()->getDistanceMeters();
#endif // MODULE_TRIP_ODO
}
static void updateFuelInfo() {

View File

@ -14,7 +14,6 @@ CONTROLLERS_ALGO_SRC_CPP = $(PROJECT_DIR)/controllers/algo/advance_map.cpp \
$(PROJECT_DIR)/controllers/algo/engine_configuration.cpp \
$(PROJECT_DIR)/controllers/algo/engine.cpp \
$(PROJECT_DIR)/controllers/algo/engine2.cpp \
$(PROJECT_DIR)/controllers/algo/gear_detector.cpp \
$(PROJECT_DIR)/controllers/algo/event_registry.cpp \
$(PROJECT_DIR)/controllers/algo/airmass/airmass.cpp \
$(PROJECT_DIR)/controllers/algo/airmass/alphan_airmass.cpp \
@ -24,7 +23,6 @@ CONTROLLERS_ALGO_SRC_CPP = $(PROJECT_DIR)/controllers/algo/advance_map.cpp \
$(PROJECT_DIR)/controllers/algo/fuel/fuel_computer.cpp \
$(PROJECT_DIR)/controllers/algo/fuel/injector_model.cpp \
$(PROJECT_DIR)/controllers/algo/fuel/dfco.cpp \
$(PROJECT_DIR)/controllers/algo/trip_odometer.cpp \
$(PROJECT_DIR)/controllers/algo/defaults/default_base_engine.cpp \
$(PROJECT_DIR)/controllers/algo/defaults/default_cranking.cpp \
$(PROJECT_DIR)/controllers/algo/defaults/default_fuel.cpp \

View File

@ -27,7 +27,6 @@
#include "speedometer.h"
#include "dynoview.h"
#include "boost_control.h"
#include "fan_control.h"
#include "ac_control.h"
#include "vr_pwm.h"
#if EFI_MC33816

View File

@ -32,7 +32,6 @@
#include "launch_control.h"
#include "antilag_system.h"
#include "trigger_scheduler.h"
#include "fuel_pump.h"
#include "main_relay.h"
#include "ac_control.h"
#include "type_list.h"
@ -42,16 +41,15 @@
#include "harley_acr.h"
#include "dfco.h"
#include "fuel_computer.h"
#include "gear_detector.h"
#include "advance_map.h"
#include "fan_control.h"
#include "sensor_checker.h"
#include "fuel_schedule.h"
#include "prime_injection.h"
#include "throttle_model.h"
#include "lambda_monitor.h"
#include "vvt.h"
#include "trip_odometer.h"
#include "engine_modules_generated.h"
#include <functional>
@ -156,20 +154,13 @@ public:
#if EFI_ALTERNATOR_CONTROL
AlternatorController,
#endif /* EFI_ALTERNATOR_CONTROL */
FuelPumpController,
MainRelayController,
IgnitionController,
Mockable<AcController>,
FanControl1,
FanControl2,
PrimeController,
DfcoController,
HarleyAcr,
Mockable<WallFuelController>,
#if EFI_VEHICLE_SPEED
GearDetector,
TripOdometer,
#endif // EFI_VEHICLE_SPEED
KnockController,
SensorChecker,
LimpManager,
@ -183,6 +174,9 @@ public:
BoostController,
#endif // EFI_BOOST_CONTROL
LedBlinkingTask,
#include "modules_list_generated.h"
EngineModule // dummy placeholder so the previous entries can all have commas
> engineModules;

View File

@ -52,8 +52,10 @@ static void populateFrame(Status& msg) {
msg.gear = Sensor::getOrZero(SensorType::DetectedGear);
#ifdef MODULE_TRIP_ODO
// scale to units of 0.1km
msg.distanceTraveled = engine->module<TripOdometer>()->getDistanceMeters() / 100;
#endif
}
struct Speeds {
@ -158,8 +160,10 @@ struct Fueling2 {
};
static void populateFrame(Fueling2& msg) {
msg.fuelConsumedGram = engine->module<TripOdometer>()->getConsumedGrams();
msg.fuelFlowRate = engine->module<TripOdometer>()->getConsumptionGramPerSecond();
#ifdef MODULE_TRIP_ODO
msg.fuelConsumedGram = engine->module<TripOdometer>()->getConsumedGrams();
msg.fuelFlowRate = engine->module<TripOdometer>()->getConsumptionGramPerSecond();
#endif // MODULE_TRIP_ODO
for (size_t i = 0; i < 2; i++) {
msg.fuelTrim[i] = 100.0f * (engine->stftCorrection[i] - 1.0f);

View File

@ -160,12 +160,15 @@ static void handleGetDataRequest(const CANRxFrame& rx, CanBusIndex busIndex) {
obdSendPacket(1, pid, 4, scaled << 16, busIndex);
break;
#ifdef MODULE_TRIP_ODO
} case PID_FUEL_RATE: {
float gPerSecond = engine->module<TripOdometer>()->getConsumptionGramPerSecond();
float gPerHour = gPerSecond * 3600;
float literPerHour = gPerHour * 0.00139f;
obdSendValue(_1_MODE, pid, 2, literPerHour * 20.0f, busIndex); // L/h. (A*256+B)/20
break;
#endif // MODULE_TRIP_ODO
} default:
// ignore unhandled PIDs
break;

View File

@ -13,8 +13,6 @@ CONTROLLERS_SRC_CPP = \
$(CONTROLLERS_DIR)/actuators/alternator_controller.cpp \
$(CONTROLLERS_DIR)/actuators/boost_control.cpp \
$(CONTROLLERS_DIR)/actuators/dc_motors.cpp \
$(CONTROLLERS_DIR)/actuators/fan_control.cpp \
$(CONTROLLERS_DIR)/actuators/fuel_pump.cpp \
$(CONTROLLERS_DIR)/actuators/harley_acr.cpp \
$(CONTROLLERS_DIR)/actuators/idle_thread_io.cpp \
$(CONTROLLERS_DIR)/actuators/idle_hardware.cpp \

View File

@ -115,12 +115,14 @@ void InjectionEvent::onTriggerTooth(efitick_t nowNt, float currentPhase, float n
{
// Log this fuel as consumed
#ifdef MODULE_TRIP_ODO
bool isCranking = getEngineRotationState()->isCranking();
int numberOfInjections = isCranking ? getNumberOfInjections(engineConfiguration->crankingInjectionMode) : getNumberOfInjections(engineConfiguration->injectionMode);
float actualInjectedMass = numberOfInjections * (injectionMassStage1 + injectionMassStage2);
engine->module<TripOdometer>()->consumeFuel(actualInjectedMass, nowNt);
#endif // MODULE_TRIP_ODO
}
if (doSplitInjection) {

View File

@ -893,7 +893,7 @@ void configureRusefiLuaHooks(lua_State* l) {
return 1;
});
#if EFI_VEHICLE_SPEED
#ifdef MODULE_GEAR_DETECT
lua_register(l, "getCurrentGear", [](lua_State* l2) {
lua_pushinteger(l2, Sensor::getOrZero(SensorType::DetectedGear));
return 1;
@ -904,7 +904,7 @@ void configureRusefiLuaHooks(lua_State* l) {
lua_pushinteger(l2, engine->module<GearDetector>()->getRpmInGear(idx));
return 1;
});
#endif // EFI_VEHICLE_SPEED
#endif // MODULE_GEAR_DETECT
#if !EFI_UNIT_TEST
lua_register(l, "startPwm", lua_startPwm);
@ -940,8 +940,10 @@ void configureRusefiLuaHooks(lua_State* l) {
lua_register(l, "txCan", lua_txCan);
#endif
#ifdef MODULE_TRIP_ODO
lua_register(l, "resetOdometer", [](lua_State*) {
engine->module<TripOdometer>()->reset();
return 0;
});
#endif // MODULE_TRIP_ODO
}

View File

@ -0,0 +1,4 @@
MODULES_INC += $(PROJECT_DIR)/controllers/modules/fan
MODULES_CPPSRC += $(PROJECT_DIR)/controllers/modules/fan/fan_control.cpp
MODULES_INCLUDE += \#include "fan_control.h"\n
MODULES_LIST += FanControl1,FanControl2,

View File

@ -0,0 +1,4 @@
MODULES_INC += $(PROJECT_DIR)/controllers/modules/fuel_pump
MODULES_CPPSRC += $(PROJECT_DIR)/controllers/modules/fuel_pump/fuel_pump.cpp
MODULES_INCLUDE += \#include "fuel_pump.h"\n
MODULES_LIST += FuelPumpController,

View File

@ -0,0 +1,6 @@
MODULES_INC += $(PROJECT_DIR)/controllers/modules/gear_detector
MODULES_CPPSRC += $(PROJECT_DIR)/controllers/modules/gear_detector/gear_detector.cpp
MODULES_INCLUDE += \#include "gear_detector.h"\n
MODULES_LIST += GearDetector,
DDEFS += -DMODULE_GEAR_DETECT

View File

@ -0,0 +1,4 @@
include $(PROJECT_DIR)/controllers/modules/fan/fan.mk
include $(PROJECT_DIR)/controllers/modules/fuel_pump/fuel_pump.mk
include $(PROJECT_DIR)/controllers/modules/gear_detector/gear_detector.mk
include $(PROJECT_DIR)/controllers/modules/trip_odometer/trip_odometer.mk

View File

@ -0,0 +1,16 @@
# Generate header to include all built modules
engine_modules_generated.h.gen : .FORCE
printf '$(MODULES_INCLUDE)' > $@
engine_modules_generated.h : engine_modules_generated.h.gen
rsync --checksum $< $@
modules_list_generated.h.gen : .FORCE
printf '$(MODULES_LIST)' > $@
modules_list_generated.h : modules_list_generated.h.gen
rsync --checksum $< $@
# All objects could depend on module list
$(OBJS) : engine_modules_generated.h
$(OBJS) : modules_list_generated.h

View File

@ -0,0 +1,6 @@
MODULES_INC += $(PROJECT_DIR)/controllers/modules/trip_odometer
MODULES_CPPSRC += $(PROJECT_DIR)/controllers/modules/trip_odometer/trip_odometer.cpp
MODULES_INCLUDE += \#include "trip_odometer.h"\n
MODULES_LIST += TripOdometer,
DDEFS += -DMODULE_TRIP_ODO

View File

@ -69,13 +69,13 @@ Usages:
output_name: ac
- name: fan_control
folder: controllers/actuators
folder: controllers/modules/fan
output_name: [ "fan1", "fan2" ]
constexpr: "___engine.module<FanControl1>()"
isPtr: true
- name: fuel_pump_control
folder: controllers/actuators
folder: controllers/modules/fuel_pump
output_name: fuelPump
- name: main_relay

View File

@ -282,7 +282,9 @@ void runRusEfiWithConfig() {
*/
initEngineController();
#ifdef MODULE_GEAR_DETECT
engine->module<GearDetector>()->onConfigurationChange(nullptr);
#endif
#if EFI_ENGINE_EMULATOR
initEngineEmulator();

View File

@ -158,6 +158,7 @@ endif
include $(PROJECT_DIR)/console/binary/tunerstudio.mk
include $(PROJECT_DIR)/console/console.mk
include $(PROJECT_DIR)/common.mk
include $(PROJECT_DIR)/controllers/modules/modules.mk
# C sources that can be compiled in ARM or THUMB mode depending on the global
@ -181,6 +182,7 @@ CPPSRC = $(ALLCPPSRC) \
simulator/system/signal_executor_sleep.cpp \
simulator/boards.cpp \
$(TEST_SRC_CPP) \
$(MODULES_CPPSRC) \
$(RUSEFI_LIB_CPP) \
main.cpp
@ -191,6 +193,7 @@ ASMSRC = $(PORTASM)
INCDIR = . \
$(PCH_DIR) \
$(ALLINC) \
$(MODULES_INC) \
$(CHIBIOS)/os/various/cpp_wrappers \
$(PROJECT_DIR)/hw_layer/drivers/can \
${CHIBIOS}/os/various \
@ -290,6 +293,7 @@ include $(RULESPATH)/rules.mk
include $(PROJECT_DIR)/rusefi_pch.mk
include $(PROJECT_DIR)/fome_generated.mk
include $(PROJECT_DIR)/gitversion.mk
include $(PROJECT_DIR)/controllers/modules/modules_header_gen.mk
.PHONY: CLEAN_RULE_HOOK CLEAN_PCH_HOOK CLEAN_BUNDLE_HOOK

View File

@ -14,6 +14,7 @@ include $(UNIT_TESTS_DIR)/test.mk
include $(UNIT_TESTS_DIR)/tests/tests.mk
include $(PROJECT_DIR)/../unit_tests/tests/util/test_util.mk
include $(PROJECT_DIR)/common.mk
include $(PROJECT_DIR)/controllers/modules/modules.mk
RUSEFI_LIB = $(PROJECT_DIR)/libfirmware
include $(RUSEFI_LIB)/util/util.mk
@ -47,11 +48,13 @@ CPPSRC += $(ALLCPPSRC) \
$(PROJECT_DIR)/../unit_tests/mocks.cpp \
$(RUSEFI_LIB_CPP) \
$(RUSEFI_LIB_CPP_TEST) \
$(MODULES_CPPSRC) \
INCDIR += \
$(PCH_DIR) \
$(UNIT_TESTS_DIR) \
$(ALLINC) \
$(MODULES_INC) \
$(GENERATED_DIR) \
$(PROJECT_DIR)/config/boards/hellen \
$(UNIT_TESTS_DIR)/test_data_structures \

View File

@ -1,7 +1,5 @@
#include "pch.h"
#include "fan_control.h"
static void updateFans() {
engine->module<FanControl1>()->onSlowCallback();
}

View File

@ -197,6 +197,7 @@ include $(UNIT_TESTS_DIR)/rules.mk
include $(PROJECT_DIR)/rusefi_pch.mk
include $(PROJECT_DIR)/fome_generated.mk
include $(PROJECT_DIR)/gitversion.mk
include $(PROJECT_DIR)/controllers/modules/modules_header_gen.mk
.PHONY: CLEAN_RULE_HOOK CLEAN_PCH_HOOK CLEAN_BUNDLE_HOOK