auto-sync
This commit is contained in:
parent
fa85678d21
commit
9f382381a7
|
@ -45,18 +45,35 @@ void Engine::onTriggerEvent(uint64_t nowNt) {
|
|||
lastTriggerEventTimeNt = nowNt;
|
||||
}
|
||||
|
||||
static void invokeEnginePreCalculate(Engine *engine) {
|
||||
engine->preCalculate();
|
||||
}
|
||||
|
||||
void Engine::addConfigurationListener(configuration_callback_t callback) {
|
||||
configurationListeners.registerCallback((VoidInt)invokeEnginePreCalculate, this);
|
||||
}
|
||||
|
||||
Engine::Engine() {
|
||||
lastTriggerEventTimeNt = 0;
|
||||
isCylinderCleanupMode = false;
|
||||
engineCycleEventCount = 0;
|
||||
stopEngineRequestTimeNt = 0;
|
||||
isRunningPwmTest = false;
|
||||
|
||||
addConfigurationListener(invokeEnginePreCalculate);
|
||||
}
|
||||
|
||||
void Engine::precalc() {
|
||||
/**
|
||||
* Here we have a bunch of stuff which should invoked after configuration change
|
||||
* so that we can prepare some helper structures
|
||||
*/
|
||||
void Engine::preCalculate() {
|
||||
sparkTable.preCalc(engineConfiguration->sparkDwellBins,
|
||||
engineConfiguration->sparkDwell);
|
||||
|
||||
/**
|
||||
* Here we prepare a fast, index-based MAF lookup from a slower curve description
|
||||
*/
|
||||
for (int i = 0; i < MAF_DECODING_CACHE_SIZE; i++) {
|
||||
float volts = i / MAF_DECODING_CACHE_MULT;
|
||||
float maf = interpolate2d(volts, engineConfiguration->mafDecodingBins,
|
||||
|
|
|
@ -111,6 +111,10 @@ typedef struct {
|
|||
uint32_t fuelCalcTime;
|
||||
} monitoring_timestamps_s;
|
||||
|
||||
class Engine;
|
||||
|
||||
typedef void (*configuration_callback_t)(Engine*);
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
Engine();
|
||||
|
@ -196,11 +200,16 @@ public:
|
|||
*/
|
||||
float mafDecodingLookup[MAF_DECODING_CACHE_SIZE];
|
||||
|
||||
void precalc();
|
||||
void preCalculate();
|
||||
void addConfigurationListener(configuration_callback_t callback);
|
||||
|
||||
void updateSlowSensors();
|
||||
void watchdog();
|
||||
|
||||
/**
|
||||
* here we have all the listeners which should be notified about a configuration
|
||||
* change
|
||||
*/
|
||||
IntListenerArray configurationListeners;
|
||||
|
||||
monitoring_timestamps_s m;
|
||||
|
|
|
@ -90,7 +90,6 @@ int getGlobalConfigurationVersion(void) {
|
|||
|
||||
void incrementGlobalConfigurationVersion(void) {
|
||||
globalConfigurationVersion++;
|
||||
// todo invoke engine->configurationListeners.
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "malfunction_central.h"
|
||||
#include "engine.h"
|
||||
#include "algo.h"
|
||||
#include "LocalVersionHolder.h"
|
||||
|
||||
#if HAL_USE_ADC || defined(__DOXYGEN__)
|
||||
#include "AdcConfiguration.h"
|
||||
|
@ -197,6 +198,8 @@ static void cylinderCleanupControl(Engine *engine) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static LocalVersionHolder versionForConfigurationListeners;
|
||||
|
||||
static void onEvenyGeneralMilliseconds(Engine *engine) {
|
||||
#if EFI_PROD_CODE
|
||||
/**
|
||||
|
@ -214,6 +217,15 @@ static void onEvenyGeneralMilliseconds(Engine *engine) {
|
|||
writeToFlashIfPending();
|
||||
#endif
|
||||
|
||||
if (versionForConfigurationListeners.isOld()) {
|
||||
/**
|
||||
* version change could happen for multiple reason and on different threads
|
||||
* in order to be sure which thread (and which stack) invokes the potentially heavy
|
||||
* listeners we invoke them from here.
|
||||
*/
|
||||
engine->configurationListeners.invokeJustArgCallbacks();
|
||||
}
|
||||
|
||||
engine->watchdog();
|
||||
engine->updateSlowSensors();
|
||||
|
||||
|
@ -254,7 +266,7 @@ extern AdcDevice fastAdc;
|
|||
|
||||
static void printAnalogChannelInfoExt(const char *name, adc_channel_e hwChannel, float adcVoltage) {
|
||||
#if HAL_USE_ADC || defined(__DOXYGEN__)
|
||||
if(fastAdc.isHwUsed(hwChannel)) {
|
||||
if (fastAdc.isHwUsed(hwChannel)) {
|
||||
scheduleMsg(&logger, "fast enabled=%s", boolToString(boardConfiguration->isFastAdcEnabled));
|
||||
}
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ static void calcFastAdcIndexes(void) {
|
|||
-1 : fastAdc.internalAdcIndexByHardwareIndex[engineConfiguration->hipOutputChannel];
|
||||
}
|
||||
|
||||
static void adcConfigListener(void) {
|
||||
static void adcConfigListener(Engine *engine) {
|
||||
calcFastAdcIndexes();
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ void initHardware(Logging *l, Engine *engine) {
|
|||
initJoystick(sharedLogger);
|
||||
|
||||
calcFastAdcIndexes();
|
||||
engine->configurationListeners.registerCallback(adcConfigListener);
|
||||
engine->addConfigurationListener(adcConfigListener);
|
||||
|
||||
printMsg(sharedLogger, "initHardware() OK!");
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ void testMafLookup(void) {
|
|||
Engine * engine = ð.engine;
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
setBosch0280218037(engineConfiguration);
|
||||
engine->precalc();
|
||||
engine->preCalculate();
|
||||
|
||||
assertEqualsM("@0", -34.5000, engine->mafDecodingLookup[0]);
|
||||
assertEqualsM("@1", -33.7875, engine->mafDecodingLookup[1]);
|
||||
|
|
Loading…
Reference in New Issue