Hip9011 and cleanups (#2477)

* hip9011: move hipCs out of EnginePins to hip9011 driver

* hip9011: cleanup debug output, save few RAM bytes

* Supress few signed vs unsigned warnings
This commit is contained in:
Andrey G 2021-03-20 15:40:36 +03:00 committed by GitHub
parent a768a2ae47
commit 89b631a794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 54 deletions

View File

@ -211,7 +211,7 @@ static void resetAccel(void) {
engine->engineLoadAccelEnrichment.resetAE();
engine->tpsAccelEnrichment.resetAE();
for (unsigned int i = 0; i < efi::size(engine->injectionEvents.elements); i++)
for (size_t i = 0; i < efi::size(engine->injectionEvents.elements); i++)
{
engine->injectionEvents.elements[i].wallFuel.resetWF();
}

View File

@ -79,7 +79,7 @@ void startSimultaniousInjection(Engine *engine) {
EXPAND_Engine;
#endif // EFI_UNIT_TEST
efitick_t nowNt = getTimeNowNt();
for (int i = 0; i < CONFIG(specs.cylindersCount); i++) {
for (size_t i = 0; i < CONFIG(specs.cylindersCount); i++) {
enginePins.injectors[i].open(nowNt PASS_ENGINE_PARAMETER_SUFFIX);
}
}
@ -89,7 +89,7 @@ static void endSimultaniousInjectionOnlyTogglePins(Engine *engine) {
EXPAND_Engine;
#endif
efitick_t nowNt = getTimeNowNt();
for (int i = 0; i < CONFIG(specs.cylindersCount); i++) {
for (size_t i = 0; i < CONFIG(specs.cylindersCount); i++) {
enginePins.injectors[i].close(nowNt PASS_ENGINE_PARAMETER_SUFFIX);
}
}

View File

@ -235,7 +235,7 @@ void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
angle_t offsetAngle = ENGINE(triggerCentral.triggerFormDetails).eventAngles[CONFIG(mapAveragingSchedulingAtIndex)];
efiAssertVoid(CUSTOM_ERR_MAP_AVG_OFFSET, !cisnan(offsetAngle), "offsetAngle");
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
angle_t cylinderOffset = getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) * i / engineConfiguration->specs.cylindersCount;
efiAssertVoid(CUSTOM_ERR_MAP_CYL_OFFSET, !cisnan(cylinderOffset), "cylinderOffset");
// part of this formula related to specific cylinder offset is never changing - we can
@ -247,7 +247,7 @@ void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
}
engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow);
} else {
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
engine->engineState.mapAveragingStart[i] = NAN;
}
engine->engineState.mapAveragingDuration = NAN;

View File

@ -410,7 +410,7 @@ void initializeIgnitionActions(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
}
efiAssertVoid(CUSTOM_ERR_6592, engineConfiguration->specs.cylindersCount > 0, "cylindersCount");
for (int cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) {
for (size_t cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) {
list->elements[cylinderIndex].cylinderIndex = cylinderIndex;
#if EFI_UNIT_TEST
list->elements[cylinderIndex].engine = engine;
@ -500,7 +500,7 @@ void onTriggerEventSparkLogic(bool limitedSpark, uint32_t trgEventIndex, int rpm
// scheduleSimpleMsg(&logger, "eventId spark ", eventIndex);
if (ENGINE(ignitionEvents.isReady)) {
for (int i = 0; i < CONFIG(specs.cylindersCount); i++) {
for (size_t i = 0; i < CONFIG(specs.cylindersCount); i++) {
IgnitionEvent *event = &ENGINE(ignitionEvents.elements[i]);
if (event->dwellPosition.triggerEventIndex != trgEventIndex)
continue;

View File

@ -73,13 +73,13 @@ extern engine_configuration_s *engineConfiguration;
static void printOutputs(const engine_configuration_s *engineConfiguration) {
scheduleMsg(&logger, "injectionPins: mode %s", getPin_output_mode_e(engineConfiguration->injectionPinMode));
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
brain_pin_e brainPin = engineConfiguration->injectionPins[i];
scheduleMsg(&logger, "injection #%d @ %s", (1 + i), hwPortname(brainPin));
}
scheduleMsg(&logger, "ignitionPins: mode %s", getPin_output_mode_e(engineConfiguration->ignitionPinMode));
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
brain_pin_e brainPin = engineConfiguration->ignitionPins[i];
scheduleMsg(&logger, "ignition #%d @ %s", (1 + i), hwPortname(brainPin));
}

View File

@ -116,8 +116,7 @@ EnginePins::EnginePins() :
alternatorPin("Alternator control", CONFIG_PIN_OFFSETS(alternatorControl)),
checkEnginePin("checkEnginePin", CONFIG_PIN_OFFSETS(malfunctionIndicator)),
tachOut("tachOut", CONFIG_PIN_OFFSETS(tachOutput)),
triggerDecoderErrorPin("led: trigger debug", CONFIG_PIN_OFFSETS(triggerError)),
hipCs("hipCs", CONFIG_PIN_OFFSETS(hip9011Cs))
triggerDecoderErrorPin("led: trigger debug", CONFIG_PIN_OFFSETS(triggerError))
{
tachOut.name = PROTOCOL_TACH_NAME;
hpfpValve.name = PROTOCOL_HPFP_NAME;
@ -274,7 +273,7 @@ void EnginePins::startAuxValves(void) {
void EnginePins::startIgnitionPins(void) {
#if EFI_PROD_CODE
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
NamedOutputPin *output = &enginePins.coils[i];
if (isPinOrModeChanged(ignitionPins[i], ignitionPinMode)) {
output->initPin(output->name, CONFIG(ignitionPins)[i], &CONFIG(ignitionPinMode));
@ -286,7 +285,7 @@ void EnginePins::startIgnitionPins(void) {
void EnginePins::startInjectionPins(void) {
#if EFI_PROD_CODE
// todo: should we move this code closer to the injection logic?
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
NamedOutputPin *output = &enginePins.injectors[i];
if (isPinOrModeChanged(injectionPins[i], injectionPinMode)) {
output->initPin(output->name, CONFIG(injectionPins)[i],

View File

@ -200,7 +200,6 @@ public:
OutputPin fsioOutputs[FSIO_COMMAND_COUNT];
RegisteredOutputPin triggerDecoderErrorPin;
RegisteredOutputPin hipCs;
OutputPin sdCsPin;
OutputPin accelerometerCs;

View File

@ -187,7 +187,7 @@ void TriggerWaveform::calculateExpectedEventCounts(bool useOnlyRisingEdgeForTrig
UNUSED(useOnlyRisingEdgeForTrigger);
if (!useOnlyRisingEdgeForTrigger) {
for (int i = 0;i<efi::size(expectedEventCount);i++) {
for (size_t i = 0; i < efi::size(expectedEventCount); i++) {
if (expectedEventCount[i] % 2 != 0) {
firmwareError(ERROR_TRIGGER_DRAMA, "Trigger: should be even %d %d", i, expectedEventCount[i]);
}

View File

@ -55,6 +55,7 @@
#if EFI_HIP_9011
static NamedOutputPin intHold(PROTOCOL_HIP_NAME);
static NamedOutputPin Cs(PROTOCOL_HIP_NAME);
class Hip9011Hardware : public Hip9011HardwareInterface {
void sendSyncCommand(unsigned char command) override;
@ -69,7 +70,6 @@ HIP9011 instance(&hardware);
static unsigned char tx_buff[1];
static unsigned char rx_buff[1];
static char pinNameBuffer[16];
static scheduling_s startTimer[2];
static scheduling_s endTimer[2];
@ -87,11 +87,11 @@ static SPIConfig hipSpiCfg = {
.ssport = NULL,
.sspad = 0,
.cr1 =
SPI_CR1_8BIT_MODE |
SPI_CR1_MSTR |
SPI_CR1_CPHA |
//SPI_CR1_BR_1 // 5MHz
SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_BR_2 |
SPI_CR1_8BIT_MODE,
SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_BR_2,
.cr2 =
SPI_CR2_8BIT_MODE
};
@ -130,50 +130,59 @@ void Hip9011Hardware::sendCommand(unsigned char command) {
EXTERN_ENGINE;
static char hipPinNameBuffer[16];
static void showHipInfo(void) {
if (!CONFIG(isHip9011Enabled)) {
scheduleMsg(logger, "hip9011 driver not active");
return;
}
printSpiState(logger, engineConfiguration);
scheduleMsg(logger, "enabled=%s state=%s bore=%.2fmm freq=%.2fkHz PaSDO=%d",
boolToString(CONFIG(isHip9011Enabled)),
getHip_state_e(instance.state),
engineConfiguration->cylinderBore, getHIP9011Band(PASS_HIP_PARAMS),
engineConfiguration->hip9011PrescalerAndSDO);
scheduleMsg(logger, "enabled=%s state=%s",
boolToString(CONFIG(isHip9011Enabled)),
getHip_state_e(instance.state));
char *outputName = getPinNameByAdcChannel("hip", engineConfiguration->hipOutputChannel, hipPinNameBuffer);
scheduleMsg(logger, " bore=%.2fmm freq=%.2fkHz",
engineConfiguration->cylinderBore,
getHIP9011Band(PASS_HIP_PARAMS));
scheduleMsg(logger, "band_index=%d gain %.2f/index=%d output=%s", instance.currentBandIndex, engineConfiguration->hip9011Gain, instance.currentGainIndex,
outputName);
scheduleMsg(logger, "integrator index=%d knockVThreshold=%.2f knockCount=%d maxKnockSubDeg=%.2f",
instance.currentIntergratorIndex, engineConfiguration->knockVThreshold,
engine->knockCount, engineConfiguration->maxKnockSubDeg);
scheduleMsg(logger, " band_index=%d integrator index=%d gain %.2f (%d) output=%s",
instance.currentBandIndex,
instance.currentIntergratorIndex,
engineConfiguration->hip9011Gain,
instance.currentGainIndex,
getAdc_channel_e(engineConfiguration->hipOutputChannel));
const char * msg = instance.invalidHip9011ResponsesCount > 0 ? "NOT GOOD" : "ok";
scheduleMsg(logger, "spi=%s IntHold@%s/%d response count=%d incorrect response=%d %s",
getSpi_device_e(engineConfiguration->hip9011SpiDevice),
hwPortname(CONFIG(hip9011IntHoldPin)),
CONFIG(hip9011IntHoldPinMode),
instance.correctResponsesCount, instance.invalidHip9011ResponsesCount,
msg);
scheduleMsg(logger, "CS@%s updateCount=%d", hwPortname(CONFIG(hip9011CsPin)), instance.settingUpdateCount);
scheduleMsg(logger, " PaSDO=0x%x",
engineConfiguration->hip9011PrescalerAndSDO);
scheduleMsg(logger, " knockVThreshold=%.2f knockCount=%d maxKnockSubDeg=%.2f",
engineConfiguration->knockVThreshold,
engine->knockCount,
engineConfiguration->maxKnockSubDeg);
scheduleMsg(logger, " spi=%s IntHold@%s(0x%x) correct response=%d incorrect response=%d (%s)",
getSpi_device_e(engineConfiguration->hip9011SpiDevice),
hwPortname(CONFIG(hip9011IntHoldPin)),
CONFIG(hip9011IntHoldPinMode),
instance.correctResponsesCount,
instance.invalidHip9011ResponsesCount,
instance.invalidHip9011ResponsesCount > 0 ? "NOT GOOD" : "ok");
scheduleMsg(logger, "CS@%s updateCount=%d",
hwPortname(CONFIG(hip9011CsPin)),
instance.settingUpdateCount);
#if EFI_PROD_CODE
scheduleMsg(logger, "hip %.2fv/last=%.2f@%s/max=%.2f adv=%d",
engine->knockVolts,
getVoltage("hipinfo", engineConfiguration->hipOutputChannel),
getPinNameByAdcChannel("hip", engineConfiguration->hipOutputChannel, pinNameBuffer),
hipValueMax,
CONFIG(useTpicAdvancedMode));
scheduleMsg(logger, "hip %.2fv/last=%.2f/max=%.2f adv=%d",
engine->knockVolts,
getVoltage("hipinfo", engineConfiguration->hipOutputChannel),
hipValueMax,
CONFIG(useTpicAdvancedMode));
printSpiConfig(logger, "hip9011", CONFIG(hip9011SpiDevice));
#endif /* EFI_PROD_CODE */
scheduleMsg(logger, "start %.2f end %.2f", engineConfiguration->knockDetectionWindowStart,
engineConfiguration->knockDetectionWindowEnd);
scheduleMsg(logger, "start %.2f end %.2f",
engineConfiguration->knockDetectionWindowStart,
engineConfiguration->knockDetectionWindowEnd);
hipValueMax = 0;
engine->printKnockState();
@ -341,15 +350,15 @@ static void hipStartupCode(void) {
static THD_WORKING_AREA(hipThreadStack, UTILITY_THREAD_STACK_SIZE);
static msg_t hipThread(void *arg) {
(void)arg;
UNUSED(arg);
chRegSetThreadName("hip9011 init");
// some time to let the hardware start
enginePins.hipCs.setValue(true);
Cs.setValue(true);
chThdSleepMilliseconds(100);
enginePins.hipCs.setValue(false);
Cs.setValue(false);
chThdSleepMilliseconds(100);
enginePins.hipCs.setValue(true);
Cs.setValue(true);
while (true) {
chThdSleepMilliseconds(100);
@ -364,12 +373,15 @@ static msg_t hipThread(void *arg) {
void stopHip9001_pins() {
intHold.deInit();
enginePins.hipCs.deInit();
Cs.deInit();
#if EFI_PROD_CODE
hipSpiCfg.ssport = NULL;
#endif
}
void startHip9001_pins() {
intHold.initPin("hip int/hold", CONFIG(hip9011IntHoldPin), &CONFIG(hip9011IntHoldPinMode));
enginePins.hipCs.initPin("hip CS", CONFIG(hip9011CsPin), &CONFIG(hip9011CsPinMode));
Cs.initPin("hip CS", CONFIG(hip9011CsPin), &CONFIG(hip9011CsPinMode));
}
void initHip9011(Logging *sharedLogger) {