auto-sync
This commit is contained in:
parent
9d856fd770
commit
1bd2cd8867
|
@ -39,6 +39,9 @@ extern "C"
|
||||||
*
|
*
|
||||||
* By using 64 bit, we can achieve a very precise timestamp which does not overflow.
|
* By using 64 bit, we can achieve a very precise timestamp which does not overflow.
|
||||||
* The primary implementation counts the number of CPU cycles from MCU reset.
|
* The primary implementation counts the number of CPU cycles from MCU reset.
|
||||||
|
*
|
||||||
|
* WARNING: you should use getTimeNowNt where possible for performance reasons.
|
||||||
|
* The heaviest part is '__aeabi_ildivmod' - non-native 64 bit division
|
||||||
*/
|
*/
|
||||||
uint64_t getTimeNowUs(void);
|
uint64_t getTimeNowUs(void);
|
||||||
|
|
||||||
|
|
|
@ -225,6 +225,7 @@ void showMainHistogram(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: eliminate this 'extern'
|
||||||
extern Engine engine;
|
extern Engine engine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -102,17 +102,17 @@ bool isCranking(void) {
|
||||||
* This callback is invoked on interrupt thread.
|
* This callback is invoked on interrupt thread.
|
||||||
*/
|
*/
|
||||||
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, RpmCalculator *rpmState) {
|
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, RpmCalculator *rpmState) {
|
||||||
|
uint64_t nowUs = getTimeNowUs();
|
||||||
|
|
||||||
if (index != 0) {
|
if (index != 0) {
|
||||||
#if EFI_ANALOG_CHART || defined(__DOXYGEN__)
|
#if EFI_ANALOG_CHART || defined(__DOXYGEN__)
|
||||||
if (engineConfiguration->analogChartMode == AC_TRIGGER)
|
if (engineConfiguration->analogChartMode == AC_TRIGGER)
|
||||||
acAddData(getCrankshaftAngle(getTimeNowUs()), 1000 * ckpSignalType + index);
|
acAddData(getCrankshaftAngle(nowUs), 1000 * ckpSignalType + index);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rpmState->revolutionCounter++;
|
rpmState->revolutionCounter++;
|
||||||
|
|
||||||
uint64_t nowUs = getTimeNowUs();
|
|
||||||
|
|
||||||
bool hadRpmRecently = rpmState->isRunning();
|
bool hadRpmRecently = rpmState->isRunning();
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#define GPTDEVICE GPTD5
|
#define GPTDEVICE GPTD5
|
||||||
|
|
||||||
static volatile uint64_t lastSetTimerTime;
|
static volatile uint64_t lastSetTimerTimeNt;
|
||||||
static int lastSetTimerValue;
|
static int lastSetTimerValue;
|
||||||
static volatile bool isTimerPending = FALSE;
|
static volatile bool isTimerPending = FALSE;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ void setHardwareUsTimer(int32_t timeUs) {
|
||||||
gptStopTimerI(&GPTDEVICE);
|
gptStopTimerI(&GPTDEVICE);
|
||||||
gptStartOneShotI(&GPTDEVICE, timeUs);
|
gptStartOneShotI(&GPTDEVICE, timeUs);
|
||||||
|
|
||||||
lastSetTimerTime = getTimeNowUs();
|
lastSetTimerTimeNt = getTimeNowNt();
|
||||||
lastSetTimerValue = timeUs;
|
lastSetTimerValue = timeUs;
|
||||||
isTimerPending = TRUE;
|
isTimerPending = TRUE;
|
||||||
timerRestartCounter++;
|
timerRestartCounter++;
|
||||||
|
@ -85,7 +85,7 @@ static msg_t mwThread(int param) {
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
chThdSleepMilliseconds(1000); // once a second is enough
|
chThdSleepMilliseconds(1000); // once a second is enough
|
||||||
|
|
||||||
if (getTimeNowUs() >= lastSetTimerTime + 2 * US_PER_SECOND) {
|
if (getTimeNowNt() >= lastSetTimerTimeNt + 2 * CORE_CLOCK) {
|
||||||
strcpy(buff, "no_event");
|
strcpy(buff, "no_event");
|
||||||
itoa10(&buff[8], lastSetTimerValue);
|
itoa10(&buff[8], lastSetTimerValue);
|
||||||
firmwareError(buff);
|
firmwareError(buff);
|
||||||
|
@ -94,7 +94,7 @@ static msg_t mwThread(int param) {
|
||||||
|
|
||||||
msg = isTimerPending ? "No_cb too long" : "Timer not awhile";
|
msg = isTimerPending ? "No_cb too long" : "Timer not awhile";
|
||||||
// 2 seconds of inactivity would not look right
|
// 2 seconds of inactivity would not look right
|
||||||
efiAssert(getTimeNowUs() < lastSetTimerTime + 2 * US_PER_SECOND, msg, -1);
|
efiAssert(getTimeNowNt() < lastSetTimerTimeNt + 2 * CORE_CLOCK, msg, -1);
|
||||||
}
|
}
|
||||||
#if defined __GNUC__
|
#if defined __GNUC__
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -111,7 +111,7 @@ void initMicrosecondTimer(void) {
|
||||||
|
|
||||||
gptStart(&GPTDEVICE, &gpt5cfg);
|
gptStart(&GPTDEVICE, &gpt5cfg);
|
||||||
|
|
||||||
lastSetTimerTime = getTimeNowUs();
|
lastSetTimerTimeNt = getTimeNowNt();
|
||||||
#if EFI_EMULATE_POSITION_SENSORS
|
#if EFI_EMULATE_POSITION_SENSORS
|
||||||
chThdCreateStatic(mwThreadStack, sizeof(mwThreadStack), NORMALPRIO, (tfunc_t) mwThread, NULL);
|
chThdCreateStatic(mwThreadStack, sizeof(mwThreadStack), NORMALPRIO, (tfunc_t) mwThread, NULL);
|
||||||
#endif /* EFI_ENGINE_EMULATOR */
|
#endif /* EFI_ENGINE_EMULATOR */
|
||||||
|
|
|
@ -339,11 +339,16 @@ void testGY6_139QMB(void) {
|
||||||
|
|
||||||
extern EventQueue schedulingQueue;
|
extern EventQueue schedulingQueue;
|
||||||
|
|
||||||
|
// this is a very dirty and sad hack. todo: eliminate
|
||||||
|
extern Engine engine;
|
||||||
|
|
||||||
static void testRpmCalculator(void) {
|
static void testRpmCalculator(void) {
|
||||||
printf("*************************************************** testRpmCalculator\r\n");
|
printf("*************************************************** testRpmCalculator\r\n");
|
||||||
|
|
||||||
EngineTestHelper eth(FORD_INLINE_6_1995);
|
EngineTestHelper eth(FORD_INLINE_6_1995);
|
||||||
|
|
||||||
|
efiAssertVoid(eth.engine.engineConfiguration!=NULL, "null config in engine");
|
||||||
|
|
||||||
initThermistors(ð.engine);
|
initThermistors(ð.engine);
|
||||||
|
|
||||||
engine_configuration_s *ec = ð.persistentConfig.engineConfiguration;
|
engine_configuration_s *ec = ð.persistentConfig.engineConfiguration;
|
||||||
|
@ -354,6 +359,9 @@ static void testRpmCalculator(void) {
|
||||||
ec->globalFuelCorrection = 3;
|
ec->globalFuelCorrection = 3;
|
||||||
eth.initTriggerShapeAndRpmCalculator();
|
eth.initTriggerShapeAndRpmCalculator();
|
||||||
|
|
||||||
|
// this is a very dirty and sad hack. todo: eliminate
|
||||||
|
engine.engineConfiguration = eth.engine.engineConfiguration;
|
||||||
|
|
||||||
configuration_s configuration = { ec, ec2 };
|
configuration_s configuration = { ec, ec2 };
|
||||||
timeNow = 0;
|
timeNow = 0;
|
||||||
assertEquals(0, eth.rpmState.rpm());
|
assertEquals(0, eth.rpmState.rpm());
|
||||||
|
|
Loading…
Reference in New Issue