rusefi-1/firmware/controllers/trigger/rpm_calculator.h

81 lines
1.7 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>
#define WC_DOWN "d"
#define WC_UP "u"
#define WC_CRANK1 "c1"
#define WC_CRANK2 "c2"
#define WC_CRANK3 "c3"
#define NOISY_RPM -1
#ifdef __cplusplus
#include "engine.h"
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);
uint32_t getRevolutionCounterSinceStart(void);
2014-08-29 07:52:33 -07:00
volatile int rpmValue;
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
};
#define getRpm() getRpmE(&engine)
/**
* @brief Current RPM
*/
int getRpmE(Engine *engine);
2014-10-16 01:02:58 -07:00
bool isCrankingE(Engine *engine);
2014-09-24 09:03:00 -07:00
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, RpmCalculator *rpmState);
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 */
/**
* @brief Initialize RPM calculator
*/
void initRpmCalculator(void);
bool isCranking(void);
uint64_t getLastRpmEventTime(void);
int getRevolutionCounter(void);
2014-11-06 17:04:40 -08:00
float getCrankshaftAngleNt(uint64_t timeNt);
2014-08-29 07:52:33 -07:00
bool isValidRpm(int rpm);
void addWaveChartEvent(const char *name, const char *msg, const char *msg2);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* RPM_REPORTER_H_ */