fome-fw/firmware/controllers/trigger/trigger_structure.h

147 lines
3.7 KiB
C
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file trigger_structure.h
*
* @date Dec 22, 2013
2015-01-12 15:04:10 -08:00
* @author Andrey Belomutskiy, (c) 2012-2015
2014-08-29 07:52:33 -07:00
*/
#ifndef TRIGGER_STRUCTURE_H_
#define TRIGGER_STRUCTURE_H_
2014-10-29 13:04:17 -07:00
#include "global.h"
2014-08-29 07:52:33 -07:00
#include "rusefi_enums.h"
#include "EfiWave.h"
#include "engine_configuration.h"
2015-01-13 05:04:00 -08:00
class TriggerShape;
2014-08-29 07:52:33 -07:00
#define TRIGGER_CHANNEL_COUNT 3
class trigger_shape_helper {
2015-01-20 20:07:37 -08:00
pin_state_t pinStates[TRIGGER_CHANNEL_COUNT][PWM_PHASE_MAX_COUNT];
2014-08-29 07:52:33 -07:00
public:
trigger_shape_helper();
single_wave_s waves[TRIGGER_CHANNEL_COUNT];
};
2014-11-12 14:03:12 -08:00
class Engine;
2015-01-13 05:04:00 -08:00
class TriggerShape {
2014-08-29 07:52:33 -07:00
public:
2015-01-13 05:04:00 -08:00
TriggerShape();
2014-11-25 13:03:16 -08:00
bool_t isSynchronizationNeeded;
2015-02-02 21:04:02 -08:00
bool_t needSecondTriggerInput;
2014-08-29 07:52:33 -07:00
int totalToothCount;
int skippedToothCount;
float dutyCycle[PWM_PHASE_MAX_WAVE_PER_PWM];
2015-01-13 18:06:35 -08:00
/**
* this cache allows us to find a close-enough (with one degree precision) trigger wheel index by
* given angle with fast constant speed
*/
int triggerIndexByAngle[720];
2014-08-29 07:52:33 -07:00
float syncRatioFrom;
float syncRatioTo;
2015-02-02 08:10:08 -08:00
/**
* that's the angle distance from trigger event #0 and actual engine TDC
2015-02-04 14:04:24 -08:00
* see also globalTriggerAngleOffset
2015-02-02 08:10:08 -08:00
*/
2015-02-12 09:09:11 -08:00
angle_t tdcPosition;
2015-02-02 08:10:08 -08:00
2014-10-29 14:03:10 -07:00
/**
* Should we use falls or rises for gap ratio detection?
*/
2014-10-29 13:04:17 -07:00
bool_t useRiseEdge;
2014-10-29 14:03:10 -07:00
/**
* Should we measure gaps with events of both kinds?
*/
bool_t gapBothDirections;
2014-08-29 07:52:33 -07:00
/**
* This is used for signal validation
*/
2014-09-24 12:03:03 -07:00
uint32_t expectedEventCount[PWM_PHASE_MAX_WAVE_PER_PWM];
2014-08-29 07:52:33 -07:00
multi_wave_s wave;
// todo: add a runtime validation which would verify that this field was set properly
// tood: maybe even automate this flag calculation?
int initialState[PWM_PHASE_MAX_WAVE_PER_PWM];
/**
* These angles are in event coordinates - with synchronization point located at angle zero.
* These values are pre-calculated for performance reasons.
*/
float eventAngles[PWM_PHASE_MAX_COUNT];
2014-11-03 12:06:53 -08:00
bool_t invertOnAdd;
2014-11-25 08:04:15 -08:00
/**
* Total count of shaft events per CAM or CRANK shaft revolution.
* TODO this should be migrated to CRANKshaft revolution, this would go together
* TODO with eliminating RPM_MULT magic constant
*/
2014-08-29 07:52:33 -07:00
int size;
2015-02-16 17:09:39 -08:00
void addEvent(float angle, trigger_wheel_e const waveIndex, trigger_value_e const state);
// todo: these two methods here, something could be improved
void clear();
void reset(operation_mode_e operationMode, bool needSecondTriggerInput);
void setTriggerSynchronizationGap2(float syncRatioFrom, float syncRatioTo);
void setTriggerSynchronizationGap(float synchRatio);
/**
* this one is per CRANKshaft revolution
*/
uint32_t getLength() const;
int getSize() const;
int getTriggerShapeSynchPointIndex();
2015-02-27 16:09:09 -08:00
void calculateTriggerSynchPoint(DECLARE_ENGINE_PARAMETER_F);
2015-02-16 17:09:39 -08:00
void setTriggerShapeSynchPointIndex(engine_configuration_s *engineConfiguration, int triggerShapeSynchPointIndex, Engine *engine);
2014-11-26 12:04:04 -08:00
private:
trigger_shape_helper h;
2014-08-29 07:52:33 -07:00
/**
2015-01-13 05:04:00 -08:00
* index of synchronization event within TriggerShape
2014-08-29 07:52:33 -07:00
* See findTriggerZeroEventIndex()
*/
int triggerShapeSynchPointIndex;
/**
* Values are in the 0..1 range
*/
float switchTimesBuffer[PWM_PHASE_MAX_COUNT];
/**
* These angles are in trigger DESCRIPTION coordinates - i.e. the way you add events while declaring trigger shape
*/
float getSwitchAngle(int index) const;
float previousAngle;
/**
* this is part of performance optimization
*/
operation_mode_e operationMode;
/**
* This private method should only be used to prepare the array of pre-calculated values
* See eventAngles array
*/
float getAngle(int phaseIndex) const;
int getCycleDuration() const;
};
2015-01-13 05:04:00 -08:00
void setTriggerSynchronizationGap(TriggerShape *s, float synchGap);
void setTriggerSynchronizationGap2(TriggerShape *s, float syncGapFrom, float syncRatioTo);
void setToothedWheelConfiguration(TriggerShape *s, int total, int skipped, engine_configuration_s const *engineConfiguration);
2014-08-29 07:52:33 -07:00
#endif /* TRIGGER_STRUCTURE_H_ */