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

97 lines
2.0 KiB
C
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file rpm_calculator.h
* @brief Shaft position sensor(s) decoder header
*
* @date Jan 1, 2013
* @author Andrey Belomutskiy, (c) 2012-2014
*/
#ifndef RPM_REPORTER_H_
#define RPM_REPORTER_H_
#include <global.h>
2014-11-24 18:03:34 -08:00
#include "engine_configuration.h"
2014-08-29 07:52:33 -07:00
#define WC_DOWN "d"
#define WC_UP "u"
#define WC_CRANK1 "c1"
#define WC_CRANK2 "c2"
#define WC_CRANK3 "c3"
#define NOISY_RPM -1
2014-11-11 20:04:51 -08:00
#define UNREALISTIC_RPM 30000
2014-08-29 07:52:33 -07:00
#ifdef __cplusplus
2014-11-11 13:05:09 -08:00
class Engine;
2014-08-29 07:52:33 -07:00
class RpmCalculator {
public:
2014-10-17 12:02:59 -07:00
#if !EFI_PROD_CODE
int mockRpm;
#endif
2014-08-29 07:52:33 -07:00
RpmCalculator();
2014-11-03 10:03:03 -08:00
bool isRunning(void);
2014-08-29 07:52:33 -07:00
int rpm(void);
2014-11-03 10:03:03 -08:00
void onNewEngineCycle();
uint32_t getRevolutionCounter(void);
2014-11-11 11:06:07 -08:00
void setRpmValue(int value);
2014-11-03 10:03:03 -08:00
uint32_t getRevolutionCounterSinceStart(void);
2014-08-29 07:52:33 -07:00
volatile int rpmValue;
2014-11-11 11:06:07 -08:00
/**
* This is a performance optimization: let's pre-calulate this each time RPM changes
*/
2014-11-11 13:05:09 -08:00
volatile float oneDegreeUs;
2014-11-06 17:04:40 -08:00
volatile uint64_t lastRpmEventTimeNt;
2014-11-03 10:03:03 -08:00
private:
2014-08-29 07:52:33 -07:00
/**
* This counter is incremented with each revolution of one of the shafts. Could be
* crankshaft could be camshaft.
*/
2014-11-03 10:03:03 -08:00
volatile uint32_t revolutionCounterSinceBoot;
/**
* Same as the above, but since the engine started spinning
*/
volatile uint32_t revolutionCounterSinceStart;
2014-08-29 07:52:33 -07:00
};
2014-11-07 19:04:45 -08:00
#define getRpm() getRpmE(engine)
2014-08-29 07:52:33 -07:00
/**
* @brief Current RPM
*/
2014-11-24 07:03:19 -08:00
#define getRpmE(engine) (engine)->rpmCalculator.rpm()
2014-10-16 01:02:58 -07:00
bool isCrankingE(Engine *engine);
2014-11-24 18:03:34 -08:00
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S);
2014-11-08 09:03:07 -08:00
/**
* @brief Initialize RPM calculator
*/
void initRpmCalculator(Engine *engine);
2014-11-11 13:05:09 -08:00
float getCrankshaftAngleNt(Engine *engine, uint64_t timeNt);
2014-08-29 07:52:33 -07:00
#endif
#ifdef __cplusplus
2014-10-17 12:02:59 -07:00
extern "C" {
2014-08-29 07:52:33 -07:00
#endif /* __cplusplus */
bool isCranking(void);
int getRevolutionCounter(void);
2014-11-11 20:04:51 -08:00
#define isValidRpm(rpm) ((rpm) > 0 && (rpm) < UNREALISTIC_RPM)
2014-11-23 19:03:07 -08:00
#if EFI_WAVE_CHART
#define addWaveChartEvent(name, msg) waveChart.addWaveChartEvent3((name), (msg))
#else
#define addWaveChartEvent(n, msg) {}
#endif /* EFI_WAVE_CHART */
2014-08-29 07:52:33 -07:00
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* RPM_REPORTER_H_ */