mirror of https://github.com/FOME-Tech/fome-fw.git
parent
0d3b5414fd
commit
6b97bf8e07
|
@ -54,17 +54,21 @@ static int averagedMapBufIdx = 0;
|
|||
static scheduling_s startTimers[MAX_CYLINDER_COUNT][2];
|
||||
static scheduling_s endTimers[MAX_CYLINDER_COUNT][2];
|
||||
|
||||
static void endAveraging(void *arg);
|
||||
static void endAveraging(MapAverager* arg);
|
||||
|
||||
static size_t currentMapAverager = 0;
|
||||
|
||||
static void startAveraging(scheduling_s *endAveragingScheduling) {
|
||||
efiAssertVoid(CUSTOM_ERR_6649, getCurrentRemainingStack() > 128, "lowstck#9");
|
||||
|
||||
getMapAvg().start();
|
||||
// TODO: set currentMapAverager based on cylinder bank
|
||||
auto& averager = getMapAvg(currentMapAverager);
|
||||
averager.start();
|
||||
|
||||
mapAveragingPin.setHigh();
|
||||
|
||||
scheduleByAngle(endAveragingScheduling, getTimeNowNt(), engine->engineState.mapAveragingDuration,
|
||||
endAveraging);
|
||||
{ endAveraging, &averager });
|
||||
}
|
||||
|
||||
void MapAverager::start() {
|
||||
|
@ -89,6 +93,8 @@ SensorResult MapAverager::submit(float volts) {
|
|||
}
|
||||
|
||||
void MapAverager::stop() {
|
||||
chibios_rt::CriticalSectionLocker csl;
|
||||
|
||||
m_isAveraging = false;
|
||||
|
||||
if (m_counter > 0) {
|
||||
|
@ -124,7 +130,7 @@ void mapAveragingAdcCallback(adcsample_t adcValue) {
|
|||
|
||||
float instantVoltage = adcToVoltsDivided(adcValue);
|
||||
|
||||
SensorResult mapResult = getMapAvg().submit(instantVoltage);
|
||||
SensorResult mapResult = getMapAvg(currentMapAverager).submit(instantVoltage);
|
||||
|
||||
if (!mapResult) {
|
||||
// hopefully this warning is not too much CPU consumption for fast ADC callback
|
||||
|
@ -138,12 +144,8 @@ void mapAveragingAdcCallback(adcsample_t adcValue) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static void endAveraging(void*) {
|
||||
#if ! EFI_UNIT_TEST
|
||||
chibios_rt::CriticalSectionLocker csl;
|
||||
#endif
|
||||
|
||||
getMapAvg().stop();
|
||||
static void endAveraging(MapAverager* arg) {
|
||||
arg->stop();
|
||||
|
||||
mapAveragingPin.setLow();
|
||||
}
|
||||
|
|
|
@ -57,4 +57,4 @@ private:
|
|||
float m_sum = 0;
|
||||
};
|
||||
|
||||
MapAverager& getMapAvg();
|
||||
MapAverager& getMapAvg(size_t idx);
|
||||
|
|
|
@ -86,6 +86,10 @@ enum class SensorType : unsigned char {
|
|||
|
||||
Maf2, // Second bank MAF sensor
|
||||
|
||||
Map2,
|
||||
MapSlow2,
|
||||
MapFast2,
|
||||
|
||||
// analog voltage inputs for Lua
|
||||
AuxAnalog1,
|
||||
AuxAnalog2,
|
||||
|
|
|
@ -13,19 +13,21 @@ static FunctionalSensor baroSensor(SensorType::BarometricPressure, MS2NT(50));
|
|||
// how the *voltage* is determined, not how its converted to a pressure.
|
||||
static LinearFunc mapConverter;
|
||||
static FunctionalSensor slowMapSensor(SensorType::MapSlow, MS2NT(50));
|
||||
static FunctionalSensor slowMapSensor2(SensorType::MapSlow2, MS2NT(50));
|
||||
|
||||
// lowest reasonable idle is maybe 600 rpm
|
||||
// one sample per cycle (1 cylinder, or "sample one cyl" mode) gives a period of 100ms
|
||||
// add some margin -> 200ms timeout for fast MAP sampling
|
||||
MapAverager fastMapSensor(SensorType::MapFast, MS2NT(200));
|
||||
MapAverager fastMapSensor2(SensorType::MapFast2, MS2NT(200));
|
||||
|
||||
MapAverager& getMapAvg() {
|
||||
return fastMapSensor;
|
||||
MapAverager& getMapAvg(size_t idx) {
|
||||
return idx == 0 ? fastMapSensor : fastMapSensor2;
|
||||
}
|
||||
|
||||
|
||||
// Combine MAP sensors: prefer fast sensor, but use slow if fast is unavailable.
|
||||
static FallbackSensor mapCombiner(SensorType::Map, SensorType::MapFast, SensorType::MapSlow);
|
||||
static FallbackSensor mapCombiner2(SensorType::Map2, SensorType::MapFast2, SensorType::MapSlow2);
|
||||
|
||||
// helper struct for the local getMapCfg function
|
||||
struct MapCfg {
|
||||
|
@ -100,11 +102,16 @@ void initMap() {
|
|||
configureMapFunction(mapConverter, engineConfiguration->map.sensor.type);
|
||||
|
||||
slowMapSensor.setFunction(mapConverter);
|
||||
slowMapSensor2.setFunction(mapConverter);
|
||||
fastMapSensor.setFunction(mapConverter);
|
||||
fastMapSensor2.setFunction(mapConverter);
|
||||
|
||||
slowMapSensor.Register();
|
||||
slowMapSensor2.Register();
|
||||
fastMapSensor.Register();
|
||||
fastMapSensor2.Register();
|
||||
mapCombiner.Register();
|
||||
mapCombiner2.Register();
|
||||
|
||||
// Configure slow MAP as a normal analog sensor
|
||||
AdcSubscription::SubscribeSensor(slowMapSensor, mapChannel, 100);
|
||||
|
|
Loading…
Reference in New Issue