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

99 lines
2.7 KiB
C
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file trigger_decoder.h
*
* @date Dec 24, 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_DECODER_H_
#define TRIGGER_DECODER_H_
#include "trigger_structure.h"
#include "engine_configuration.h"
class TriggerState;
typedef void (*TriggerStateCallback)(TriggerState *);
class TriggerState {
public:
TriggerState();
int getCurrentIndex();
int getTotalRevolutionCounter();
uint64_t getTotalEventCounter();
uint64_t getStartOfRevolutionIndex();
2014-11-26 13:03:29 -08:00
void decodeTriggerEvent(trigger_event_e const signal, uint64_t nowUs DECLARE_ENGINE_PARAMETER_S);
2014-08-29 07:52:33 -07:00
float getTriggerDutyCycle(int index);
TriggerStateCallback cycleCallback;
/**
* TRUE if we know where we are
*/
bool shaft_is_synchronized;
2014-11-26 14:03:18 -08:00
uint32_t toothed_previous_duration;
2014-11-15 06:03:49 -08:00
/**
* this could be a local variable, but it's better for debugging to have it as a field
*/
2014-11-26 14:03:18 -08:00
uint32_t currentDuration;
2014-08-29 07:52:33 -07:00
uint64_t toothed_previous_time;
/**
* Here we accumulate the amount of time this signal was ON within current trigger cycle
*/
2014-11-14 14:03:57 -08:00
int totalTimeNt[PWM_PHASE_MAX_WAVE_PER_PWM];
2014-08-29 07:52:33 -07:00
/**
* Total time result for previous trigger cycle
*/
2014-09-24 11:04:07 -07:00
uint32_t prevTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM];
2014-08-29 07:52:33 -07:00
int expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM];
2014-11-13 13:03:09 -08:00
uint32_t totalTriggerErrorCounter;
2014-11-15 11:03:19 -08:00
uint32_t orderingErrorCounter;
2014-08-29 07:52:33 -07:00
/**
* index within trigger revolution, from 0 to trigger event count
*/
2014-09-24 11:04:07 -07:00
uint32_t current_index;
2015-01-17 21:04:10 -08:00
uint32_t runningRevolutionCounter;
2014-11-26 13:03:29 -08:00
private:
void clear();
2014-08-29 07:52:33 -07:00
/**
* Number of actual events within current trigger cycle
2015-01-13 05:04:00 -08:00
* see TriggerShape
2014-08-29 07:52:33 -07:00
*/
2014-09-24 11:04:07 -07:00
uint32_t eventCount[PWM_PHASE_MAX_WAVE_PER_PWM];
2014-11-15 11:03:19 -08:00
trigger_event_e curSignal;
trigger_event_e prevSignal;
uint32_t eventCountExt[2 * PWM_PHASE_MAX_WAVE_PER_PWM];
2014-11-14 14:03:57 -08:00
uint64_t timeOfPreviousEventNt[PWM_PHASE_MAX_WAVE_PER_PWM];
2014-08-29 07:52:33 -07:00
uint64_t totalEventCountBase;
2014-09-24 11:04:07 -07:00
uint32_t totalRevolutionCounter;
2014-08-29 07:52:33 -07:00
bool isFirstEvent;
uint64_t prevCycleDuration;
2014-11-14 14:03:57 -08:00
uint64_t startOfCycleNt;
2014-08-29 07:52:33 -07:00
};
class TriggerStimulatorHelper {
public:
TriggerStimulatorHelper();
2015-01-13 05:04:00 -08:00
void nextStep(TriggerState *state, TriggerShape * shape, int i, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S);
2014-08-29 07:52:33 -07:00
private:
bool primaryWheelState;
bool secondaryWheelState;
bool thirdWheelState;
};
2015-01-13 05:04:00 -08:00
void initializeSkippedToothTriggerShapeExt(TriggerShape *s, int totalTeethCount, int skippedCount, operation_mode_e operationMode);
uint32_t findTriggerZeroEventIndex(TriggerShape * shape, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S);
2014-11-24 12:06:11 -08:00
class Engine;
2014-11-24 13:03:32 -08:00
void initializeTriggerShape(Logging *logger, engine_configuration_s const *engineConfiguration, Engine *engine);
2014-08-29 07:52:33 -07:00
void initTriggerDecoder(void);
2015-01-14 18:03:44 -08:00
void initTriggerDecoderLogger(Logging *sharedLogger);
2014-08-29 07:52:33 -07:00
2014-11-14 08:03:49 -08:00
bool_t isTriggerDecoderError(void);
2014-08-29 07:52:33 -07:00
#endif /* TRIGGER_DECODER_H_ */