hip9011 compilation fix, cosmetic clean-ups (#2414)
* Board subaru eg33: has HIP9011 knock sensor * hip9011: lastExecutionCount does not exist any more * hip9011: extranc commands to header, use logic math for bitfields
This commit is contained in:
parent
0d143e2a56
commit
fbcff6f0c8
|
@ -33,6 +33,10 @@
|
|||
/* do not use serial device for console */
|
||||
#undef TS_SERIAL_DEVICE
|
||||
|
||||
/* Knock detection */
|
||||
#undef EFI_HIP_9011
|
||||
#define EFI_HIP_9011 TRUE
|
||||
|
||||
#undef BOARD_TLE6240_COUNT
|
||||
#define BOARD_TLE6240_COUNT 1
|
||||
|
||||
|
|
|
@ -56,11 +56,6 @@
|
|||
|
||||
static NamedOutputPin intHold(PROTOCOL_HIP_NAME);
|
||||
|
||||
extern uint32_t lastExecutionCount;
|
||||
|
||||
uint32_t hipLastExecutionCount;
|
||||
|
||||
|
||||
class Hip9011Hardware : public Hip9011HardwareInterface {
|
||||
void sendSyncCommand(unsigned char command) override;
|
||||
void sendCommand(unsigned char command) override;
|
||||
|
@ -191,7 +186,7 @@ void setHip9011FrankensoPinout(void) {
|
|||
// CONFIG(hip9011CsPin) = GPIOD_0; // rev 0.1
|
||||
|
||||
CONFIG(isHip9011Enabled) = true;
|
||||
engineConfiguration->hip9011PrescalerAndSDO = _8MHZ_PRESCALER; // 8MHz chip
|
||||
engineConfiguration->hip9011PrescalerAndSDO = HIP_8MHZ_PRESCALER; // 8MHz chip
|
||||
CONFIG(is_enabled_spi_2) = true;
|
||||
// todo: convert this to rusEfi, hardware-independent enum
|
||||
#if EFI_PROD_CODE
|
||||
|
@ -261,9 +256,6 @@ void intHoldCallback(trigger_event_e ckpEventType, uint32_t index, efitick_t edg
|
|||
// todo: schedule this based on closest trigger event, same as ignition works
|
||||
scheduleByAngle(&startTimer[structIndex], edgeTimestamp, engineConfiguration->knockDetectionWindowStart,
|
||||
&startIntegration);
|
||||
#if EFI_PROD_CODE
|
||||
hipLastExecutionCount = lastExecutionCount;
|
||||
#endif /* EFI_PROD_CODE */
|
||||
scheduleByAngle(&endTimer[structIndex], edgeTimestamp, engineConfiguration->knockDetectionWindowEnd,
|
||||
&endIntegration);
|
||||
}
|
||||
|
@ -316,29 +308,14 @@ void hipAdcCallback(adcsample_t adcValue) {
|
|||
}
|
||||
|
||||
static void hipStartupCode(void) {
|
||||
// D[4:1] = 0000 : 4 MHz
|
||||
// D[4:1] = 0001 : 5 MHz
|
||||
// D[4:1] = 0010 : 6 MHz
|
||||
// D[4:1] = 0011 ; 8 MHz
|
||||
// D[4:1] = 0100 ; 10 MHz
|
||||
// D[4:1] = 0101 ; 12 MHz
|
||||
// D[4:1] = 0110 : 16 MHz
|
||||
// D[4:1] = 0111 : 20 MHz
|
||||
// D[4:1] = 1000 : 24 MHz
|
||||
|
||||
|
||||
// 0 for 4MHz
|
||||
// 6 for 8 MHz
|
||||
instance.currentPrescaler = engineConfiguration->hip9011PrescalerAndSDO;
|
||||
instance.hardware->sendSyncCommand(SET_PRESCALER_CMD + instance.currentPrescaler);
|
||||
|
||||
instance.hardware->sendSyncCommand(SET_PRESCALER_CMD(instance.currentPrescaler));
|
||||
|
||||
// '0' for channel #1
|
||||
instance.hardware->sendSyncCommand(SET_CHANNEL_CMD + 0);
|
||||
instance.hardware->sendSyncCommand(SET_CHANNEL_CMD(0));
|
||||
|
||||
// band index depends on cylinder bore
|
||||
instance.hardware->sendSyncCommand(SET_BAND_PASS_CMD + instance.currentBandIndex);
|
||||
|
||||
instance.hardware->sendSyncCommand(SET_BAND_PASS_CMD(instance.currentBandIndex));
|
||||
|
||||
if (instance.correctResponsesCount == 0) {
|
||||
warning(CUSTOM_OBD_KNOCK_PROCESSOR, "TPIC/HIP does not respond");
|
||||
|
@ -346,7 +323,7 @@ static void hipStartupCode(void) {
|
|||
|
||||
if (CONFIG(useTpicAdvancedMode)) {
|
||||
// enable advanced mode for digital integrator output
|
||||
instance.hardware->sendSyncCommand(SET_ADVANCED_MODE);
|
||||
instance.hardware->sendSyncCommand(SET_ADVANCED_MODE_CMD);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// 0b01110001
|
||||
#define SET_ADVANCED_MODE 0x71
|
||||
|
||||
#define HIP_THREAD_PERIOD 100
|
||||
|
||||
void initHip9011(Logging *sharedLogger);
|
||||
|
|
|
@ -85,20 +85,19 @@ void HIP9011::handleValue(int rpm DEFINE_PARAM_SUFFIX(DEFINE_HIP_PARAMS)) {
|
|||
int gainIndex = getHip9011GainIndex(FORWARD_HIP_PARAMS);
|
||||
int bandIndex = getBandIndex(FORWARD_HIP_PARAMS);
|
||||
|
||||
|
||||
if (currentGainIndex != gainIndex) {
|
||||
currentGainIndex = gainIndex;
|
||||
setStateAndCommand(SET_GAIN_CMD + gainIndex);
|
||||
setStateAndCommand(SET_GAIN_CMD(gainIndex));
|
||||
|
||||
} else if (currentIntergratorIndex != integratorIndex) {
|
||||
currentIntergratorIndex = integratorIndex;
|
||||
setStateAndCommand(SET_INTEGRATOR_CMD + integratorIndex);
|
||||
setStateAndCommand(SET_INTEGRATOR_CMD(integratorIndex));
|
||||
} else if (currentBandIndex != bandIndex) {
|
||||
currentBandIndex = bandIndex;
|
||||
setStateAndCommand(SET_BAND_PASS_CMD + bandIndex);
|
||||
setStateAndCommand(SET_BAND_PASS_CMD(bandIndex));
|
||||
} else if (currentPrescaler != prescalerIndex) {
|
||||
currentPrescaler = prescalerIndex;
|
||||
setStateAndCommand(SET_PRESCALER_CMD + prescalerIndex);
|
||||
setStateAndCommand(SET_PRESCALER_CMD(prescalerIndex));
|
||||
|
||||
} else {
|
||||
state = READY_TO_INTEGRATE;
|
||||
|
|
|
@ -99,20 +99,35 @@ float getHIP9011Band(DEFINE_HIP_PARAMS);
|
|||
int getBandIndex(DEFINE_HIP_PARAMS);
|
||||
int getHip9011GainIndex(DEFINE_HIP_PARAMS);
|
||||
|
||||
// 0b01000000
|
||||
#define SET_PRESCALER_CMD 0x40
|
||||
// 0b010x.xxxx
|
||||
#define SET_PRESCALER_CMD(v) (0x40 | ((v) & 0x1f))
|
||||
// 0b1110.000x
|
||||
#define SET_CHANNEL_CMD(v) (0xE0 | ((v) & 0x01))
|
||||
// 0b00xx.xxxx
|
||||
#define SET_BAND_PASS_CMD(v) (0x00 | ((v) & 0x3f))
|
||||
// 0b10xx.xxxx
|
||||
#define SET_GAIN_CMD(v) (0x80 | ((v) & 0x3f))
|
||||
// 0b110x.xxxx
|
||||
#define SET_INTEGRATOR_CMD(v) (0xC0 | ((v) & 0x1f))
|
||||
// 0b0111.0001
|
||||
#define SET_ADVANCED_MODE_CMD (0x71)
|
||||
|
||||
// 0b11100000
|
||||
#define SET_CHANNEL_CMD 0xE0
|
||||
|
||||
// 0b11000000
|
||||
#define SET_INTEGRATOR_CMD 0xC0
|
||||
|
||||
// 0b00000000
|
||||
#define SET_BAND_PASS_CMD 0x0
|
||||
|
||||
// 0b10000000
|
||||
#define SET_GAIN_CMD 0x80
|
||||
|
||||
#define _8MHZ_PRESCALER 6
|
||||
// D[4:1] = 0000 : 4 MHz
|
||||
#define HIP_4MHZ_PRESCALER (0x0 << 1)
|
||||
// D[4:1] = 0001 : 5 MHz
|
||||
#define HIP_5MHZ_PRESCALER (0x1 << 1)
|
||||
// D[4:1] = 0010 : 6 MHz
|
||||
#define HIP_6MHZ_PRESCALER (0x2 << 1)
|
||||
// D[4:1] = 0011 ; 8 MHz
|
||||
#define HIP_8MHZ_PRESCALER (0x3 << 1)
|
||||
// D[4:1] = 0100 ; 10 MHz
|
||||
#define HIP_10MHZ_PRESCALER (0x4 << 1)
|
||||
// D[4:1] = 0101 ; 12 MHz
|
||||
#define HIP_12MHZ_PRESCALER (0x5 << 1)
|
||||
// D[4:1] = 0110 : 16 MHz
|
||||
#define HIP_16MHZ_PRESCALER (0x6 << 1)
|
||||
// D[4:1] = 0111 : 20 MHz
|
||||
#define HIP_20MHZ_PRESCALER (0x7 << 1)
|
||||
// D[4:1] = 1000 : 24 MHz
|
||||
#define HIP_24MHZ_PRESCALER (0x8 << 1)
|
||||
|
||||
|
|
|
@ -61,23 +61,23 @@ TEST(hip9011, configurationCommands) {
|
|||
HIP9011 instance(&mock);
|
||||
|
||||
// want to invoke method with same parameters a few times
|
||||
#define PARAMETERS 600, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1, _8MHZ_PRESCALER, 0.0, 50.0
|
||||
#define PARAMETERS 600, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1, HIP_8MHZ_PRESCALER, 0.0, 50.0
|
||||
|
||||
// Not making assumptions on the message send ...
|
||||
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
|
||||
EXPECT_CALL(mock, sendCommand(SET_GAIN_CMD + 0xE)).Times(1);
|
||||
EXPECT_CALL(mock, sendCommand(SET_GAIN_CMD(0xE))).Times(1);
|
||||
instance.handleValue(PARAMETERS);
|
||||
|
||||
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
|
||||
EXPECT_CALL(mock, sendCommand(SET_INTEGRATOR_CMD + 0x1C)).Times(1);
|
||||
EXPECT_CALL(mock, sendCommand(SET_INTEGRATOR_CMD(0x1C))).Times(1);
|
||||
instance.handleValue(PARAMETERS);
|
||||
|
||||
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
|
||||
EXPECT_CALL(mock, sendCommand(SET_BAND_PASS_CMD + 0x2A)).Times(1);
|
||||
EXPECT_CALL(mock, sendCommand(SET_BAND_PASS_CMD(0x2A))).Times(1);
|
||||
instance.handleValue(PARAMETERS);
|
||||
|
||||
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);
|
||||
EXPECT_CALL(mock, sendCommand(SET_PRESCALER_CMD + 6)).Times(1);
|
||||
EXPECT_CALL(mock, sendCommand(SET_PRESCALER_CMD(6))).Times(1);
|
||||
instance.handleValue(PARAMETERS);
|
||||
|
||||
// initialization is over, no commands should be sent
|
||||
|
|
Loading…
Reference in New Issue