2015-07-10 06:01:56 -07:00
/*
* @ file trigger_central . cpp
2017-12-12 14:26:23 -08:00
* Here we have a bunch of higher - level methods which are not directly related to actual signal decoding
2015-07-10 06:01:56 -07:00
*
* @ date Feb 23 , 2014
2020-01-07 21:02:40 -08:00
* @ author Andrey Belomutskiy , ( c ) 2012 - 2020
2015-07-10 06:01:56 -07:00
*/
2018-09-16 19:26:57 -07:00
# include "global.h"
2019-07-04 00:57:21 -07:00
# include "os_access.h"
2015-07-10 06:01:56 -07:00
# include "trigger_central.h"
# include "trigger_decoder.h"
# include "main_trigger_callback.h"
# include "engine_configuration.h"
# include "listener_array.h"
# include "pwm_generator_logic.h"
2019-07-06 17:48:58 -07:00
# include "tooth_logger.h"
2020-10-17 05:00:11 -07:00
# include "hip9011.h"
# include "logic_analyzer.h"
2019-03-31 14:44:34 -07:00
2015-07-10 06:01:56 -07:00
# include "settings.h"
2016-08-20 20:02:09 -07:00
# include "engine_math.h"
2019-03-31 13:56:13 -07:00
# include "local_version_holder.h"
2017-10-16 11:08:45 -07:00
# include "trigger_simulator.h"
2021-04-22 18:23:20 -07:00
# include "trigger_emulator_algo.h"
2015-07-10 06:01:56 -07:00
# include "rpm_calculator.h"
2020-04-15 16:10:54 -07:00
# include "tooth_logger.h"
2019-10-11 17:43:21 -07:00
# include "perf_trace.h"
2020-10-03 22:43:02 -07:00
# include "map_averaging.h"
# include "main_trigger_callback.h"
2019-10-11 17:43:21 -07:00
2019-07-06 17:15:49 -07:00
# if EFI_PROD_CODE
# include "pin_repository.h"
# endif /* EFI_PROD_CODE */
# if EFI_TUNER_STUDIO
# include "tunerstudio.h"
# endif /* EFI_TUNER_STUDIO */
# if EFI_ENGINE_SNIFFER
# include "engine_sniffer.h"
WaveChart waveChart ;
# endif /* EFI_ENGINE_SNIFFER */
2019-06-30 06:38:51 -07:00
trigger_central_s : : trigger_central_s ( ) : hwEventCounters ( ) {
}
2021-01-26 19:54:25 -08:00
TriggerCentral : : TriggerCentral ( ) : trigger_central_s ( ) ,
vvtPosition ( ) ,
vvtSyncTimeNt ( ) {
2019-01-31 14:55:23 -08:00
triggerState . resetTriggerState ( ) ;
2020-01-27 21:16:33 -08:00
noiseFilter . resetAccumSignalData ( ) ;
2019-01-31 14:55:23 -08:00
}
2020-10-04 16:29:26 -07:00
void TriggerCentral : : init ( DECLARE_ENGINE_PARAMETER_SIGNATURE ) {
INJECT_ENGINE_REFERENCE ( & triggerState ) ;
2021-01-26 18:16:47 -08:00
for ( int bankIndex = 0 ; bankIndex < BANKS_COUNT ; bankIndex + + ) {
2021-02-08 17:38:38 -08:00
for ( int camIndex = 0 ; camIndex < CAMS_PER_BANK ; camIndex + + ) {
INJECT_ENGINE_REFERENCE ( & vvtState [ bankIndex ] [ camIndex ] ) ;
}
2021-01-26 18:16:47 -08:00
}
2020-10-04 16:29:26 -07:00
}
2020-01-27 21:16:33 -08:00
void TriggerNoiseFilter : : resetAccumSignalData ( ) {
2019-01-31 14:55:23 -08:00
memset ( lastSignalTimes , 0xff , sizeof ( lastSignalTimes ) ) ; // = -1
memset ( accumSignalPeriods , 0 , sizeof ( accumSignalPeriods ) ) ;
memset ( accumSignalPrevPeriods , 0 , sizeof ( accumSignalPrevPeriods ) ) ;
}
2019-06-08 06:51:36 -07:00
int TriggerCentral : : getHwEventCounter ( int index ) const {
2019-01-31 14:55:23 -08:00
return hwEventCounters [ index ] ;
}
2019-04-12 19:07:03 -07:00
# if EFI_SHAFT_POSITION_INPUT
2019-01-31 14:55:23 -08:00
2015-09-13 14:02:44 -07:00
EXTERN_ENGINE ;
2021-03-25 04:39:23 -07:00
angle_t TriggerCentral : : getVVTPosition ( uint8_t bankIndex , uint8_t camIndex ) {
2021-05-27 02:50:59 -07:00
if ( bankIndex > = BANKS_COUNT | | camIndex > = CAMS_PER_BANK ) {
return NAN ;
}
2021-03-25 04:39:23 -07:00
return vvtPosition [ bankIndex ] [ camIndex ] ;
2020-01-30 22:49:10 -08:00
}
2020-04-05 08:43:45 -07:00
# define miataNbIndex (0)
2020-03-09 13:59:19 -07:00
2021-04-04 19:05:55 -07:00
// todo: should we hard-code the list of 'not real decoder' modes instead of adding to list of 'real decoders'? these days we only add 'real decode' modes
2020-08-29 15:37:13 -07:00
static bool vvtWithRealDecoder ( vvt_mode_e vvtMode ) {
2021-02-08 15:20:53 -08:00
return vvtMode = = VVT_MIATA_NB2
2020-10-03 07:39:43 -07:00
| | vvtMode = = VVT_BOSCH_QUICK_START
2020-12-03 20:54:08 -08:00
| | vvtMode = = VVT_FORD_ST170
2021-03-25 04:39:23 -07:00
| | vvtMode = = VVT_4_1
| | vvtMode = = VVT_BARRA_3_PLUS_1 ;
2020-08-29 15:37:13 -07:00
}
2021-01-31 19:24:45 -08:00
void hwHandleVvtCamSignal ( trigger_value_e front , efitick_t nowNt , int index DECLARE_ENGINE_PARAMETER_SUFFIX ) {
2021-02-08 18:28:57 -08:00
int bankIndex = index / CAMS_PER_BANK ;
int camIndex = index % CAMS_PER_BANK ;
2019-09-02 18:02:08 -07:00
TriggerCentral * tc = & engine - > triggerCentral ;
if ( front = = TV_RISE ) {
tc - > vvtEventRiseCounter + + ;
} else {
tc - > vvtEventFallCounter + + ;
}
2021-04-25 06:18:35 -07:00
extern const char * vvtNames [ ] ;
2021-04-25 06:34:40 -07:00
const char * vvtName = vvtNames [ index ] ;
2019-09-02 18:02:08 -07:00
2020-12-21 10:33:09 -08:00
# if VR_HW_CHECK_MODE
// some boards do not have hardware VR input LEDs which makes such boards harder to validate
// from experience we know that assembly mistakes happen and quality control is required
extern ioportid_t criticalErrorLedPort ;
extern ioportmask_t criticalErrorLedPin ;
2021-04-22 18:23:20 -07:00
2020-12-21 10:33:09 -08:00
for ( int i = 0 ; i < 100 ; i + + ) {
// turning pin ON and busy-waiting a bit
palWritePad ( criticalErrorLedPort , criticalErrorLedPin , 1 ) ;
}
palWritePad ( criticalErrorLedPort , criticalErrorLedPin , 0 ) ;
# endif // VR_HW_CHECK_MODE
2020-04-15 16:10:54 -07:00
if ( ! CONFIG ( displayLogicLevelsInEngineSniffer ) ) {
2021-04-25 06:18:35 -07:00
addEngineSnifferEvent ( vvtName , front = = TV_RISE ? PROTOCOL_ES_UP : PROTOCOL_ES_DOWN ) ;
2020-05-15 13:35:18 -07:00
# if EFI_TOOTH_LOGGER
if ( front = = TV_RISE ) {
LogTriggerTooth ( SHAFT_SECONDARY_RISING , nowNt PASS_ENGINE_PARAMETER_SUFFIX ) ;
} else {
LogTriggerTooth ( SHAFT_SECONDARY_FALLING , nowNt PASS_ENGINE_PARAMETER_SUFFIX ) ;
}
# endif /* EFI_TOOTH_LOGGER */
2020-04-15 16:10:54 -07:00
}
2019-09-02 18:02:08 -07:00
2016-08-23 20:03:01 -07:00
2021-04-04 20:03:51 -07:00
bool isImportantFront = ( CONFIG ( vvtCamSensorUseRise ) ^ ( front = = TV_FALL ) ) ;
if ( ! vvtWithRealDecoder ( engineConfiguration - > vvtMode [ camIndex ] ) & & ! isImportantFront ) {
2020-08-29 15:37:13 -07:00
// todo: there should be a way to always use real trigger code for this logic?
2016-08-23 20:03:01 -07:00
return ;
}
2021-04-04 20:12:07 -07:00
if ( CONFIG ( displayLogicLevelsInEngineSniffer ) & & isImportantFront ) {
2020-04-15 16:10:54 -07:00
if ( CONFIG ( vvtCamSensorUseRise ) ) {
// todo: unify TS composite logger code with console Engine Sniffer
// todo: better API to reduce copy/paste?
2020-04-15 18:09:05 -07:00
# if EFI_TOOTH_LOGGER
2020-04-15 16:50:07 -07:00
LogTriggerTooth ( SHAFT_SECONDARY_RISING , nowNt PASS_ENGINE_PARAMETER_SUFFIX ) ;
LogTriggerTooth ( SHAFT_SECONDARY_FALLING , nowNt PASS_ENGINE_PARAMETER_SUFFIX ) ;
2020-04-15 18:09:05 -07:00
# endif /* EFI_TOOTH_LOGGER */
2021-04-25 06:18:35 -07:00
addEngineSnifferEvent ( vvtName , PROTOCOL_ES_UP ) ;
addEngineSnifferEvent ( vvtName , PROTOCOL_ES_DOWN ) ;
2020-04-15 16:10:54 -07:00
} else {
2020-04-15 18:09:05 -07:00
# if EFI_TOOTH_LOGGER
2020-04-15 16:50:07 -07:00
LogTriggerTooth ( SHAFT_SECONDARY_FALLING , nowNt PASS_ENGINE_PARAMETER_SUFFIX ) ;
LogTriggerTooth ( SHAFT_SECONDARY_RISING , nowNt PASS_ENGINE_PARAMETER_SUFFIX ) ;
2020-04-15 18:09:05 -07:00
# endif /* EFI_TOOTH_LOGGER */
2020-04-15 16:10:54 -07:00
2021-04-25 06:18:35 -07:00
addEngineSnifferEvent ( vvtName , PROTOCOL_ES_DOWN ) ;
addEngineSnifferEvent ( vvtName , PROTOCOL_ES_UP ) ;
2020-04-15 16:10:54 -07:00
}
}
2017-08-11 11:02:15 -07:00
floatus_t oneDegreeUs = engine - > rpmCalculator . oneDegreeUs ;
if ( cisnan ( oneDegreeUs ) ) {
2020-04-26 17:50:49 -07:00
// todo: this code branch is slowing NB2 cranking since we require RPM sync for VVT sync!
// todo: smarter code
//
2017-08-11 11:02:15 -07:00
// we are here if we are getting VVT position signals while engine is not running
// for example if crank position sensor is broken :)
return ;
}
2021-02-08 17:38:38 -08:00
ENGINE ( triggerCentral ) . vvtState [ bankIndex ] [ camIndex ] . decodeTriggerEvent (
2021-02-08 18:28:57 -08:00
ENGINE ( triggerCentral ) . vvtShape [ camIndex ] ,
2020-08-26 21:06:10 -07:00
nullptr ,
nullptr ,
2021-02-08 19:21:02 -08:00
engine - > vvtTriggerConfiguration [ camIndex ] ,
2020-08-26 21:06:10 -07:00
front = = TV_RISE ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING , nowNt ) ;
2019-09-02 11:47:05 -07:00
tc - > vvtCamCounter + + ;
2016-08-20 19:02:12 -07:00
2021-03-07 12:32:41 -08:00
float offsetUs = tc - > virtualZeroTimer . getElapsedUs ( nowNt ) ;
angle_t currentPosition = offsetUs / oneDegreeUs ;
2020-05-10 08:54:21 -07:00
// convert engine cycle angle into trigger cycle angle
currentPosition - = tdcPosition ( ) ;
2020-08-23 08:49:46 -07:00
// https://github.com/rusefi/rusefi/issues/1713 currentPosition could be negative that's expected
2020-05-10 08:54:21 -07:00
2021-01-26 19:54:25 -08:00
# if EFI_UNIT_TEST
2021-02-08 17:38:38 -08:00
tc - > currentVVTEventPosition [ bankIndex ] [ camIndex ] = currentPosition ;
2021-01-26 19:54:25 -08:00
# endif // EFI_UNIT_TEST
2020-05-10 15:03:11 -07:00
if ( engineConfiguration - > debugMode = = DBG_VVT ) {
# if EFI_TUNER_STUDIO
tsOutputChannels . debugFloatField1 = currentPosition ;
# endif /* EFI_TUNER_STUDIO */
}
2020-05-10 08:54:21 -07:00
2021-02-08 18:50:31 -08:00
switch ( engineConfiguration - > vvtMode [ camIndex ] ) {
2020-05-10 15:03:11 -07:00
case VVT_2JZ :
2020-05-15 13:35:18 -07:00
// we do not know if we are in sync or out of sync, so we have to be looking for both possibilities
if ( ( currentPosition < engineConfiguration - > fsio_setting [ 14 ] | | currentPosition > engineConfiguration - > fsio_setting [ 15 ] ) & &
( currentPosition < engineConfiguration - > fsio_setting [ 14 ] + 360 | | currentPosition > engineConfiguration - > fsio_setting [ 15 ] + 360 ) ) {
2020-05-10 15:03:11 -07:00
// outside of the expected range
return ;
}
2020-05-10 15:10:50 -07:00
break ;
2021-02-08 15:20:53 -08:00
case VVT_MIATA_NB2 :
2020-08-26 22:01:03 -07:00
case VVT_BOSCH_QUICK_START :
2021-03-22 04:48:29 -07:00
case VVT_BARRA_3_PLUS_1 :
2020-05-10 08:54:04 -07:00
{
2021-02-08 17:38:38 -08:00
if ( engine - > triggerCentral . vvtState [ bankIndex ] [ camIndex ] . currentCycle . current_index ! = 0 ) {
2021-03-22 04:48:29 -07:00
// this is not sync tooth - exiting
2016-11-11 20:02:49 -08:00
return ;
}
2018-08-14 11:19:58 -07:00
if ( engineConfiguration - > debugMode = = DBG_VVT ) {
2019-04-12 19:07:03 -07:00
# if EFI_TUNER_STUDIO
2018-08-14 11:19:58 -07:00
tsOutputChannels . debugIntField1 + + ;
2018-11-16 04:40:06 -08:00
# endif /* EFI_TUNER_STUDIO */
2018-08-14 11:19:58 -07:00
}
2016-11-11 20:02:49 -08:00
}
2020-05-10 12:22:50 -07:00
default :
// else, do nothing
break ;
2020-05-10 08:54:04 -07:00
}
2016-11-11 20:02:49 -08:00
2021-02-08 17:38:38 -08:00
tc - > vvtSyncTimeNt [ bankIndex ] [ camIndex ] = nowNt ;
2016-11-11 20:02:49 -08:00
2020-05-15 18:33:25 -07:00
// we do NOT clamp VVT position into the [0, engineCycle) range - we expect vvtOffset to be configured so that
// it's not necessary
2021-02-08 17:38:38 -08:00
tc - > vvtPosition [ bankIndex ] [ camIndex ] = engineConfiguration - > vvtOffset - currentPosition ;
2021-04-08 11:39:26 -07:00
if ( tc - > vvtPosition [ bankIndex ] [ camIndex ] < - ENGINE ( engineCycle ) / 2 | | tc - > vvtPosition [ bankIndex ] [ camIndex ] > ENGINE ( engineCycle ) / 2 ) {
2020-05-15 18:33:25 -07:00
warning ( CUSTOM_ERR_VVT_OUT_OF_RANGE , " Please adjust vvtOffset since position %f " , tc - > vvtPosition ) ;
}
2016-08-23 20:03:01 -07:00
2021-02-08 18:50:31 -08:00
switch ( engineConfiguration - > vvtMode [ camIndex ] ) {
2020-05-09 21:42:33 -07:00
case VVT_FIRST_HALF :
{
2016-08-23 20:03:01 -07:00
bool isEven = tc - > triggerState . isEvenRevolution ( ) ;
if ( ! isEven ) {
/**
* we are here if we ' ve detected the cam sensor within the wrong crank phase
* let ' s increase the trigger event counter , that would adjust the state of
* virtual crank - based trigger
*/
2018-02-05 14:16:34 -08:00
tc - > triggerState . incrementTotalEventCounter ( ) ;
2016-09-17 16:02:34 -07:00
if ( engineConfiguration - > debugMode = = DBG_VVT ) {
2019-04-12 19:07:03 -07:00
# if EFI_TUNER_STUDIO
2016-08-23 20:03:01 -07:00
tsOutputChannels . debugIntField1 + + ;
2018-11-16 04:40:06 -08:00
# endif /* EFI_TUNER_STUDIO */
2016-08-23 20:03:01 -07:00
}
}
2020-05-09 21:42:33 -07:00
}
break ;
case VVT_SECOND_HALF :
{
2016-08-23 20:03:01 -07:00
bool isEven = tc - > triggerState . isEvenRevolution ( ) ;
if ( isEven ) {
// see above comment
2018-02-05 14:16:34 -08:00
tc - > triggerState . incrementTotalEventCounter ( ) ;
2016-09-17 16:02:34 -07:00
if ( engineConfiguration - > debugMode = = DBG_VVT ) {
2019-04-12 19:07:03 -07:00
# if EFI_TUNER_STUDIO
2016-08-23 20:03:01 -07:00
tsOutputChannels . debugIntField1 + + ;
2018-11-16 04:40:06 -08:00
# endif /* EFI_TUNER_STUDIO */
2016-08-23 20:03:01 -07:00
}
}
2020-05-09 21:42:33 -07:00
}
break ;
2021-02-08 15:20:53 -08:00
case VVT_MIATA_NB2 :
2016-11-14 20:01:47 -08:00
/**
* NB2 is a symmetrical crank , there are four phases total
*/
2020-04-05 08:43:45 -07:00
while ( tc - > triggerState . getTotalRevolutionCounter ( ) % 4 ! = miataNbIndex ) {
2018-02-05 14:16:34 -08:00
tc - > triggerState . incrementTotalEventCounter ( ) ;
2016-11-14 20:01:47 -08:00
}
2020-05-14 20:13:32 -07:00
break ;
default :
case VVT_INACTIVE :
// do nothing
break ;
2016-08-20 19:02:12 -07:00
}
}
2019-05-10 20:52:55 -07:00
int triggerReentraint = 0 ;
int maxTriggerReentraint = 0 ;
uint32_t triggerDuration ;
uint32_t triggerMaxDuration = 0 ;
2021-04-22 21:45:36 -07:00
/**
* this method is invoked only by real hardware call - backs
*/
2020-12-26 15:12:36 -08:00
2021-06-27 10:00:01 -07:00
void hwHandleShaftSignal ( trigger_event_e signal , efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX ) {
2020-12-20 08:17:38 -08:00
# if VR_HW_CHECK_MODE
// some boards do not have hardware VR input LEDs which makes such boards harder to validate
// from experience we know that assembly mistakes happen and quality control is required
extern ioportid_t criticalErrorLedPort ;
extern ioportmask_t criticalErrorLedPin ;
2021-04-22 18:23:20 -07:00
# if HW_CHECK_ALWAYS_STIMULATE
disableTriggerStimulator ( ) ;
# endif // HW_CHECK_ALWAYS_STIMULATE
2020-12-20 08:17:38 -08:00
for ( int i = 0 ; i < 100 ; i + + ) {
// turning pin ON and busy-waiting a bit
palWritePad ( criticalErrorLedPort , criticalErrorLedPin , 1 ) ;
}
palWritePad ( criticalErrorLedPort , criticalErrorLedPin , 0 ) ;
# endif // VR_HW_CHECK_MODE
2021-06-27 10:00:01 -07:00
handleShaftSignal2 ( signal , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
2021-04-22 21:45:36 -07:00
}
/**
* this method is invoked by both real hardware and self - stimulator
*/
2021-06-25 08:30:06 -07:00
void handleShaftSignal2 ( trigger_event_e signal , efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX ) {
2021-04-22 21:45:36 -07:00
ScopePerf perf ( PE : : HandleShaftSignal ) ;
// Don't accept trigger input in case of some problems
if ( ! engine - > limpManager . allowTriggerInput ( ) ) {
return ;
}
2019-07-07 12:22:46 -07:00
# if EFI_TOOTH_LOGGER
2019-07-06 17:48:58 -07:00
// Log to the Tunerstudio tooth logger
// We want to do this before anything else as we
2019-07-07 12:22:46 -07:00
// actually want to capture any noise/jitter that may be occurring
2020-04-17 09:14:45 -07:00
2020-10-03 21:15:40 -07:00
bool logLogicState = CONFIG ( displayLogicLevelsInEngineSniffer ) & & CONFIG ( useOnlyRisingEdgeForTrigger ) ;
2020-04-17 09:14:45 -07:00
if ( ! logLogicState ) {
// we log physical state even if displayLogicLevelsInEngineSniffer if both fronts are used by decoder
LogTriggerTooth ( signal , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
}
2019-07-07 12:22:46 -07:00
# endif /* EFI_TOOTH_LOGGER */
2019-07-06 17:48:58 -07:00
2018-04-25 23:11:51 -07:00
// for effective noise filtering, we need both signal edges,
// so we pass them to handleShaftSignal() and defer this test
2019-12-11 14:48:55 -08:00
if ( ! CONFIG ( useNoiselessTriggerDecoder ) ) {
2020-10-05 11:22:59 -07:00
if ( ! isUsefulSignal ( signal , ENGINE ( primaryTriggerConfiguration ) ) ) {
2020-07-30 16:24:55 -07:00
/**
* no need to process VR falls further
*/
2018-04-25 23:11:51 -07:00
return ;
}
2017-10-16 11:08:45 -07:00
}
2020-04-17 09:14:45 -07:00
2020-04-17 11:02:10 -07:00
# if EFI_TOOTH_LOGGER
2020-04-17 09:14:45 -07:00
if ( logLogicState ) {
LogTriggerTooth ( signal , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
if ( signal = = SHAFT_PRIMARY_RISING ) {
LogTriggerTooth ( SHAFT_PRIMARY_FALLING , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
} else {
LogTriggerTooth ( SHAFT_SECONDARY_FALLING , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
}
}
2020-04-17 11:02:10 -07:00
# endif /* EFI_TOOTH_LOGGER */
2020-04-17 09:14:45 -07:00
2019-05-07 16:32:08 -07:00
uint32_t triggerHandlerEntryTime = getTimeNowLowerNt ( ) ;
2015-07-10 06:01:56 -07:00
if ( triggerReentraint > maxTriggerReentraint )
maxTriggerReentraint = triggerReentraint ;
triggerReentraint + + ;
2020-03-22 16:06:29 -07:00
2020-10-03 22:04:15 -07:00
ENGINE ( triggerCentral ) . handleShaftSignal ( signal , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
2020-03-22 16:06:29 -07:00
2015-07-10 06:01:56 -07:00
triggerReentraint - - ;
2019-05-07 16:32:08 -07:00
triggerDuration = getTimeNowLowerNt ( ) - triggerHandlerEntryTime ;
2021-01-31 19:41:17 -08:00
triggerMaxDuration = maxI ( triggerMaxDuration , triggerDuration ) ;
2015-07-10 06:01:56 -07:00
}
void TriggerCentral : : resetCounters ( ) {
memset ( hwEventCounters , 0 , sizeof ( hwEventCounters ) ) ;
}
static char shaft_signal_msg_index [ 15 ] ;
2019-02-02 23:47:20 -08:00
static const bool isUpEvent [ 6 ] = { false , true , false , true , false , true } ;
2019-08-18 12:04:02 -07:00
static const char * eventId [ 6 ] = { PROTOCOL_CRANK1 , PROTOCOL_CRANK1 , PROTOCOL_CRANK2 , PROTOCOL_CRANK2 , PROTOCOL_CRANK3 , PROTOCOL_CRANK3 } ;
2015-07-10 06:01:56 -07:00
2020-11-23 17:10:17 -08:00
static void reportEventToWaveChart ( trigger_event_e ckpSignalType , int index DECLARE_ENGINE_PARAMETER_SUFFIX ) {
2017-05-25 20:23:22 -07:00
if ( ! ENGINE ( isEngineChartEnabled ) ) { // this is here just as a shortcut so that we avoid engine sniffer as soon as possible
return ; // engineSnifferRpmThreshold is accounted for inside ENGINE(isEngineChartEnabled)
}
2015-07-10 06:01:56 -07:00
itoa10 ( & shaft_signal_msg_index [ 2 ] , index ) ;
2016-01-11 14:01:33 -08:00
bool isUp = isUpEvent [ ( int ) ckpSignalType ] ;
2015-07-10 06:01:56 -07:00
shaft_signal_msg_index [ 0 ] = isUp ? ' u ' : ' d ' ;
2018-09-10 19:29:43 -07:00
addEngineSnifferEvent ( eventId [ ( int ) ckpSignalType ] , ( char * ) shaft_signal_msg_index ) ;
2016-02-27 20:03:34 -08:00
if ( engineConfiguration - > useOnlyRisingEdgeForTrigger ) {
2015-07-10 06:01:56 -07:00
// let's add the opposite event right away
shaft_signal_msg_index [ 0 ] = isUp ? ' d ' : ' u ' ;
2018-09-10 19:29:43 -07:00
addEngineSnifferEvent ( eventId [ ( int ) ckpSignalType ] , ( char * ) shaft_signal_msg_index ) ;
2015-07-10 06:01:56 -07:00
}
}
2018-04-25 23:11:51 -07:00
/**
* This is used to filter noise spikes ( interference ) in trigger signal . See
* The basic idea is to use not just edges , but the average amount of time the signal stays in ' 0 ' or ' 1 ' .
* So we update ' accumulated periods ' to track where the signal is .
* And then compare between the current period and previous , with some tolerance ( allowing for the wheel speed change ) .
* @ return true if the signal is passed through .
*/
2020-01-27 21:16:33 -08:00
bool TriggerNoiseFilter : : noiseFilter ( efitick_t nowNt ,
TriggerState * triggerState ,
trigger_event_e signal DECLARE_ENGINE_PARAMETER_SUFFIX ) {
2018-04-25 23:11:51 -07:00
// todo: find a better place for these defs
static const trigger_event_e opposite [ 6 ] = { SHAFT_PRIMARY_RISING , SHAFT_PRIMARY_FALLING , SHAFT_SECONDARY_RISING , SHAFT_SECONDARY_FALLING ,
SHAFT_3RD_RISING , SHAFT_3RD_FALLING } ;
static const trigger_wheel_e triggerIdx [ 6 ] = { T_PRIMARY , T_PRIMARY , T_SECONDARY , T_SECONDARY , T_CHANNEL_3 , T_CHANNEL_3 } ;
// we process all trigger channels independently
trigger_wheel_e ti = triggerIdx [ signal ] ;
// falling is opposite to rising, and vise versa
trigger_event_e os = opposite [ signal ] ;
// todo: currently only primary channel is filtered, because there are some weird trigger types on other channels
if ( ti ! = T_PRIMARY )
return true ;
// update period accumulator: for rising signal, we update '0' accumulator, and for falling - '1'
if ( lastSignalTimes [ signal ] ! = - 1 )
accumSignalPeriods [ signal ] + = nowNt - lastSignalTimes [ signal ] ;
// save current time for this trigger channel
lastSignalTimes [ signal ] = nowNt ;
// now we want to compare current accumulated period to the stored one
efitick_t currentPeriod = accumSignalPeriods [ signal ] ;
// the trick is to compare between different
efitick_t allowedPeriod = accumSignalPrevPeriods [ os ] ;
// but first check if we're expecting a gap
2020-01-27 21:16:33 -08:00
bool isGapExpected = TRIGGER_WAVEFORM ( isSynchronizationNeeded ) & & triggerState - > shaft_is_synchronized & &
2021-06-26 19:17:07 -07:00
( triggerState - > currentCycle . eventCount [ ti ] + 1 ) = = TRIGGER_WAVEFORM ( getExpectedEventCount ( ti ) ) ;
2018-04-25 23:11:51 -07:00
if ( isGapExpected ) {
// usually we need to extend the period for gaps, based on the trigger info
2019-12-07 22:09:39 -08:00
allowedPeriod * = TRIGGER_WAVEFORM ( syncRatioAvg ) ;
2018-04-25 23:11:51 -07:00
}
// also we need some margin for rapidly changing trigger-wheel speed,
// that's why we expect the period to be no less than 2/3 of the previous period (this is just an empirical 'magic' coef.)
efitick_t minAllowedPeriod = 2 * allowedPeriod / 3 ;
// but no longer than 5/4 of the previous 'normal' period
efitick_t maxAllowedPeriod = 5 * allowedPeriod / 4 ;
// above all, check if the signal comes not too early
if ( currentPeriod > = minAllowedPeriod ) {
// now we store this period as a reference for the next time,
// BUT we store only 'normal' periods, and ignore too long periods (i.e. gaps)
if ( ! isGapExpected & & ( maxAllowedPeriod = = 0 | | currentPeriod < = maxAllowedPeriod ) ) {
accumSignalPrevPeriods [ signal ] = currentPeriod ;
}
// reset accumulator
accumSignalPeriods [ signal ] = 0 ;
return true ;
}
// all premature or extra-long events are ignored - treated as interference
return false ;
}
2021-06-26 20:01:47 -07:00
/**
* todo : why is this method NOT reciprocal to getRpmMultiplier ? !
*/
2021-06-26 19:42:53 -07:00
int getCrankDivider ( operation_mode_e operationMode ) {
if ( operationMode = = FOUR_STROKE_CAM_SENSOR | | operationMode = = TWO_STROKE ) {
// That's easy - trigger cycle matches engine cycle
return 1 ;
} else {
return operationMode = = FOUR_STROKE_CRANK_SENSOR ? 2 : SYMMETRICAL_CRANK_SENSOR_DIVIDER ;
}
}
2020-07-30 16:24:55 -07:00
/**
* This method is NOT invoked for VR falls .
*/
2020-01-09 10:19:11 -08:00
void TriggerCentral : : handleShaftSignal ( trigger_event_e signal , efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX ) {
2017-03-01 19:37:10 -08:00
if ( triggerShape . shapeDefinitionError ) {
2017-02-23 17:24:06 -08:00
// trigger is broken, we cannot do anything here
2017-03-05 11:13:47 -08:00
warning ( CUSTOM_ERR_UNEXPECTED_SHAFT_EVENT , " Shaft event while trigger is mis-configured " ) ;
2019-08-07 17:13:30 -07:00
// magic value to indicate a problem
hwEventCounters [ 0 ] = 155 ;
2017-02-23 17:24:06 -08:00
return ;
}
2018-04-25 23:11:51 -07:00
// This code gathers some statistics on signals and compares accumulated periods to filter interference
2019-12-11 14:48:55 -08:00
if ( CONFIG ( useNoiselessTriggerDecoder ) ) {
2020-01-27 21:16:33 -08:00
if ( ! noiseFilter . noiseFilter ( timestamp , & triggerState , signal PASS_ENGINE_PARAMETER_SUFFIX ) ) {
2018-04-25 23:11:51 -07:00
return ;
}
2020-10-05 11:22:59 -07:00
if ( ! isUsefulSignal ( signal , ENGINE ( primaryTriggerConfiguration ) ) ) {
2018-04-25 23:11:51 -07:00
return ;
}
}
2021-03-15 07:23:19 -07:00
engine - > onTriggerSignalEvent ( ) ;
2015-07-10 06:01:56 -07:00
2020-12-03 08:13:45 -08:00
m_lastEventTimer . reset ( timestamp ) ;
2015-07-10 06:01:56 -07:00
int eventIndex = ( int ) signal ;
2020-01-27 21:16:33 -08:00
efiAssertVoid ( CUSTOM_TRIGGER_EVENT_TYPE , eventIndex > = 0 & & eventIndex < HW_EVENT_TYPES , " signal type " ) ;
2015-07-10 06:01:56 -07:00
hwEventCounters [ eventIndex ] + + ;
/**
* This invocation changes the state of triggerState
*/
2020-10-05 11:22:59 -07:00
triggerState . decodeTriggerEvent ( triggerShape ,
2020-08-23 22:21:42 -07:00
nullptr ,
engine ,
2020-10-05 11:22:59 -07:00
engine - > primaryTriggerConfiguration ,
2020-08-23 23:01:50 -07:00
signal , timestamp ) ;
2015-07-10 06:01:56 -07:00
/**
* If we only have a crank position sensor with four stroke , here we are extending crank revolutions with a 360 degree
* cycle into a four stroke , 720 degrees cycle .
*/
2019-08-07 21:32:31 -07:00
operation_mode_e operationMode = engine - > getOperationMode ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2021-06-26 19:42:53 -07:00
int crankDivider = getCrankDivider ( operationMode ) ;
int crankInternalIndex = triggerState . getTotalRevolutionCounter ( ) % crankDivider ;
int triggerIndexForListeners = triggerState . getCurrentIndex ( ) + ( crankInternalIndex * getTriggerSize ( ) ) ;
2016-08-22 20:04:55 -07:00
if ( triggerIndexForListeners = = 0 ) {
2021-03-07 12:32:41 -08:00
virtualZeroTimer . reset ( timestamp ) ;
2016-08-22 20:04:55 -07:00
}
2017-05-15 20:28:49 -07:00
reportEventToWaveChart ( signal , triggerIndexForListeners PASS_ENGINE_PARAMETER_SUFFIX ) ;
2015-07-10 06:01:56 -07:00
2015-07-15 17:01:33 -07:00
if ( ! triggerState . shaft_is_synchronized ) {
// we should not propagate event if we do not know where we are
return ;
}
2020-10-05 11:22:59 -07:00
if ( triggerState . isValidIndex ( ENGINE ( triggerCentral . triggerShape ) ) ) {
2019-10-13 13:14:08 -07:00
ScopePerf perf ( PE : : ShaftPositionListeners ) ;
2019-04-12 19:07:03 -07:00
# if TRIGGER_EXTREME_LOGGING
2021-04-21 09:53:13 -07:00
efiPrintf ( " trigger %d %d %d " , triggerIndexForListeners , getRevolutionCounter ( ) , ( int ) getTimeNowUs ( ) ) ;
2020-07-20 10:38:33 -07:00
# endif /* TRIGGER_EXTREME_LOGGING */
2016-10-31 17:02:09 -07:00
2020-10-03 22:43:02 -07:00
rpmShaftPositionCallback ( signal , triggerIndexForListeners , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
2020-10-03 23:09:12 -07:00
tdcMarkCallback ( triggerIndexForListeners , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
2020-10-03 22:43:02 -07:00
# if !EFI_UNIT_TEST
2020-10-17 05:00:11 -07:00
# if EFI_MAP_AVERAGING
2020-10-03 23:09:12 -07:00
mapAveragingTriggerCallback ( triggerIndexForListeners , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
2020-10-17 05:00:11 -07:00
# endif /* EFI_MAP_AVERAGING */
2020-10-03 22:43:02 -07:00
# endif /* EFI_UNIT_TEST */
2020-10-17 05:00:11 -07:00
# if EFI_LOGIC_ANALYZER
waTriggerEventListener ( signal , triggerIndexForListeners , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
# endif
2020-10-03 22:43:02 -07:00
2020-10-17 05:00:11 -07:00
mainTriggerCallback ( triggerIndexForListeners , timestamp PASS_ENGINE_PARAMETER_SUFFIX ) ;
2015-07-10 06:01:56 -07:00
}
}
2020-03-29 16:06:03 -07:00
EXTERN_ENGINE ;
2015-07-10 06:01:56 -07:00
static void triggerShapeInfo ( void ) {
2019-04-12 19:07:03 -07:00
# if EFI_PROD_CODE || EFI_SIMULATOR
2020-08-24 21:59:07 -07:00
TriggerWaveform * shape = & engine - > triggerCentral . triggerShape ;
TriggerFormDetails * triggerFormDetails = & engine - > triggerCentral . triggerFormDetails ;
2021-04-21 09:53:13 -07:00
efiPrintf ( " useRise=%s " , boolToString ( TRIGGER_WAVEFORM ( useRiseEdge ) ) ) ;
efiPrintf ( " gap from %.2f to %.2f " , TRIGGER_WAVEFORM ( syncronizationRatioFrom [ 0 ] ) , TRIGGER_WAVEFORM ( syncronizationRatioTo [ 0 ] ) ) ;
2015-07-10 06:01:56 -07:00
2020-08-24 21:59:07 -07:00
for ( size_t i = 0 ; i < shape - > getSize ( ) ; i + + ) {
2021-04-21 09:53:13 -07:00
efiPrintf ( " event %d %.2f " , i , triggerFormDetails - > eventAngles [ i ] ) ;
2015-07-10 06:01:56 -07:00
}
# endif
}
2019-04-12 19:07:03 -07:00
# if EFI_PROD_CODE
2015-07-10 06:01:56 -07:00
extern PwmConfig triggerSignal ;
# endif /* #if EFI_PROD_CODE */
2019-07-14 12:22:02 -07:00
# if HAL_USE_ICU == TRUE
2020-03-08 05:57:21 -07:00
extern int icuRisingCallbackCounter ;
extern int icuFallingCallbackCounter ;
2019-07-14 12:22:02 -07:00
# endif /* HAL_USE_ICU */
2015-07-10 06:01:56 -07:00
void triggerInfo ( void ) {
2019-04-12 19:07:03 -07:00
# if EFI_PROD_CODE || EFI_SIMULATOR
2015-07-10 06:01:56 -07:00
2019-12-07 22:09:39 -08:00
TriggerWaveform * ts = & engine - > triggerCentral . triggerShape ;
2015-07-10 06:01:56 -07:00
2019-08-06 20:56:35 -07:00
# if (HAL_TRIGGER_USE_PAL == TRUE) && (PAL_USE_CALLBACKS == TRUE)
2021-04-21 09:53:13 -07:00
efiPrintf ( " trigger PAL mode %d " , engine - > hwTriggerInputEnabled ) ;
2019-08-06 20:56:35 -07:00
# else
2019-07-14 12:22:02 -07:00
# if HAL_USE_ICU == TRUE
2021-04-21 09:53:13 -07:00
efiPrintf ( " trigger ICU hw: %d %d %d " , icuRisingCallbackCounter , icuFallingCallbackCounter , engine - > hwTriggerInputEnabled ) ;
2019-07-14 12:22:02 -07:00
# endif /* HAL_USE_ICU */
2019-08-06 19:17:18 -07:00
# endif /* HAL_TRIGGER_USE_PAL */
2021-04-21 09:53:13 -07:00
efiPrintf ( " Template %s (%d) trigger %s (%d) useRiseEdge=%s onlyFront=%s useOnlyFirstChannel=%s tdcOffset=%.2f " ,
2015-07-10 06:01:56 -07:00
getConfigurationName ( engineConfiguration - > engineType ) , engineConfiguration - > engineType ,
getTrigger_type_e ( engineConfiguration - > trigger . type ) , engineConfiguration - > trigger . type ,
2019-12-07 22:09:39 -08:00
boolToString ( TRIGGER_WAVEFORM ( useRiseEdge ) ) , boolToString ( engineConfiguration - > useOnlyRisingEdgeForTrigger ) ,
boolToString ( engineConfiguration - > trigger . useOnlyFirstChannel ) , TRIGGER_WAVEFORM ( tdcPosition ) ) ;
2015-07-10 06:01:56 -07:00
if ( engineConfiguration - > trigger . type = = TT_TOOTHED_WHEEL ) {
2021-04-21 09:53:13 -07:00
efiPrintf ( " total %d/skipped %d " , engineConfiguration - > trigger . customTotalToothCount ,
2015-07-10 06:01:56 -07:00
engineConfiguration - > trigger . customSkippedToothCount ) ;
}
2021-04-21 09:53:13 -07:00
efiPrintf ( " trigger#1 event counters up=%d/down=%d " , engine - > triggerCentral . getHwEventCounter ( 0 ) ,
2015-09-13 14:02:44 -07:00
engine - > triggerCentral . getHwEventCounter ( 1 ) ) ;
2015-07-10 06:01:56 -07:00
2017-03-01 19:18:25 -08:00
if ( ts - > needSecondTriggerInput ) {
2021-04-21 09:53:13 -07:00
efiPrintf ( " trigger#2 event counters up=%d/down=%d " , engine - > triggerCentral . getHwEventCounter ( 2 ) ,
2015-09-13 14:02:44 -07:00
engine - > triggerCentral . getHwEventCounter ( 3 ) ) ;
2015-07-10 06:01:56 -07:00
}
2021-06-26 19:17:07 -07:00
efiPrintf ( " expected cycle events %d/%d/%d " ,
TRIGGER_WAVEFORM ( getExpectedEventCount ( 0 ) ) ,
TRIGGER_WAVEFORM ( getExpectedEventCount ( 1 ) ) ,
TRIGGER_WAVEFORM ( getExpectedEventCount ( 2 ) ) ) ;
2015-07-10 06:01:56 -07:00
2021-04-21 09:53:13 -07:00
efiPrintf ( " trigger type=%d/need2ndChannel=%s " , engineConfiguration - > trigger . type ,
2019-12-07 22:09:39 -08:00
boolToString ( TRIGGER_WAVEFORM ( needSecondTriggerInput ) ) ) ;
2021-04-21 09:53:13 -07:00
efiPrintf ( " expected duty #0=%.2f/#1=%.2f " , TRIGGER_WAVEFORM ( expectedDutyCycle [ 0 ] ) , TRIGGER_WAVEFORM ( expectedDutyCycle [ 1 ] ) ) ;
2015-07-10 06:01:56 -07:00
2021-04-21 09:53:13 -07:00
efiPrintf ( " synchronizationNeeded=%s/isError=%s/total errors=%d ord_err=%d/total revolutions=%d/self=%s " ,
2015-07-10 06:01:56 -07:00
boolToString ( ts - > isSynchronizationNeeded ) ,
2015-09-13 14:02:44 -07:00
boolToString ( isTriggerDecoderError ( ) ) , engine - > triggerCentral . triggerState . totalTriggerErrorCounter ,
engine - > triggerCentral . triggerState . orderingErrorCounter , engine - > triggerCentral . triggerState . getTotalRevolutionCounter ( ) ,
2020-04-23 19:38:14 -07:00
boolToString ( engine - > directSelfStimulation ) ) ;
2015-07-10 06:01:56 -07:00
2019-12-07 22:09:39 -08:00
if ( TRIGGER_WAVEFORM ( isSynchronizationNeeded ) ) {
2021-04-21 09:53:13 -07:00
efiPrintf ( " gap from %.2f to %.2f " , TRIGGER_WAVEFORM ( syncronizationRatioFrom [ 0 ] ) , TRIGGER_WAVEFORM ( syncronizationRatioTo [ 0 ] ) ) ;
2015-07-10 06:01:56 -07:00
}
2017-05-19 18:52:10 -07:00
# endif /* EFI_PROD_CODE || EFI_SIMULATOR */
2015-07-10 06:01:56 -07:00
2019-04-12 19:07:03 -07:00
# if EFI_PROD_CODE
2019-05-10 18:56:33 -07:00
if ( HAVE_CAM_INPUT ( ) ) {
2021-04-21 09:53:13 -07:00
efiPrintf ( " VVT input: %s mode %s " , hwPortname ( engineConfiguration - > camInputs [ 0 ] ) ,
2021-02-08 18:50:31 -08:00
getVvt_mode_e ( engineConfiguration - > vvtMode [ 0 ] ) ) ;
2021-04-21 09:53:13 -07:00
efiPrintf ( " VVT event counters: %d/%d " , engine - > triggerCentral . vvtEventRiseCounter , engine - > triggerCentral . vvtEventFallCounter ) ;
2016-08-20 16:02:07 -07:00
}
2021-04-21 09:53:13 -07:00
efiPrintf ( " primary trigger input: %s " , hwPortname ( CONFIG ( triggerInputPins ) [ 0 ] ) ) ;
efiPrintf ( " primary trigger simulator: %s %s freq=%d " ,
2019-12-11 14:48:55 -08:00
hwPortname ( CONFIG ( triggerSimulatorPins ) [ 0 ] ) ,
getPin_output_mode_e ( CONFIG ( triggerSimulatorPinModes ) [ 0 ] ) ,
CONFIG ( triggerSimulatorFrequency ) ) ;
2015-07-10 06:01:56 -07:00
2017-03-01 19:18:25 -08:00
if ( ts - > needSecondTriggerInput ) {
2021-04-21 09:53:13 -07:00
efiPrintf ( " secondary trigger input: %s " , hwPortname ( CONFIG ( triggerInputPins ) [ 1 ] ) ) ;
2019-04-12 19:07:03 -07:00
# if EFI_EMULATE_POSITION_SENSORS
2021-04-21 09:53:13 -07:00
efiPrintf ( " secondary trigger simulator: %s %s phase=%d " ,
2019-12-11 14:48:55 -08:00
hwPortname ( CONFIG ( triggerSimulatorPins ) [ 1 ] ) ,
getPin_output_mode_e ( CONFIG ( triggerSimulatorPinModes ) [ 1 ] ) , triggerSignal . safe . phaseIndex ) ;
2015-07-10 06:01:56 -07:00
# endif /* EFI_EMULATE_POSITION_SENSORS */
}
2021-04-21 09:53:13 -07:00
// efiPrintf("3rd trigger simulator: %s %s", hwPortname(CONFIG(triggerSimulatorPins)[2]),
2019-12-11 14:48:55 -08:00
// getPin_output_mode_e(CONFIG(triggerSimulatorPinModes)[2]));
2015-07-10 06:01:56 -07:00
2021-04-21 09:53:13 -07:00
efiPrintf ( " trigger error extra LED: %s %s " , hwPortname ( CONFIG ( triggerErrorPin ) ) ,
2019-12-11 14:48:55 -08:00
getPin_output_mode_e ( CONFIG ( triggerErrorPinMode ) ) ) ;
2021-04-21 09:53:13 -07:00
efiPrintf ( " primary logic input: %s " , hwPortname ( CONFIG ( logicAnalyzerPins ) [ 0 ] ) ) ;
efiPrintf ( " secondary logic input: %s " , hwPortname ( CONFIG ( logicAnalyzerPins ) [ 1 ] ) ) ;
2015-07-10 06:01:56 -07:00
2021-04-21 09:53:13 -07:00
efiPrintf ( " totalTriggerHandlerMaxTime=%d " , triggerMaxDuration ) ;
2015-07-10 06:01:56 -07:00
# endif /* EFI_PROD_CODE */
}
static void resetRunningTriggerCounters ( ) {
2019-04-12 19:07:03 -07:00
# if !EFI_UNIT_TEST
2015-09-13 14:02:44 -07:00
engine - > triggerCentral . resetCounters ( ) ;
2015-07-10 06:01:56 -07:00
triggerInfo ( ) ;
# endif
}
2019-10-21 20:47:40 -07:00
void onConfigurationChangeTriggerCallback ( DECLARE_ENGINE_PARAMETER_SIGNATURE ) {
2019-07-12 18:13:24 -07:00
bool changed = false ;
2021-06-25 16:38:42 -07:00
for ( size_t i = 0 ; i < efi : : size ( CONFIG ( camInputs ) ) ; i + + ) {
2019-10-21 20:47:40 -07:00
changed | = isConfigurationChanged ( camInputs [ i ] ) ;
2019-07-12 18:13:24 -07:00
}
2021-06-25 16:38:42 -07:00
for ( size_t i = 0 ; i < efi : : size ( CONFIG ( triggerGapOverride ) ) ; i + + ) {
2021-05-23 17:52:18 -07:00
changed | = isConfigurationChanged ( triggerGapOverride [ i ] ) ;
}
2021-06-25 16:38:42 -07:00
for ( size_t i = 0 ; i < efi : : size ( CONFIG ( triggerInputPins ) ) ; i + + ) {
changed | = isConfigurationChanged ( triggerInputPins [ i ] ) ;
}
for ( size_t i = 0 ; i < efi : : size ( CONFIG ( vvtMode ) ) ; i + + ) {
changed | = isConfigurationChanged ( vvtMode [ i ] ) ;
}
changed | = isConfigurationChanged ( trigger . type ) ;
changed | = isConfigurationChanged ( ambiguousOperationMode ) ;
changed | = isConfigurationChanged ( useOnlyRisingEdgeForTrigger ) ;
changed | = isConfigurationChanged ( globalTriggerAngleOffset ) ;
changed | = isConfigurationChanged ( trigger . customTotalToothCount ) ;
changed | = isConfigurationChanged ( trigger . customSkippedToothCount ) ;
changed | = isConfigurationChanged ( vvtCamSensorUseRise ) ;
changed | = isConfigurationChanged ( overrideTriggerGaps ) ;
changed | = isConfigurationChanged ( vvtOffset ) ;
2018-02-03 10:08:11 -08:00
if ( changed ) {
2018-02-03 17:43:31 -08:00
assertEngineReference ( ) ;
2019-04-12 19:07:03 -07:00
# if EFI_ENGINE_CONTROL
2021-04-21 11:28:48 -07:00
ENGINE ( initializeTriggerWaveform ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) ;
2020-01-27 21:16:33 -08:00
engine - > triggerCentral . noiseFilter . resetAccumSignalData ( ) ;
2018-02-03 17:43:31 -08:00
# endif
2018-02-03 10:08:11 -08:00
}
2018-03-04 17:43:38 -08:00
# if EFI_DEFAILED_LOGGING
2021-04-21 09:53:13 -07:00
efiPrintf ( " isTriggerConfigChanged=%d " , engine - > isTriggerConfigChanged ) ;
2018-03-04 17:43:38 -08:00
# endif /* EFI_DEFAILED_LOGGING */
2018-02-04 09:46:57 -08:00
// we do not want to miss two updates in a row
2019-02-02 23:33:33 -08:00
engine - > isTriggerConfigChanged = engine - > isTriggerConfigChanged | | changed ;
2017-06-26 11:31:10 -07:00
}
2017-07-05 19:22:24 -07:00
/**
* @ returns true if configuration just changed , and if that change has affected trigger
*/
2019-01-09 18:08:04 -08:00
bool checkIfTriggerConfigChanged ( DECLARE_ENGINE_PARAMETER_SIGNATURE ) {
2019-04-15 18:02:42 -07:00
bool result = engine - > triggerVersion . isOld ( engine - > getGlobalConfigurationVersion ( ) ) & & engine - > isTriggerConfigChanged ;
2019-02-02 23:33:33 -08:00
engine - > isTriggerConfigChanged = false ; // whoever has called the method is supposed to react to changes
2018-02-04 09:46:57 -08:00
return result ;
2017-06-26 11:31:10 -07:00
}
2019-05-10 18:29:17 -07:00
bool isTriggerConfigChanged ( DECLARE_ENGINE_PARAMETER_SIGNATURE ) {
2019-02-02 23:33:33 -08:00
return engine - > isTriggerConfigChanged ;
2018-03-10 17:58:51 -08:00
}
2021-04-21 11:28:48 -07:00
void initTriggerCentral ( ) {
2015-07-10 06:01:56 -07:00
strcpy ( ( char * ) shaft_signal_msg_index , " x_ " ) ;
2019-04-12 19:07:03 -07:00
# if EFI_ENGINE_SNIFFER
2015-07-10 06:01:56 -07:00
initWaveChart ( & waveChart ) ;
2015-07-15 18:01:45 -07:00
# endif /* EFI_ENGINE_SNIFFER */
2015-07-10 06:01:56 -07:00
2019-04-12 19:07:03 -07:00
# if EFI_PROD_CODE || EFI_SIMULATOR
2019-07-14 12:22:02 -07:00
addConsoleAction ( CMD_TRIGGERINFO , triggerInfo ) ;
2015-07-10 06:01:56 -07:00
addConsoleAction ( " trigger_shape_info " , triggerShapeInfo ) ;
addConsoleAction ( " reset_trigger " , resetRunningTriggerCounters ) ;
2020-08-23 23:01:50 -07:00
# endif // EFI_PROD_CODE || EFI_SIMULATOR
2015-07-10 06:01:56 -07:00
}
2020-08-23 23:01:50 -07:00
/**
* @ return TRUE is something is wrong with trigger decoding
*/
bool isTriggerDecoderError ( DECLARE_ENGINE_PARAMETER_SIGNATURE ) {
return engine - > triggerErrorDetection . sum ( 6 ) > 4 ;
}
# endif // EFI_SHAFT_POSITION_INPUT