convert a table to scaled_channel (#2724)

* scaled VE table

* use setTable

* efi::clear

* ratio -> struct
This commit is contained in:
Matthew Kennedy 2021-05-20 17:00:32 -07:00 committed by GitHub
parent 4195de3819
commit de7879b6e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 27 deletions

View File

@ -147,7 +147,7 @@ void setFordEscortGt(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
setLinearCurve(config->ignitionLoadBins, 20, 105, 5);
setWholeTimingTable_d(10 PASS_CONFIG_PARAMETER_SUFFIX);
setLambdaMap(config->lambdaTable, 0.92);
setTable(config->lambdaTable, 0.92f);
setSingleCoilDwell(PASS_CONFIG_PARAMETER_SIGNATURE);
engineConfiguration->ignitionMode = IM_ONE_COIL;

View File

@ -458,7 +458,7 @@ void Engine::injectEngineReferences() {
void Engine::setConfig(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
INJECT_ENGINE_REFERENCE(this);
memset(config, 0, sizeof(persistent_config_s));
efi::clear(config);
injectEngineReferences();
}

View File

@ -218,14 +218,6 @@ void setConstantDwell(floatms_t dwellMs DECLARE_CONFIG_PARAMETER_SUFFIX) {
setLinearCurve(engineConfiguration->sparkDwellValues, dwellMs, dwellMs, 0.01);
}
void setLambdaMap(lambda_table_t table, float value) {
for (int l = 0; l < FUEL_LOAD_COUNT; l++) {
for (int rpmIndex = 0; rpmIndex < FUEL_RPM_COUNT; rpmIndex++) {
table[l][rpmIndex] = (int)(value * PACK_MULT_LAMBDA_CFG);
}
}
}
void setWholeIgnitionIatCorr(float value DECLARE_CONFIG_PARAMETER_SUFFIX) {
// todo: make setMap a template
setTable(config->ignitionIatCorrTable, value);
@ -257,7 +249,7 @@ static void initTemperatureCurve(float *bins, float *values, int size, float def
void prepareVoidConfiguration(engine_configuration_s *engineConfiguration) {
efiAssertVoid(OBD_PCM_Processor_Fault, engineConfiguration != NULL, "ec NULL");
memset(engineConfiguration, 0, sizeof(engine_configuration_s));
efi::clear(engineConfiguration);
engineConfiguration->clutchDownPinMode = PI_PULLUP;
engineConfiguration->clutchUpPinMode = PI_PULLUP;
@ -685,7 +677,7 @@ static void setHip9011FrankensoPinout(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
*/
static void setDefaultEngineConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if (! EFI_UNIT_TEST)
memset(&persistentState.persistentConfiguration, 0, sizeof(persistentState.persistentConfiguration));
efi::clear(persistentState.persistentConfiguration);
#endif
prepareVoidConfiguration(engineConfiguration);
@ -804,7 +796,7 @@ static void setDefaultEngineConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
setLinearCurve(engineConfiguration->map.samplingWindowBins, 800, 7000, 1);
setLinearCurve(engineConfiguration->map.samplingWindow, 50, 50, 1);
setLambdaMap(config->lambdaTable, 1.0f);
setTable(config->lambdaTable, 1.0f);
engineConfiguration->stoichRatioPrimary = STOICH_RATIO * PACK_MULT_AFR_CFG;
engineConfiguration->stoichRatioSecondary = 9.0f * PACK_MULT_AFR_CFG;

View File

@ -26,7 +26,6 @@ void setOperationMode(engine_configuration_s *engineConfiguration, operation_mod
void prepareVoidConfiguration(engine_configuration_s *activeConfiguration);
void setTargetRpmCurve(int rpm DECLARE_CONFIG_PARAMETER_SUFFIX);
void setLambdaMap(lambda_table_t table, float value);
void setWholeIgnitionIatCorr(float value DECLARE_CONFIG_PARAMETER_SUFFIX);
void setFuelTablesLoadBin(float minValue, float maxValue DECLARE_CONFIG_PARAMETER_SUFFIX);
void setWholeIatCorrTimingTable(float value DECLARE_CONFIG_PARAMETER_SUFFIX);

View File

@ -94,9 +94,12 @@ typedef char le_formula_t[LE_COMMAND_LENGTH];
typedef brain_pin_e egt_cs_array_t[EGT_CHANNEL_COUNT];
typedef uint8_t lambda_table_t[FUEL_LOAD_COUNT][FUEL_RPM_COUNT];
// todo: merge these two types together? but these tables have different TS parameters like ranges etc
typedef float fuel_table_t[FUEL_LOAD_COUNT][FUEL_RPM_COUNT];
#if __cplusplus
#include "scaled_channel.h"
using ve_table_t = scaled_channel<float, 1>[FUEL_LOAD_COUNT][FUEL_RPM_COUNT];
using lambda_table_t = scaled_channel<uint8_t, PACK_MULT_LAMBDA_CFG>[FUEL_LOAD_COUNT][FUEL_RPM_COUNT];
#endif
typedef uint16_t map_estimate_table_t[FUEL_LOAD_COUNT][FUEL_RPM_COUNT];
typedef float ignition_table_t[IGN_LOAD_COUNT][IGN_RPM_COUNT];
typedef int16_t ignition_tps_table_t[IGN_LOAD_COUNT][IGN_RPM_COUNT];
@ -130,8 +133,6 @@ typedef float cfg_float_t_1f;
typedef brain_pin_e brain_input_pin_e;
typedef brain_pin_e switch_input_pin_e;
typedef fuel_table_t ve_table_t;
typedef void (*VoidPtr)(void*);
typedef void (*VoidInt)(int);

View File

@ -114,14 +114,14 @@ temperature_t getTCharge(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX) {
void setDefaultVETable(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
setRpmTableBin(config->veRpmBins, FUEL_RPM_COUNT);
veMap.setAll(80);
setTable(config->veTable, 80);
// setRpmTableBin(engineConfiguration->ve2RpmBins, FUEL_RPM_COUNT);
// setLinearCurve(engineConfiguration->ve2LoadBins, 10, 300, 1);
// ve2Map.setAll(0.81);
setRpmTableBin(config->lambdaRpmBins, FUEL_RPM_COUNT);
lambdaMap.setAll(1.0);
setTable(config->lambdaTable, 1);
setRpmTableBin(engineConfiguration->baroCorrRpmBins, BARO_CORR_SIZE);
setLinearCurve(engineConfiguration->baroCorrPressureBins, 75, 105, 1);

View File

@ -94,6 +94,7 @@ float tanf_taylor(float theta);
}
#include <cstddef>
#include <cstring>
#define IS_NEGATIVE_ZERO(value) (__builtin_signbit(value) && value==0)
#define fixNegativeZero(value) (IS_NEGATIVE_ZERO(value) ? 0 : value)
@ -105,6 +106,21 @@ template <typename T, size_t N>
constexpr size_t size(const T(&)[N]) {
return N;
}
// Zero the passed object
template <typename T>
constexpr void clear(T* obj) {
// The cast to void* is to prevent errors like:
// clearing an object of non-trivial type 'struct persistent_config_s'; use assignment or value-initialization instead
// This is technically wrong, but we know config objects only ever actually
// contain integral types, though they may be wrapped in a scaled_channel
memset(reinterpret_cast<void*>(obj), 0, sizeof(T));
}
template <typename T>
constexpr void clear(T& obj) {
clear(&obj);
}
} // namespace efi
#define assertIsInBounds(length, array, msg) efiAssertVoid(OBD_PCM_Processor_Fault, (length) >= 0 && (length) < efi::size(array), msg)

View File

@ -3,16 +3,14 @@
namespace efi {
template <int TNum, int TDenom = 1>
class ratio {
private:
struct ratio {
static constexpr int num = TNum;
static constexpr int den = TDenom;
public:
// A ratio type representing the reciprocal of this type.
using recip = ratio<den, num>;
static float asFloat() {
static constexpr float asFloat() {
return (float)num / den;
}
};

View File

@ -41,8 +41,7 @@ TEST(fuelControl, transitionIssue1592) {
engineConfiguration->ambiguousOperationMode = FOUR_STROKE_CAM_SENSOR;
engineConfiguration->isFasterEngineSpinUpEnabled = true;
extern fuel_Map3D_t fuelPhaseMap;
fuelPhaseMap.setAll(0);
setTable(config->injectionPhase, 0.0f);
setArrayValues(config->crankingFuelCoef, 1.0f);
setArrayValues(config->crankingCycleCoef, 1.0f);