This commit is contained in:
rusEfi 2019-12-10 23:18:44 -05:00
commit a44a0cad99
13 changed files with 282 additions and 216 deletions

View File

@ -15,37 +15,43 @@
EXTERN_ENGINE; EXTERN_ENGINE;
static void setInjectorPins() { static const brain_pin_e injPins[] = {
boardConfiguration->injectionPins[0] = GPIOD_7; GPIOD_7,
boardConfiguration->injectionPins[1] = GPIOG_9; GPIOG_9,
boardConfiguration->injectionPins[2] = GPIOG_10; GPIOG_10,
boardConfiguration->injectionPins[3] = GPIOG_11; GPIOG_11,
boardConfiguration->injectionPins[4] = GPIOG_12; GPIOG_12,
boardConfiguration->injectionPins[5] = GPIOG_13; GPIOG_13,
boardConfiguration->injectionPins[6] = GPIOG_14; GPIOG_14,
boardConfiguration->injectionPins[7] = GPIOB_4; GPIOB_4,
boardConfiguration->injectionPins[8] = GPIOB_5; GPIOB_5,
boardConfiguration->injectionPins[9] = GPIOB_6; GPIOB_6,
boardConfiguration->injectionPins[10] = GPIOB_7; GPIOB_7,
boardConfiguration->injectionPins[11] = GPIOB_8; GPIOB_8
};
static const brain_pin_e ignPins[] = {
GPIOD_4,
GPIOD_3,
GPIOC_9,
GPIOC_8,
GPIOC_7,
GPIOG_8,
GPIOG_7,
GPIOG_6,
GPIOG_5,
GPIOG_4,
GPIOG_3,
GPIOG_2,
};
static void setInjectorPins() {
copyArray(boardConfiguration->injectionPins, injPins);
boardConfiguration->injectionPinMode = OM_DEFAULT; boardConfiguration->injectionPinMode = OM_DEFAULT;
} }
static void setIgnitionPins() { static void setIgnitionPins() {
boardConfiguration->ignitionPins[0] = GPIOD_4; copyArray(boardConfiguration->ignitionPins, ignPins);
boardConfiguration->ignitionPins[1] = GPIOD_3;
boardConfiguration->ignitionPins[2] = GPIOC_9;
boardConfiguration->ignitionPins[3] = GPIOC_8;
boardConfiguration->ignitionPins[4] = GPIOC_7;
boardConfiguration->ignitionPins[5] = GPIOG_8;
boardConfiguration->ignitionPins[6] = GPIOG_7;
boardConfiguration->ignitionPins[7] = GPIOG_6;
boardConfiguration->ignitionPins[8] = GPIOG_5;
boardConfiguration->ignitionPins[9] = GPIOG_4;
boardConfiguration->ignitionPins[10] = GPIOG_3;
boardConfiguration->ignitionPins[11] = GPIOG_2;
boardConfiguration->ignitionPinMode = OM_DEFAULT; boardConfiguration->ignitionPinMode = OM_DEFAULT;
} }

View File

@ -87,22 +87,28 @@ void setFordEscortGt(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
setFuelLoadBin(1.2, 4.4 PASS_CONFIG_PARAMETER_SUFFIX); setFuelLoadBin(1.2, 4.4 PASS_CONFIG_PARAMETER_SUFFIX);
setFuelRpmBin(800, 7000 PASS_CONFIG_PARAMETER_SUFFIX); setFuelRpmBin(800, 7000 PASS_CONFIG_PARAMETER_SUFFIX);
config->veRpmBins[0] = 800; static const float veRpmBins[] =
config->veRpmBins[1] = 1200; {
config->veRpmBins[2] = 1600; 800,
config->veRpmBins[3] = 2000; 1200,
config->veRpmBins[4] = 2400; 1600,
config->veRpmBins[5] = 2800; 2000,
config->veRpmBins[6] = 3200; 2400,
config->veRpmBins[7] = 3600; 2800,
config->veRpmBins[8] = 4100; 3200,
config->veRpmBins[9] = 4500; 3600,
config->veRpmBins[10] = 4900; 4100,
config->veRpmBins[11] = 5300; 4500,
config->veRpmBins[12] = 5700; 4900,
config->veRpmBins[13] = 6100; 5300,
config->veRpmBins[14] = 6500; 5700,
config->veRpmBins[15] = 7000; 6100,
6500,
7000
};
copyArray(config->veRpmBins, veRpmBins);
copyFuelTable(racingFestivaVeTable, config->veTable); copyFuelTable(racingFestivaVeTable, config->veTable);
@ -252,22 +258,28 @@ void setFordEscortGt(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
setFsio(1, GPIOD_7, RPM_ABOVE_USER_SETTING_2 PASS_CONFIG_PARAMETER_SUFFIX); setFsio(1, GPIOD_7, RPM_ABOVE_USER_SETTING_2 PASS_CONFIG_PARAMETER_SUFFIX);
#endif /* EFI_FSIO */ #endif /* EFI_FSIO */
config->ignitionRpmBins[0] = 800; static const float ignitionRpmBins[] =
config->ignitionRpmBins[1] = 1200; {
config->ignitionRpmBins[2] = 1600; 800,
config->ignitionRpmBins[3] = 2000; 1200,
config->ignitionRpmBins[4] = 2400; 1600,
config->ignitionRpmBins[5] = 2800; 2000,
config->ignitionRpmBins[6] = 3200; 2400,
config->ignitionRpmBins[7] = 3600; 2800,
config->ignitionRpmBins[8] = 4100; 3200,
config->ignitionRpmBins[9] = 4500; 3600,
config->ignitionRpmBins[10] = 4900; 4100,
config->ignitionRpmBins[11] = 5300; 4500,
config->ignitionRpmBins[12] = 5700; 4900,
config->ignitionRpmBins[13] = 6100; 5300,
config->ignitionRpmBins[14] = 6500; 5700,
config->ignitionRpmBins[15] = 7000; 6100,
6500,
7000
};
copyArray(config->ignitionRpmBins, ignitionRpmBins);
#if IGN_LOAD_COUNT == DEFAULT_IGN_LOAD_COUNT #if IGN_LOAD_COUNT == DEFAULT_IGN_LOAD_COUNT
copyTimingTable(racingFestivaIgnitionTable, config->ignitionTable); copyTimingTable(racingFestivaIgnitionTable, config->ignitionTable);
#endif #endif

View File

@ -275,7 +275,7 @@ static const void * getStructAddr(int structId) {
return static_cast<trigger_state_s*>(&engine->triggerCentral.triggerState); return static_cast<trigger_state_s*>(&engine->triggerCentral.triggerState);
#if EFI_ELECTRONIC_THROTTLE_BODY #if EFI_ELECTRONIC_THROTTLE_BODY
case LDS_ETB_PID_STATE_INDEX: case LDS_ETB_PID_STATE_INDEX:
return static_cast<pid_state_s*>(&etbController[0].etbPid); return etbController[0].getPidState();
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */ #endif /* EFI_ELECTRONIC_THROTTLE_BODY */
#ifndef EFI_IDLE_CONTROL #ifndef EFI_IDLE_CONTROL

View File

@ -180,9 +180,24 @@ static percent_t currentEtbDuty;
// this macro clamps both positive and negative percentages from about -100% to 100% // this macro clamps both positive and negative percentages from about -100% to 100%
#define ETB_PERCENT_TO_DUTY(X) (maxF(minF((X * 0.01), ETB_DUTY_LIMIT - 0.01), 0.01 - ETB_DUTY_LIMIT)) #define ETB_PERCENT_TO_DUTY(X) (maxF(minF((X * 0.01), ETB_DUTY_LIMIT - 0.01), 0.01 - ETB_DUTY_LIMIT))
void EtbController::init(DcMotor *motor, int ownIndex) { void EtbController::init(DcMotor *motor, int ownIndex, pid_s *pidParameters) {
this->m_motor = motor; m_motor = motor;
this->ownIndex = ownIndex; m_myIndex = ownIndex;
m_pid.initPidClass(pidParameters);
}
void EtbController::reset() {
m_shouldResetPid = true;
}
void EtbController::onConfigurationChange(pid_s* previousConfiguration) {
if (m_pid.isSame(previousConfiguration)) {
m_shouldResetPid = true;
}
}
void EtbController::showStatus(Logging* logger) {
m_pid.showPidStatus(logger, "ETB");
} }
int EtbController::getPeriodMs() { int EtbController::getPeriodMs() {
@ -190,18 +205,19 @@ int EtbController::getPeriodMs() {
} }
void EtbController::PeriodicTask() { void EtbController::PeriodicTask() {
#if EFI_TUNER_STUDIO
// Only debug throttle #0
if (m_myIndex == 0) {
// set debug_mode 17 // set debug_mode 17
if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_PID) { if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_PID) {
#if EFI_TUNER_STUDIO m_pid.postState(&tsOutputChannels);
etbPid.postState(&tsOutputChannels);
tsOutputChannels.debugIntField5 = engine->engineState.etbFeedForward; tsOutputChannels.debugIntField5 = engine->engineState.etbFeedForward;
#endif /* EFI_TUNER_STUDIO */
} else if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_EXTRA) { } else if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_EXTRA) {
#if EFI_TUNER_STUDIO
// set debug_mode 29 // set debug_mode 29
tsOutputChannels.debugFloatField1 = directPwmValue; tsOutputChannels.debugFloatField1 = directPwmValue;
#endif /* EFI_TUNER_STUDIO */
} }
}
#endif /* EFI_TUNER_STUDIO */
if (!m_motor) { if (!m_motor) {
return; return;
@ -212,9 +228,9 @@ void EtbController::PeriodicTask() {
return; return;
} }
if (shouldResetPid) { if (m_shouldResetPid) {
etbPid.reset(); m_pid.reset();
shouldResetPid = false; m_shouldResetPid = false;
} }
if (!cisnan(directPwmValue)) { if (!cisnan(directPwmValue)) {
@ -227,7 +243,7 @@ void EtbController::PeriodicTask() {
return; return;
} }
percent_t actualThrottlePosition = getTPSWithIndex(ownIndex PASS_ENGINE_PARAMETER_SUFFIX); percent_t actualThrottlePosition = getTPSWithIndex(m_myIndex PASS_ENGINE_PARAMETER_SUFFIX);
if (engine->etbAutoTune) { if (engine->etbAutoTune) {
autoTune.input = actualThrottlePosition; autoTune.input = actualThrottlePosition;
@ -271,16 +287,16 @@ void EtbController::PeriodicTask() {
} }
engine->engineState.etbFeedForward = interpolate2d("etbb", targetPosition, engineConfiguration->etbBiasBins, engineConfiguration->etbBiasValues); engine->engineState.etbFeedForward = interpolate2d("etbb", targetPosition, engineConfiguration->etbBiasBins, engineConfiguration->etbBiasValues);
etbPid.iTermMin = engineConfiguration->etb_iTermMin; m_pid.iTermMin = engineConfiguration->etb_iTermMin;
etbPid.iTermMax = engineConfiguration->etb_iTermMax; m_pid.iTermMax = engineConfiguration->etb_iTermMax;
currentEtbDuty = engine->engineState.etbFeedForward + currentEtbDuty = engine->engineState.etbFeedForward +
etbPid.getOutput(targetPosition, actualThrottlePosition); m_pid.getOutput(targetPosition, actualThrottlePosition);
m_motor->set(ETB_PERCENT_TO_DUTY(currentEtbDuty)); m_motor->set(ETB_PERCENT_TO_DUTY(currentEtbDuty));
if (engineConfiguration->isVerboseETB) { if (engineConfiguration->isVerboseETB) {
etbPid.showPidStatus(&logger, "ETB"); m_pid.showPidStatus(&logger, "ETB");
} }
DISPLAY_STATE(Engine) DISPLAY_STATE(Engine)
@ -323,6 +339,9 @@ DISPLAY(DISPLAY_IF(hasEtbPedalPositionSensor))
/* DISPLAY_ELSE */ /* DISPLAY_ELSE */
DISPLAY_TEXT(No_Pedal_Sensor); DISPLAY_TEXT(No_Pedal_Sensor);
/* DISPLAY_ENDIF */ /* DISPLAY_ENDIF */
// Only report the 0th throttle
if (m_myIndex == 0) {
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO
// 312 // 312
tsOutputChannels.etbTarget = targetPosition; tsOutputChannels.etbTarget = targetPosition;
@ -332,6 +351,7 @@ DISPLAY(DISPLAY_IF(hasEtbPedalPositionSensor))
// Error is positive if the throttle needs to open further // Error is positive if the throttle needs to open further
tsOutputChannels.etb1Error = targetPosition - actualThrottlePosition; tsOutputChannels.etb1Error = targetPosition - actualThrottlePosition;
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
}
} }
static EtbHardware etbHardware[ETB_COUNT]; static EtbHardware etbHardware[ETB_COUNT];
@ -390,16 +410,17 @@ static void showEthInfo(void) {
for (int i = 0 ; i < ETB_COUNT; i++) { for (int i = 0 ; i < ETB_COUNT; i++) {
EtbHardware *etb = &etbHardware[i]; EtbHardware *etb = &etbHardware[i];
scheduleMsg(&logger, "%d: dir=%d DC=%f", i, etb->dcMotor.isOpenDirection(), etb->dcMotor.get()); scheduleMsg(&logger, "ETB %%d", i);
scheduleMsg(&logger, "Motor: dir=%d DC=%f", etb->dcMotor.isOpenDirection(), etb->dcMotor.get());
etbController[i].showStatus(&logger);
} }
etbController[0].etbPid.showPidStatus(&logger, "ETB");
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
} }
static void etbPidReset() { static void etbPidReset() {
for (int i = 0 ; i < ETB_COUNT; i++) { for (int i = 0 ; i < ETB_COUNT; i++) {
etbController[i].etbPid.reset(); etbController[i].reset();
} }
} }
@ -419,6 +440,7 @@ static void etbReset() {
for (int i = 0 ; i < ETB_COUNT; i++) { for (int i = 0 ; i < ETB_COUNT; i++) {
etbHardware[i].dcMotor.set(0); etbHardware[i].dcMotor.set(0);
} }
etbPidReset(); etbPidReset();
mockPedalPosition = MOCK_UNDEFINED; mockPedalPosition = MOCK_UNDEFINED;
@ -555,9 +577,8 @@ void stopETBPins(void) {
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration) { void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration) {
bool shouldResetPid = !etbController[0].etbPid.isSame(&previousConfiguration->etb); for (int i = 0; i < ETB_COUNT; i++) {
for (int i = 0 ; i < ETB_COUNT; i++) { etbController[i].onConfigurationChange(&previousConfiguration->etb);
etbController[i].shouldResetPid = shouldResetPid;
} }
} }
@ -644,8 +665,7 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
for (int i = 0 ; i < ETB_COUNT; i++) { for (int i = 0 ; i < ETB_COUNT; i++) {
etbController[i].init(&etbHardware[i].dcMotor, i); etbController[i].init(&etbHardware[i].dcMotor, i, &engineConfiguration->etb);
etbController[i].etbPid.initPidClass(&engineConfiguration->etb);
INJECT_ENGINE_REFERENCE(&etbController[i]); INJECT_ENGINE_REFERENCE(&etbController[i]);
} }

View File

@ -15,20 +15,33 @@
#include "periodic_task.h" #include "periodic_task.h"
class DcMotor; class DcMotor;
class Logging;
class EtbController final : public PeriodicTimerController { class EtbController final : public PeriodicTimerController {
public: public:
DECLARE_ENGINE_PTR; DECLARE_ENGINE_PTR;
void init(DcMotor *motor, int ownIndex); void init(DcMotor *motor, int ownIndex, pid_s *pidParameters);
void reset();
// PeriodicTimerController implementation
int getPeriodMs() override; int getPeriodMs() override;
void PeriodicTask() override; void PeriodicTask() override;
Pid etbPid;
bool shouldResetPid = false; // Called when the configuration may have changed. Controller will
// reset if necessary.
void onConfigurationChange(pid_s* previousConfiguration);
// Print this throttle's status.
void showStatus(Logging* logger);
// Used to inspect the internal PID controller's state
const pid_state_s* getPidState() const { return &m_pid; };
private: private:
int ownIndex; int m_myIndex;
DcMotor *m_motor; DcMotor *m_motor;
Pid m_pid;
bool m_shouldResetPid = false;
}; };
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE); void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);

View File

@ -431,20 +431,49 @@ static void setDefaultWarmupIdleCorrection(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
} }
static void setDefaultWarmupFuelEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void setDefaultWarmupFuelEnrichment(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
initTemperatureCurve(WARMUP_CLT_EXTRA_FUEL_CURVE, 1.0); static const float bins[] =
{
-40,
-30,
-20,
-10,
0,
10,
20,
30,
40,
50,
60,
70,
80,
90,
100,
110
};
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, -40, 1.50); copyArray(config->cltFuelCorrBins, bins);
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, -30, 1.50);
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, -20, 1.42); static const float values[] =
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, -10, 1.36); {
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, 0, 1.28); 1.50,
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, 10, 1.19); 1.50,
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, 20, 1.12); 1.42,
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, 30, 1.10); 1.36,
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, 40, 1.06); 1.28,
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, 50, 1.06); 1.19,
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, 60, 1.03); 1.12,
setCurveValue(WARMUP_CLT_EXTRA_FUEL_CURVE, 70, 1.01); 1.10,
1.06,
1.06,
1.03,
1.01,
1,
1,
1,
1
};
copyArray(config->cltFuelCorr, values);
} }
static void setDefaultFuelCutParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void setDefaultFuelCutParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
@ -465,54 +494,64 @@ static void setDefaultCrankingSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
setLinearCurve(config->cltCrankingCorrBins, CLT_CURVE_RANGE_FROM, 100, 1); setLinearCurve(config->cltCrankingCorrBins, CLT_CURVE_RANGE_FROM, 100, 1);
setLinearCurve(config->cltCrankingCorr, 1.0, 1.0, 1); setLinearCurve(config->cltCrankingCorr, 1.0, 1.0, 1);
config->crankingFuelCoef[0] = 2.8; // base cranking fuel adjustment coefficient // Cranking temperature compensation
config->crankingFuelBins[0] = -20; // temperature in C static const float crankingCoef[] = {
config->crankingFuelCoef[1] = 2.2; 2.8,
config->crankingFuelBins[1] = -10; 2.2,
config->crankingFuelCoef[2] = 1.8; 1.8,
config->crankingFuelBins[2] = 5; 1.5,
config->crankingFuelCoef[3] = 1.5; 1.0,
config->crankingFuelBins[3] = 30; 1.0,
1.0,
1.0
};
copyArray(config->crankingFuelCoef, crankingCoef);
config->crankingFuelCoef[4] = 1.0; // Deg C
config->crankingFuelBins[4] = 35; static const float crankingBins[] = {
config->crankingFuelCoef[5] = 1.0; -20,
config->crankingFuelBins[5] = 50; -10,
config->crankingFuelCoef[6] = 1.0; 5,
config->crankingFuelBins[6] = 65; 30,
config->crankingFuelCoef[7] = 1.0; 35,
config->crankingFuelBins[7] = 90; 50,
65,
90
};
copyArray(config->crankingFuelBins, crankingBins);
config->crankingCycleCoef[0] = 1.5; // Cranking cycle compensation
config->crankingCycleBins[0] = 4;
config->crankingCycleCoef[1] = 1.35; static const float crankingCycleCoef[] = {
config->crankingCycleBins[1] = 8; 1.5,
1.35,
1.05,
0.75,
0.5,
0.5,
0.5,
0.5
};
copyArray(config->crankingCycleCoef, crankingCycleCoef);
config->crankingCycleCoef[2] = 1.05; static const float crankingCycleBins[] = {
config->crankingCycleBins[2] = 12; 4,
8,
12,
16,
74,
75,
76,
77
};
copyArray(config->crankingCycleBins, crankingCycleBins);
config->crankingCycleCoef[3] = 0.75; // Cranking ignition timing
config->crankingCycleBins[3] = 16; static const float advanceValues[] = { 0, 0, 0, 0 };
copyArray(engineConfiguration->crankingAdvance, advanceValues);
config->crankingCycleCoef[4] = 0.5;
config->crankingCycleBins[4] = 74;
config->crankingCycleCoef[5] = 0.5;
config->crankingCycleBins[5] = 75;
config->crankingCycleCoef[6] = 0.5;
config->crankingCycleBins[6] = 76;
config->crankingCycleCoef[7] = 0.5;
config->crankingCycleBins[7] = 77;
engineConfiguration->crankingAdvance[0] = 0;
engineConfiguration->crankingAdvanceBins[0] = 0;
engineConfiguration->crankingAdvance[1] = 0;
engineConfiguration->crankingAdvanceBins[1] = 200;
engineConfiguration->crankingAdvance[2] = 0;
engineConfiguration->crankingAdvanceBins[2] = 400;
engineConfiguration->crankingAdvance[3] = 0;
engineConfiguration->crankingAdvanceBins[3] = 1000;
static const float advanceBins[] = { 0, 200, 400, 1000 };
copyArray(engineConfiguration->crankingAdvanceBins, advanceBins);
} }
/** /**
@ -536,7 +575,6 @@ static void setDefaultIdleSpeedTarget(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
setCurveValue(engineConfiguration->cltIdleRpmBins, engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, 90, 900); setCurveValue(engineConfiguration->cltIdleRpmBins, engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, 90, 900);
setCurveValue(engineConfiguration->cltIdleRpmBins, engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, 100, 1000); setCurveValue(engineConfiguration->cltIdleRpmBins, engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, 100, 1000);
setCurveValue(engineConfiguration->cltIdleRpmBins, engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, 110, 1100); setCurveValue(engineConfiguration->cltIdleRpmBins, engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, 110, 1100);
} }
static void setDefaultStepperIdleParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void setDefaultStepperIdleParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE) {

View File

@ -207,7 +207,7 @@ static Overflow64Counter halTime;
*/ */
//todo: macro to save method invocation //todo: macro to save method invocation
efitimeus_t getTimeNowUs(void) { efitimeus_t getTimeNowUs(void) {
ScopePerf perf(PE::ScheduleByAngle); ScopePerf perf(PE::GetTimeNowUs);
return getTimeNowNt() / (CORE_CLOCK / 1000000); return getTimeNowNt() / (CORE_CLOCK / 1000000);
} }

View File

@ -53,8 +53,7 @@ void setError(bool isError, obd_code_e errorCode) {
void getErrorCodes(error_codes_set_s * copy) { void getErrorCodes(error_codes_set_s * copy) {
copy->count = error_codes_set.count; copy->count = error_codes_set.count;
for (int i = 0; i < copy->count; i++) copyArray(copy->error_codes, error_codes_set.error_codes);
copy->error_codes[i] = error_codes_set.error_codes[i];
} }
bool hasErrorCodes(void) { bool hasErrorCodes(void) {

View File

@ -47,7 +47,7 @@ enum class PE : uint8_t {
MapAveragingTriggerCallback, MapAveragingTriggerCallback,
AdcCallbackFastComplete, AdcCallbackFastComplete,
SingleTimerExecutorScheduleByTimestamp, SingleTimerExecutorScheduleByTimestamp,
ScheduleByAngle, GetTimeNowUs,
EventQueueExecuteCallback, EventQueueExecuteCallback,
PwmGeneratorCallback, PwmGeneratorCallback,
TunerStudioHandleCrcCommand, TunerStudioHandleCrcCommand,

View File

@ -26,14 +26,6 @@ class cyclic_buffer
public: public:
cyclic_buffer(); cyclic_buffer();
explicit cyclic_buffer(int size); explicit cyclic_buffer(int size);
//cpctor
cyclic_buffer(const cyclic_buffer& cb);
//dtor
~cyclic_buffer();
public:
//overloaded =operator
cyclic_buffer& operator=(const cyclic_buffer& rhCb);
public: public:
void add(T value); void add(T value);
@ -75,33 +67,6 @@ void cyclic_buffer<T, maxSize>::baseC(int size) {
setSize(size); setSize(size);
} }
template<typename T, size_t maxSize>
cyclic_buffer<T, maxSize>::cyclic_buffer(const cyclic_buffer& cb) {
//Deep copy the data
currentIndex = cb.currentIndex;
count = cb.count;
size = cb.size;
for (int i = 0; i < size; ++i) {
elements[i] = cb.elements[i];
}
}
template<typename T, size_t maxSize>
cyclic_buffer<T, maxSize>::~cyclic_buffer() {
//No dynamic allocation - safe to leave
}
//template<typename T, size_t maxSize>
//cyclic_buffer& cyclic_buffer<T, maxSize>::operator=(const cyclic_buffer<T, maxSize>& rhCb) {
// //Deep copy
// currentIndex = rhCb.currentIndex;
// count = rhCb.count;
// for (int i = 0; i < size; ++i) {
// elements[i] = rhCb.elements[i];
// }
// return *this;
//}
template<typename T, size_t maxSize> template<typename T, size_t maxSize>
void cyclic_buffer<T, maxSize>::add(T value) { void cyclic_buffer<T, maxSize>::add(T value) {
elements[currentIndex] = value; elements[currentIndex] = value;

View File

@ -91,12 +91,35 @@ float expf_taylor(float x);
namespace efi namespace efi
{ {
template <typename T, size_t N> template <typename T, size_t N>
constexpr size_t size(const T(&)[N]) constexpr size_t size(const T(&)[N]) {
{
return N; return N;
} }
} // namespace efi } // namespace efi
/**
* Copies an array from src to dest. The lengths of the arrays must match.
*/
template <typename TElement, size_t N>
constexpr void copyArray(TElement (&dest)[N], const TElement (&src)[N]) {
for (size_t i = 0; i < N; i++) {
dest[i] = src[i];
}
}
/**
* Copies an array from src to the beginning of dst. If dst is larger
* than src, then only the elements copied from src will be touched.
* Any remaining elements at the end will be untouched.
*/
template <typename TElement, size_t NSrc, size_t NDest>
constexpr void copyArrayPartial(TElement (&dest)[NDest], const TElement (&src)[NSrc]) {
static_assert(NDest >= NSrc, "Source array must be larger than destination.");
for (size_t i = 0; i < NSrc; i++) {
dest[i] = src[i];
}
}
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* EFILIB_H_ */ #endif /* EFILIB_H_ */

View File

@ -21,8 +21,7 @@ static void addCopyAndSort(SignalFiltering *fs, float value) {
fs->values[fs->pointer] = value; fs->values[fs->pointer] = value;
fs->pointer = ++fs->pointer == FILTER_SIZE ? 0 : fs->pointer; fs->pointer = ++fs->pointer == FILTER_SIZE ? 0 : fs->pointer;
for (int i = 0; i < FILTER_SIZE; i++) copyArray(fs->sorted, fs->values);
fs->sorted[i] = fs->values[i];
for (int i = 0; i < FILTER_SIZE; i++) for (int i = 0; i < FILTER_SIZE; i++)
for (int j = i + 1; j < FILTER_SIZE; j++) for (int j = i + 1; j < FILTER_SIZE; j++)

View File

@ -5,9 +5,6 @@
* @author Andrey Belomutskiy, (c) 2012-2019 * @author Andrey Belomutskiy, (c) 2012-2019
*/ */
#ifndef TEST_ION_CPP_
#define TEST_ION_CPP_
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "cdm_ion_sense.h" #include "cdm_ion_sense.h"
@ -16,28 +13,22 @@ TEST(ion, signalCounter) {
EXPECT_EQ(0, state.getValue(0)); EXPECT_EQ(0, state.getValue(0));
state.onNewSignal(2); state.onNewSignal(/* currentRevolution= */ 2);
state.onNewSignal(2); state.onNewSignal(/* currentRevolution= */ 2);
state.onNewSignal(2); state.onNewSignal(/* currentRevolution= */ 2);
// value is still '0' until we signal end of engine cycle // value is still '0' until we signal end of engine cycle
EXPECT_EQ(0, state.getValue(2)); EXPECT_EQ(0, state.getValue(/* currentRevolution= */2));
// this invocation would flush current accumulation // this invocation would flush current accumulation
EXPECT_EQ(3, state.getValue(3)); EXPECT_EQ(3, state.getValue(/* currentRevolution= */3));
state.onNewSignal(3); state.onNewSignal(/* currentRevolution= */3);
// returning previous full cycle value // returning previous full cycle value
EXPECT_EQ(3, state.getValue(3)); EXPECT_EQ(3, state.getValue(3));
EXPECT_EQ(1, state.getValue(4)); EXPECT_EQ(1, state.getValue(/* currentRevolution= */4));
EXPECT_EQ(0, state.getValue(5)); EXPECT_EQ(0, state.getValue(/* currentRevolution= */5));
} }
#endif /* TEST_ION_CPP_ */