auto-sync
This commit is contained in:
parent
3ecd2425d5
commit
06cc8915ef
|
@ -174,7 +174,7 @@ void printState(Engine *engine, int currentCkpEventCounter) {
|
|||
// debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2);
|
||||
// debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2);
|
||||
debugFloat(&logger, "fuel_lag", getInjectorLag(engineConfiguration, getVBatt(engineConfiguration)), 2);
|
||||
debugFloat(&logger, "fuel", getFuelMs(rpm, engine), 2);
|
||||
debugFloat(&logger, "fuel", getFuelMs(rpm PASS_ENGINE_PARAMETER), 2);
|
||||
|
||||
debugFloat(&logger, "timing", getAdvance(engineConfiguration, rpm, engineLoad), 2);
|
||||
|
||||
|
|
|
@ -45,8 +45,6 @@ float getAccelEnrichment(void) {
|
|||
#if EFI_PROD_CODE
|
||||
static THD_WORKING_AREA(aeThreadStack, UTILITY_THREAD_STACK_SIZE);
|
||||
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
|
||||
static msg_t DiffEnrichmentThread(int param) {
|
||||
chRegSetThreadName("Diff Enrichment");
|
||||
while (TRUE) {
|
||||
|
|
|
@ -37,6 +37,10 @@ void Engine::onTriggerEvent(uint64_t nowUs) {
|
|||
lastTriggerEventTimeUs = nowUs;
|
||||
}
|
||||
|
||||
Engine::Engine() {
|
||||
rpmCalculator = NULL;
|
||||
}
|
||||
|
||||
void Engine::init() {
|
||||
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||
initLogging(&logger, "engine");
|
||||
|
|
|
@ -26,6 +26,7 @@ class RpmCalculator;
|
|||
|
||||
class Engine {
|
||||
public:
|
||||
Engine();
|
||||
void init();
|
||||
RpmCalculator *rpmCalculator;
|
||||
engine_configuration_s *engineConfiguration;
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
#include "accel_enrichment.h"
|
||||
#endif /* EFI_ACCEL_ENRICHMENT */
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
float getBaseFuel(Engine *engine, int rpm) {
|
||||
if (engine->engineConfiguration->algorithm == LM_SPEED_DENSITY) {
|
||||
return getSpeedDensityFuel(engine, rpm);
|
||||
|
@ -71,8 +73,7 @@ static int getNumberOfInjections(engine_configuration_s const *engineConfigurati
|
|||
/**
|
||||
* @returns Length of fuel injection, in milliseconds
|
||||
*/
|
||||
float getFuelMs(int rpm, Engine *engine) {
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
float getFuelMs(int rpm DECLATE_ENGINE_PARAMETER) {
|
||||
float theoreticalInjectionLength;
|
||||
if (isCrankingR(rpm)) {
|
||||
theoreticalInjectionLength = getCrankingFuel(engine) / getNumberOfInjections(engineConfiguration, engineConfiguration->crankingInjectionMode);
|
||||
|
|
|
@ -20,6 +20,6 @@ float getCltCorrection(engine_configuration_s *engineConfiguration, float clt);
|
|||
float getRunningFuel(float baseFuel, Engine *engine, int rpm);
|
||||
float getCrankingFuel(Engine *engine);
|
||||
float getCrankingFuel3(engine_configuration_s *engineConfiguration, float coolantTemperature, uint32_t revolutionCounterSinceStart);
|
||||
float getFuelMs(int rpm, Engine *engine);
|
||||
float getFuelMs(int rpm DECLATE_ENGINE_PARAMETER);
|
||||
|
||||
#endif /* FUEL_MAP_H_ */
|
||||
|
|
|
@ -23,12 +23,9 @@
|
|||
|
||||
class MainTriggerCallback {
|
||||
public:
|
||||
// MainTriggerCallback();
|
||||
void init(Engine *engine, engine_configuration2_s *engineConfiguration2);
|
||||
|
||||
Engine *engine;
|
||||
engine_configuration_s *engineConfiguration;
|
||||
engine_configuration2_s *engineConfiguration2;
|
||||
|
||||
};
|
||||
void initMainEventListener(Engine *engine, engine_configuration2_s *engineConfiguration2);
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
static histogram_s waveChartHisto;
|
||||
#endif
|
||||
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
EXTERN_ENGINE;
|
||||
|
||||
/**
|
||||
* This is the number of events in the digital chart which would be displayed
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
static Logging logger;
|
||||
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
EXTERN_ENGINE;
|
||||
extern board_configuration_s *boardConfiguration;
|
||||
|
||||
static bool_t isRunningBench = false;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "efiGpio.h"
|
||||
#include "svnversion.h"
|
||||
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
EXTERN_ENGINE;
|
||||
|
||||
#define LCD_WIDTH 20
|
||||
// this value should be even
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
#define LIMPING_MODE_IAT_TEMPERATURE 30.0f
|
||||
#define LIMPING_MODE_CLT_TEMPERATURE 70.0f
|
||||
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
extern engine_configuration2_s *engineConfiguration2;
|
||||
EXTERN_ENGINE;
|
||||
|
||||
static bool initialized = false;
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ static INLINE void handleFuelInjectionEvent(ActuatorEvent *event, int rpm DECLAT
|
|||
/**
|
||||
* todo: we do not really need to calculate fuel for each individual cylinder
|
||||
*/
|
||||
float fuelMs = getFuelMs(rpm, engine)
|
||||
* engine->engineConfiguration->globalFuelCorrection;
|
||||
float fuelMs = getFuelMs(rpm PASS_ENGINE_PARAMETER)
|
||||
* engineConfiguration->globalFuelCorrection;
|
||||
if (cisnan(fuelMs)) {
|
||||
warning(OBD_PCM_Processor_Fault, "NaN injection pulse");
|
||||
return;
|
||||
|
@ -109,7 +109,6 @@ static INLINE void handleFuel(uint32_t eventIndex, int rpm DECLATE_ENGINE_PARAME
|
|||
efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#3");
|
||||
efiAssertVoid(eventIndex < engine->engineConfiguration2->triggerShape.getLength(), "event index");
|
||||
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
/**
|
||||
* Ignition events are defined by addFuelEvents() according to selected
|
||||
* fueling strategy
|
||||
|
@ -131,7 +130,6 @@ static INLINE void handleFuel(uint32_t eventIndex, int rpm DECLATE_ENGINE_PARAME
|
|||
|
||||
static INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *iEvent,
|
||||
int rpm DECLATE_ENGINE_PARAMETER) {
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2;
|
||||
|
||||
float dwellMs = getSparkDwellMsT(engineConfiguration, rpm);
|
||||
|
@ -241,14 +239,14 @@ void showMainHistogram(void) {
|
|||
* This is the main trigger event handler.
|
||||
* Both injection and ignition are controlled from this method.
|
||||
*/
|
||||
void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTriggerCallback *mainTriggerCallback) {
|
||||
void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTriggerCallback *mtc) {
|
||||
Engine *engine = mtc->engine;
|
||||
(void) ckpSignalType;
|
||||
efiAssertVoid(eventIndex < 2 * mainTriggerCallback->engineConfiguration2->triggerShape.shaftPositionEventCount,
|
||||
efiAssertVoid(eventIndex < 2 * engine->engineConfiguration2->triggerShape.shaftPositionEventCount,
|
||||
"event index");
|
||||
efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowstck#2");
|
||||
|
||||
int rpm = getRpmE(mainTriggerCallback->engine);
|
||||
// int rpm = getRpmE(&engine);
|
||||
int rpm = getRpmE(engine);
|
||||
if (rpm == 0) {
|
||||
// this happens while we just start cranking
|
||||
// todo: check for 'trigger->is_synchnonized?'
|
||||
|
@ -258,7 +256,7 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
|
|||
warning(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, "noisy trigger");
|
||||
return;
|
||||
}
|
||||
if (rpm > mainTriggerCallback->engineConfiguration->rpmHardLimit) {
|
||||
if (rpm > engine->engineConfiguration->rpmHardLimit) {
|
||||
warning(OBD_PCM_Processor_Fault, "skipping stroke due to rpm=%d", rpm);
|
||||
return;
|
||||
}
|
||||
|
@ -271,7 +269,7 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
|
|||
|
||||
if (eventIndex == 0) {
|
||||
if (localVersion.isOld())
|
||||
prepareOutputSignals(mainTriggerCallback->engine);
|
||||
prepareOutputSignals(engine);
|
||||
|
||||
/**
|
||||
* TODO: warning. there is a bit of a hack here, todo: improve.
|
||||
|
@ -285,12 +283,12 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
|
|||
* Within one engine cycle all cylinders are fired with same timing advance.
|
||||
* todo: one day we can control cylinders individually
|
||||
*/
|
||||
float dwellMs = getSparkDwellMsT(mainTriggerCallback->engineConfiguration, rpm);
|
||||
float dwellMs = getSparkDwellMsT(engine->engineConfiguration, rpm);
|
||||
if (cisnan(dwellMs) || dwellMs < 0) {
|
||||
firmwareError("invalid dwell: %f at %d", dwellMs, rpm);
|
||||
return;
|
||||
}
|
||||
float advance = getAdvance(mainTriggerCallback->engineConfiguration, rpm, getEngineLoadT(mainTriggerCallback->engine));
|
||||
float advance = getAdvance(engine->engineConfiguration, rpm, getEngineLoadT(engine));
|
||||
if (cisnan(advance)) {
|
||||
// error should already be reported
|
||||
return;
|
||||
|
@ -298,18 +296,20 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
|
|||
|
||||
float dwellAngle = dwellMs / getOneDegreeTimeMs(rpm);
|
||||
|
||||
initializeIgnitionActions(advance, dwellAngle, mainTriggerCallback->engineConfiguration,
|
||||
mainTriggerCallback->engineConfiguration2,
|
||||
&mainTriggerCallback->engineConfiguration2->ignitionEvents[revolutionIndex]);
|
||||
initializeIgnitionActions(advance, dwellAngle, engine->engineConfiguration,
|
||||
engine->engineConfiguration2,
|
||||
&engine->engineConfiguration2->ignitionEvents[revolutionIndex]);
|
||||
}
|
||||
|
||||
triggerEventsQueue.executeAll(getCrankEventCounter());
|
||||
|
||||
Engine *engine = mainTriggerCallback->engine;
|
||||
// todo: remove these local variables soon
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
|
||||
|
||||
handleFuel(eventIndex, rpm PASS_ENGINE_PARAMETER);
|
||||
handleSpark(eventIndex, rpm,
|
||||
&mainTriggerCallback->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER);
|
||||
&engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER);
|
||||
#if EFI_HISTOGRAMS && EFI_PROD_CODE
|
||||
int diff = hal_lld_get_counter_value() - beforeCallback;
|
||||
if (diff > 0)
|
||||
|
@ -330,9 +330,6 @@ static void showTriggerHistogram(void) {
|
|||
void MainTriggerCallback::init(Engine *engine, engine_configuration2_s *engineConfiguration2) {
|
||||
efiAssertVoid(engine!=NULL, "engine NULL");
|
||||
this->engine = engine;
|
||||
this->engineConfiguration = engine->engineConfiguration;
|
||||
efiAssertVoid(engineConfiguration!=NULL, "engineConfiguration NULL");
|
||||
this->engineConfiguration2 = engineConfiguration2;
|
||||
}
|
||||
|
||||
static void showMainInfo(Engine *engine) {
|
||||
|
@ -340,7 +337,7 @@ static void showMainInfo(Engine *engine) {
|
|||
float el = getEngineLoadT(mainTriggerCallbackInstance.engine);
|
||||
#if EFI_PROD_CODE
|
||||
scheduleMsg(&logger, "rpm %d engine_load %f", rpm, el);
|
||||
scheduleMsg(&logger, "fuel %fms timing %f", getFuelMs(rpm, mainTriggerCallbackInstance.engine),
|
||||
scheduleMsg(&logger, "fuel %fms timing %f", getFuelMs(rpm PASS_ENGINE_PARAMETER),
|
||||
getAdvance(mainTriggerCallbackInstance.engine->engineConfiguration, rpm, el));
|
||||
#endif
|
||||
}
|
||||
|
@ -356,7 +353,7 @@ void initMainEventListener(Engine *engine, engine_configuration2_s *engineConfig
|
|||
|
||||
initLogging(&logger, "main event handler");
|
||||
printMsg(&logger, "initMainLoop: %d", currentTimeMillis());
|
||||
if (!isInjectionEnabled(mainTriggerCallbackInstance.engineConfiguration))
|
||||
if (!isInjectionEnabled(mainTriggerCallbackInstance.engine->engineConfiguration))
|
||||
printMsg(&logger, "!!!!!!!!!!!!!!!!!!! injection disabled");
|
||||
#endif
|
||||
|
||||
|
|
|
@ -48,8 +48,7 @@ int getRpmE(Engine *engine) {
|
|||
return engine->rpmCalculator->rpm();
|
||||
}
|
||||
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
extern engine_configuration2_s *engineConfiguration2;
|
||||
EXTERN_ENGINE;
|
||||
|
||||
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||
static Logging logger;
|
||||
|
|
|
@ -64,7 +64,8 @@ typedef Thread thread_t;
|
|||
* On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter
|
||||
*/
|
||||
|
||||
#define EXTERN_ENGINE extern Engine *engine;
|
||||
#define EXTERN_ENGINE extern Engine *engine; \
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
|
||||
#define DECLATE_ENGINE_PARAMETER
|
||||
#define PASS_ENGINE_PARAMETER
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef void * Logging;
|
|||
|
||||
#define EXTERN_ENGINE
|
||||
|
||||
#define DECLATE_ENGINE_PARAMETER , Engine *engine
|
||||
#define PASS_ENGINE_PARAMETER , engine
|
||||
#define DECLATE_ENGINE_PARAMETER , Engine *engine, engine_configuration_s *engineConfiguration
|
||||
#define PASS_ENGINE_PARAMETER , engine, engineConfiguration
|
||||
|
||||
#endif /* GLOBAL_H_ */
|
||||
|
|
|
@ -86,7 +86,8 @@ typedef VirtualTimer virtual_timer_t;
|
|||
typedef EventListener event_listener_t;
|
||||
#define THD_WORKING_AREA WORKING_AREA
|
||||
|
||||
#define EXTERN_ENGINE extern Engine *engine;
|
||||
#define EXTERN_ENGINE extern Engine *engine; \
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
|
||||
#define DECLATE_ENGINE_PARAMETER
|
||||
#define PASS_ENGINE_PARAMETER
|
||||
|
|
Loading…
Reference in New Issue