rusefi-1/firmware/hw_layer/HIP9011_logic.h

82 lines
1.9 KiB
C
Raw Normal View History

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
/**
* this interface defines SPI communication channel with HIP9011 chip
*/
class HIP9011SpiChannel {
public:
void sendCommand(unsigned char command);
};
class HIP9011 {
public:
HIP9011();
2019-01-07 20:23:50 -08:00
void prepareHip9011RpmLookup(float angleWindowWidth);
int getIntegrationIndexByRpm(float rpm);
/**
* band index is only send to HIP chip on startup
*/
int currentBandIndex;
int currentGainIndex;
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-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_ */