2019-01-03 21:22:35 -08:00
|
|
|
/*
|
|
|
|
* @file HIP9011_logic.h
|
|
|
|
*
|
|
|
|
* Created on: Jan 3, 2019
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_LAYER_HIP9011_LOGIC_H_
|
|
|
|
#define HW_LAYER_HIP9011_LOGIC_H_
|
|
|
|
|
2019-01-03 21:51:32 -08:00
|
|
|
#include "efifeatures.h"
|
2019-01-03 21:22:35 -08:00
|
|
|
#include "rusefi_enums.h"
|
2019-01-03 21:51:32 -08:00
|
|
|
#include "hip9011_lookup.h"
|
2019-01-03 21:22:35 -08:00
|
|
|
|
|
|
|
/**
|
2019-01-07 20:55:56 -08:00
|
|
|
* this interface defines hardware communication layer for HIP9011 chip
|
2019-01-03 21:22:35 -08:00
|
|
|
*/
|
2019-01-07 20:55:56 -08:00
|
|
|
class Hip9011HardwareInterface {
|
2019-01-03 21:22:35 -08:00
|
|
|
public:
|
2019-01-07 20:55:56 -08:00
|
|
|
virtual void sendSyncCommand(unsigned char command) = 0;
|
|
|
|
virtual void sendCommand(unsigned char command) = 0;
|
2019-01-03 21:22:35 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class HIP9011 {
|
|
|
|
public:
|
2019-01-07 20:55:56 -08:00
|
|
|
HIP9011(Hip9011HardwareInterface *hardware);
|
2019-01-07 20:23:50 -08:00
|
|
|
void prepareHip9011RpmLookup(float angleWindowWidth);
|
|
|
|
int getIntegrationIndexByRpm(float rpm);
|
2019-01-07 20:55:56 -08:00
|
|
|
void setStateAndCommand(hip_state_e state, unsigned char cmd);
|
2019-01-07 20:23:50 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* band index is only send to HIP chip on startup
|
|
|
|
*/
|
|
|
|
int currentBandIndex;
|
|
|
|
int currentGainIndex;
|
2019-01-07 20:55:56 -08:00
|
|
|
int correctResponsesCount;
|
|
|
|
int invalidHip9011ResponsesCount;
|
2019-01-07 20:23:50 -08:00
|
|
|
int currentIntergratorIndex;
|
2019-01-03 21:22:35 -08:00
|
|
|
bool needToInit;
|
2019-01-07 20:23:50 -08:00
|
|
|
int settingUpdateCount;
|
|
|
|
int totalKnockEventsCount;
|
|
|
|
int currentPrescaler;
|
2019-01-07 20:55:56 -08:00
|
|
|
Hip9011HardwareInterface *hardware;
|
2019-01-03 21:22:35 -08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
hip_state_e state;
|
|
|
|
|
2019-01-07 20:23:50 -08:00
|
|
|
float rpmLookup[INT_LOOKUP_SIZE];
|
|
|
|
};
|
2019-01-03 21:22:35 -08:00
|
|
|
|
2019-01-03 21:51:32 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
|
|
|
#define PASS_HIP_PARAMS
|
|
|
|
#define DEFINE_HIP_PARAMS
|
|
|
|
#define GET_CONFIG_VALUE(x) CONFIG(x)
|
2019-01-04 06:24:23 -08:00
|
|
|
#define FORWARD_HIP_PARAMS
|
2019-01-03 21:51:32 -08:00
|
|
|
#else
|
|
|
|
|
|
|
|
#define PASS_HIP_PARAMS CONFIG(knockBandCustom), \
|
2019-01-04 16:20:32 -08:00
|
|
|
CONFIG(cylinderBore), \
|
|
|
|
CONFIG(hip9011Gain)
|
2019-01-03 21:51:32 -08:00
|
|
|
|
2019-01-04 06:24:23 -08:00
|
|
|
#define FORWARD_HIP_PARAMS knockBandCustom, \
|
2019-01-04 16:20:32 -08:00
|
|
|
cylinderBore, \
|
|
|
|
hip9011Gain
|
2019-01-04 06:24:23 -08:00
|
|
|
|
2019-01-03 21:51:32 -08:00
|
|
|
#define DEFINE_HIP_PARAMS float knockBandCustom,\
|
2019-01-04 16:20:32 -08:00
|
|
|
float cylinderBore, \
|
|
|
|
float hip9011Gain
|
2019-01-03 21:51:32 -08:00
|
|
|
|
|
|
|
#define GET_CONFIG_VALUE(x) x
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
float getHIP9011Band(DEFINE_HIP_PARAMS);
|
2019-01-04 06:24:23 -08:00
|
|
|
int getBandIndex(DEFINE_HIP_PARAMS);
|
2019-01-04 16:20:32 -08:00
|
|
|
int getHip9011GainIndex(DEFINE_HIP_PARAMS);
|
2019-01-03 21:51:32 -08:00
|
|
|
|
2019-01-03 21:22:35 -08:00
|
|
|
#endif /* HW_LAYER_HIP9011_LOGIC_H_ */
|