rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
HIP9011 Class Reference

#include <hip9011_logic.h>

Collaboration diagram for HIP9011:
Collaboration graph
[legend]

Public Member Functions

 HIP9011 (Hip9011HardwareInterface *hardware)
 
int sendCommand (uint8_t cmd)
 
int sendCommandGetReply (uint8_t cmd, uint8_t *reply)
 
float getRpmByAngleWindowAndTimeUs (int timeUs, float angleWindowWidth)
 
void prepareRpmLookup (void)
 
void setAngleWindowWidth (DEFINE_HIP_PARAMS)
 
void handleSettings (int rpm DEFINE_PARAM_SUFFIX(DEFINE_HIP_PARAMS))
 
int cylinderToChannelIdx (int cylinder)
 
int handleChannel (DEFINE_HIP_PARAMS)
 
int readValueAndHandleChannel (DEFINE_HIP_PARAMS)
 
float getBand (DEFINE_HIP_PARAMS)
 
int getIntegrationIndexByRpm (float rpm)
 
int getIntegrationTimeByIndex (int index)
 
int getBandIndex (DEFINE_HIP_PARAMS)
 
int getGainIndex (DEFINE_HIP_PARAMS)
 

Data Fields

uint8_t intergratorIdx = 0xff
 
uint8_t bandIdx = 0xff
 
uint8_t prescaler = 0xff
 
uint8_t gainIdx = 0xff
 
uint8_t channelIdx = 0xff
 
float angleWindowWidth = - 1
 
Hip9011HardwareInterfacehw
 
bool adv_mode = false
 
hip_state_e state
 
int8_t cylinderNumber = -1
 
int8_t expectedCylinderNumber = -1
 
uint16_t rawValue [HIP_INPUT_CHANNELS]
 
uint16_t rpmLookup [INT_LOOKUP_SIZE]
 
efitick_t knockSampleTimestamp = 0
 
int correctResponsesCount = 0
 
int invalidResponsesCount = 0
 
int samples = 0
 
int overrun = 0
 
int unsync = 0
 

Detailed Description

Definition at line 80 of file hip9011_logic.h.

Constructor & Destructor Documentation

◆ HIP9011()

HIP9011::HIP9011 ( Hip9011HardwareInterface hardware)
explicit

Definition at line 64 of file hip9011_logic.cpp.

64 {
65 this->hw = hardware;
66}
Hip9011HardwareInterface * hw
static Hip9011Hardware hardware
Definition hip9011.cpp:81

Member Function Documentation

◆ cylinderToChannelIdx()

int HIP9011::cylinderToChannelIdx ( int  cylinder)

Definition at line 191 of file hip9011_logic.cpp.

191 {
192 /* TODO: hip9011 inputs to bank mapping? */
193 return getCylinderKnockBank(cylinder);
194}
int getCylinderKnockBank(uint8_t cylinderNumber)

Referenced by handleChannel(), and readValueAndHandleChannel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBand()

float HIP9011::getBand ( DEFINE_HIP_PARAMS  )
Returns
frequency band we are interested in

Definition at line 79 of file hip9011_logic.cpp.

79 {
80 return bore2frequency(GET_CONFIG_VALUE(cylinderBore));
81}

Referenced by getBandIndex(), and showHipInfo().

Here is the caller graph for this function:

◆ getBandIndex()

int HIP9011::getBandIndex ( DEFINE_HIP_PARAMS  )

Definition at line 83 of file hip9011_logic.cpp.

83 {
84 float freq = getBand(FORWARD_HIP_PARAMS);
85 int i = findIndexMsg("freq", bandFreqLookup, BAND_LOOKUP_SIZE, freq);
86 if (i < 0)
87 i = 0;
88 if (i > BAND_LOOKUP_SIZE - 1)
89 i = BAND_LOOKUP_SIZE - 1;
90
91 return i;
92}
float getBand(DEFINE_HIP_PARAMS)
int findIndexMsg(const char *msg, const kType array[], int size, kType value)
Binary search.
const float bandFreqLookup[BAND_LOOKUP_SIZE]

Referenced by handleSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGainIndex()

int HIP9011::getGainIndex ( DEFINE_HIP_PARAMS  )

Definition at line 94 of file hip9011_logic.cpp.

94 {
95 int i = findIndexMsg("fGain", gainLookupInReverseOrder, GAIN_LOOKUP_SIZE, GET_CONFIG_VALUE(hip9011Gain));
96 if (i < 0)
97 i = 0;
98 if (i > GAIN_LOOKUP_SIZE - 1)
99 i = GAIN_LOOKUP_SIZE - 1;
100
101 /* reverse order */
102 return GAIN_LOOKUP_SIZE - 1 - i;
103}
const float gainLookupInReverseOrder[GAIN_LOOKUP_SIZE]

Referenced by handleSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIntegrationIndexByRpm()

int HIP9011::getIntegrationIndexByRpm ( float  rpm)

Definition at line 135 of file hip9011_logic.cpp.

135 {
136 int i = findIndexMsg("getIbR", rpmLookup, INT_LOOKUP_SIZE, (uint16_t)(rpm));
137 return i == -1 ? INT_LOOKUP_SIZE - 1 : INT_LOOKUP_SIZE - i - 1;
138}
uint16_t rpmLookup[INT_LOOKUP_SIZE]

Referenced by handleSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIntegrationTimeByIndex()

int HIP9011::getIntegrationTimeByIndex ( int  index)

Definition at line 140 of file hip9011_logic.cpp.

140 {
141 return integratorValues[index & 0x1f];
142}
const int integratorValues[INT_LOOKUP_SIZE]

Referenced by showHipInfo().

Here is the caller graph for this function:

◆ getRpmByAngleWindowAndTimeUs()

float HIP9011::getRpmByAngleWindowAndTimeUs ( int  timeUs,
float  p_angleWindowWidth 
)

'TC is typically TINT/(2*Pi*VOUT)' Knock Sensor Training TPIC8101, page 24

TINT = TC * 2 * PI * VOUT

rpm = 60 seconds / time '60000000' because revolutions per MINUTE in uS conversion

Definition at line 109 of file hip9011_logic.cpp.

109 {
110 /**
111 * TINT = TC * 2 * PI * VOUT
112 */
113 float integrationTimeUs = timeUs * 2 * CONST_PI * HIP9011_ANALOG_OUTPUT_MAX;
114 /**
115 * rpm = 60 seconds / time
116 * '60000000' because revolutions per MINUTE in uS conversion
117 */
118 float windowWidthMult = p_angleWindowWidth / 360.0f;
119 return (60.0f * 1000.0f * 1000.0f) / integrationTimeUs * windowWidthMult;
120}

Referenced by prepareRpmLookup().

Here is the caller graph for this function:

◆ handleChannel()

int HIP9011::handleChannel ( DEFINE_HIP_PARAMS  )

Definition at line 196 of file hip9011_logic.cpp.

196 {
197 int ret;
198
199 /* we did not receive any callback from spark logic with valid cylinder yet */
200 if (cylinderNumber < 0)
201 return -1;
202
203 /* find next firing cylinder */
204 /* MAGIC +1 -1, couse getNextFiringCylinderId expect cylinders to start from 1 */
206
207 int nextChannelIdx = cylinderToChannelIdx(expectedCylinderNumber);
208 if (nextChannelIdx == channelIdx)
209 return 0;
210
211 ret = sendCommand(SET_CHANNEL_CMD(nextChannelIdx));
212 if (ret)
213 return ret;
214
215 channelIdx = nextChannelIdx;
216
217 return 0;
218}
int cylinderToChannelIdx(int cylinder)
uint8_t channelIdx
int8_t cylinderNumber
int8_t expectedCylinderNumber
int sendCommand(uint8_t cmd)
size_t getNextFiringCylinderId(size_t prevCylinderId)

Referenced by hipThread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleSettings()

void HIP9011::handleSettings ( int rpm   DEFINE_PARAM_SUFFIXDEFINE_HIP_PARAMS)

Definition at line 159 of file hip9011_logic.cpp.

159 {
160 int ret;
161
162 setAngleWindowWidth(FORWARD_HIP_PARAMS);
163
164 uint8_t new_prescaler = GET_CONFIG_VALUE(hip9011Prescaler);
165 uint8_t new_integratorIdx = getIntegrationIndexByRpm(rpm);
166 uint8_t new_gainIdx = getGainIndex(FORWARD_HIP_PARAMS);
167 uint8_t new_bandIdx = getBandIndex(FORWARD_HIP_PARAMS);
168
169 if (gainIdx != new_gainIdx) {
170 ret = sendCommand(SET_GAIN_CMD(new_gainIdx));
171 if (ret == 0)
172 gainIdx = new_gainIdx;
173 }
174 if (intergratorIdx != new_integratorIdx) {
175 ret = sendCommand(SET_INTEGRATOR_CMD(new_integratorIdx));
176 if (ret == 0)
177 intergratorIdx = new_integratorIdx;
178 }
179 if (bandIdx != new_bandIdx) {
180 ret = sendCommand(SET_BAND_PASS_CMD(new_bandIdx));
181 if (ret == 0)
182 bandIdx = new_bandIdx;
183 }
184 if (prescaler != new_prescaler) {
185 ret = sendCommand(SET_PRESCALER_CMD(new_prescaler));
186 if (ret == 0)
187 prescaler = new_prescaler;
188 }
189}
uint8_t intergratorIdx
int getBandIndex(DEFINE_HIP_PARAMS)
int getGainIndex(DEFINE_HIP_PARAMS)
uint8_t bandIdx
uint8_t prescaler
void setAngleWindowWidth(DEFINE_HIP_PARAMS)
int getIntegrationIndexByRpm(float rpm)
uint8_t gainIdx

Referenced by hipThread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepareRpmLookup()

void HIP9011::prepareRpmLookup ( void  )

We know the set of possible integration times, we know the knock detection window width

out binary search method needs increasing order thus the reverse order here

Definition at line 126 of file hip9011_logic.cpp.

126 {
127 /**
128 * out binary search method needs increasing order thus the reverse order here
129 */
130 for (int i = 0; i < INT_LOOKUP_SIZE; i++) {
132 }
133}
float getRpmByAngleWindowAndTimeUs(int timeUs, float angleWindowWidth)
float angleWindowWidth

Referenced by setAngleWindowWidth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readValueAndHandleChannel()

int HIP9011::readValueAndHandleChannel ( DEFINE_HIP_PARAMS  )

Definition at line 220 of file hip9011_logic.cpp.

220 {
221 int ret;
222 uint8_t rx[2];
223
224 /* we did not receive any callback from spark logic with valid cylinder yet */
225 if (cylinderNumber < 0)
226 return -1;
227
228 /* find next firing cylinder */
229 /* MAGIC +1 -1, couse getNextFiringCylinderId expect cylinders to start from 1 */
231
232 int nextChannelIdx = cylinderToChannelIdx(expectedCylinderNumber);
233
234 /* use cached values, let handleSettings take care of settings update */
235 /* don't care about rx'ed data now */
236 ret = sendCommand(SET_PRESCALER_CMD(prescaler));
237 if (ret)
238 return ret;
239
240 /* reply from Set Prescaler CMD -> D7 to D0 of the digital integrator output */
241 ret = sendCommandGetReply(SET_CHANNEL_CMD(nextChannelIdx), &rx[0]);
242 if (ret)
243 return ret;
244
245 /* Same connand to get reply for previous command:
246 * reply from Select the channel CMD -> D9 to D8 of difital integrator output and six zeroes */
247 ret = sendCommandGetReply(SET_CHANNEL_CMD(nextChannelIdx), &rx[1]);
248 if (ret)
249 return ret;
250
251 channelIdx = nextChannelIdx;
252
253 /* D9..D8 in high bits */
254 rx[1] = (rx[1] >> 6) & 0x03;
255
256 /* return digital integrator value */
257 return (rx[0] | (rx[1] << 8));
258}
int sendCommandGetReply(uint8_t cmd, uint8_t *reply)

Referenced by hipThread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendCommand()

int HIP9011::sendCommand ( uint8_t  cmd)

Definition at line 68 of file hip9011_logic.cpp.

68 {
69 return hw->sendSyncCommand(cmd, NULL);
70}
virtual int sendSyncCommand(unsigned char command, uint8_t *rx_ptr)=0

Referenced by handleChannel(), handleSettings(), and readValueAndHandleChannel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendCommandGetReply()

int HIP9011::sendCommandGetReply ( uint8_t  cmd,
uint8_t *  reply 
)

Definition at line 72 of file hip9011_logic.cpp.

72 {
73 return hw->sendSyncCommand(cmd, reply);
74}

Referenced by readValueAndHandleChannel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAngleWindowWidth()

void HIP9011::setAngleWindowWidth ( DEFINE_HIP_PARAMS  )

Definition at line 144 of file hip9011_logic.cpp.

144 {
145 float new_angleWindowWidth = GET_CONFIG_VALUE(knockSamplingDuration);
146 if (new_angleWindowWidth < 0) {
147#if EFI_PROD_CODE
148 warning(ObdCode::CUSTOM_KNOCK_WINDOW, "invalid knock window");
149#endif
150 new_angleWindowWidth = 0;
151 }
152 // float '==' is totally appropriate here
153 if (angleWindowWidth == new_angleWindowWidth)
154 return; // exit if value has not change
155 angleWindowWidth = new_angleWindowWidth;
157}
void prepareRpmLookup(void)
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_KNOCK_WINDOW

Referenced by handleSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ adv_mode

bool HIP9011::adv_mode = false

Definition at line 109 of file hip9011_logic.h.

Referenced by endIntegration(), hip_init(), hipAdcCallback(), hipThread(), and showHipInfo().

◆ angleWindowWidth

float HIP9011::angleWindowWidth = - 1

Definition at line 106 of file hip9011_logic.h.

Referenced by prepareRpmLookup(), and setAngleWindowWidth().

◆ bandIdx

uint8_t HIP9011::bandIdx = 0xff

Definition at line 101 of file hip9011_logic.h.

Referenced by handleSettings(), and showHipInfo().

◆ channelIdx

uint8_t HIP9011::channelIdx = 0xff

◆ correctResponsesCount

int HIP9011::correctResponsesCount = 0

Definition at line 133 of file hip9011_logic.h.

Referenced by hip_init(), and showHipInfo().

◆ cylinderNumber

int8_t HIP9011::cylinderNumber = -1

◆ expectedCylinderNumber

int8_t HIP9011::expectedCylinderNumber = -1

◆ gainIdx

uint8_t HIP9011::gainIdx = 0xff

Definition at line 103 of file hip9011_logic.h.

Referenced by handleSettings(), and showHipInfo().

◆ hw

Definition at line 108 of file hip9011_logic.h.

Referenced by HIP9011(), hip_init(), hip_testAdvMode(), sendCommand(), and sendCommandGetReply().

◆ intergratorIdx

uint8_t HIP9011::intergratorIdx = 0xff

Definition at line 100 of file hip9011_logic.h.

Referenced by handleSettings(), and showHipInfo().

◆ invalidResponsesCount

int HIP9011::invalidResponsesCount = 0

Definition at line 134 of file hip9011_logic.h.

Referenced by hip_init(), showHipInfo(), and updateTunerStudioState().

◆ knockSampleTimestamp

efitick_t HIP9011::knockSampleTimestamp = 0

Definition at line 129 of file hip9011_logic.h.

Referenced by endIntegration(), and hipThread().

◆ overrun

int HIP9011::overrun = 0

Definition at line 138 of file hip9011_logic.h.

Referenced by hip_init(), showHipInfo(), and startIntegration().

◆ prescaler

uint8_t HIP9011::prescaler = 0xff

◆ rawValue

uint16_t HIP9011::rawValue[HIP_INPUT_CHANNELS]

Definition at line 123 of file hip9011_logic.h.

Referenced by hipAdcCallback(), hipThread(), and showHipInfo().

◆ rpmLookup

uint16_t HIP9011::rpmLookup[INT_LOOKUP_SIZE]

Definition at line 126 of file hip9011_logic.h.

Referenced by getIntegrationIndexByRpm(), prepareRpmLookup(), and showHipInfo().

◆ samples

int HIP9011::samples = 0

Definition at line 137 of file hip9011_logic.h.

Referenced by hip_init(), hipThread(), and showHipInfo().

◆ state

hip_state_e HIP9011::state

Int/Hold pin is controlled from scheduler call-backs which are set according to current RPM

The following state makes sure that we only have SPI communication while not integrating and that we take a good ADC reading after integrating.

Once integration window is over, we wait for the 2nd ADC callback and then initiate SPI communication if needed

hipOutput should be set to used FAST adc device

Definition at line 120 of file hip9011_logic.h.

Referenced by endIntegration(), hip9011_onFireEvent(), hip_init(), hipAdcCallback(), hipThread(), showHipInfo(), and startIntegration().

◆ unsync

int HIP9011::unsync = 0

Definition at line 139 of file hip9011_logic.h.

Referenced by hip9011_onFireEvent(), hip_init(), and showHipInfo().


The documentation for this class was generated from the following files: