use NT_PER_SECOND instead of convert from microseconds (#1107)
* add NT_PER_SECOND * missed a few * inject tooth logger timestamp * inject
This commit is contained in:
parent
09dc2f2390
commit
ba0c48e0ac
|
@ -33,7 +33,7 @@ void SetNextEntry(uint16_t entry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogTriggerTooth(trigger_event_e tooth) {
|
void LogTriggerTooth(trigger_event_e tooth, efitick_t timestamp) {
|
||||||
// bail if we aren't enabled
|
// bail if we aren't enabled
|
||||||
if (!ToothLoggerEnabled) {
|
if (!ToothLoggerEnabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -46,7 +46,7 @@ void LogTriggerTooth(trigger_event_e tooth) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t nowUs = NT2US(getTimeNowNt());
|
uint32_t nowUs = NT2US(timestamp);
|
||||||
// 10us per LSB - this gives plenty of accuracy, yet fits 655.35 ms in to a uint16
|
// 10us per LSB - this gives plenty of accuracy, yet fits 655.35 ms in to a uint16
|
||||||
uint16_t delta = static_cast<uint16_t>((nowUs - lastEdgeTimestamp) / 10);
|
uint16_t delta = static_cast<uint16_t>((nowUs - lastEdgeTimestamp) / 10);
|
||||||
lastEdgeTimestamp = nowUs;
|
lastEdgeTimestamp = nowUs;
|
||||||
|
@ -59,7 +59,7 @@ void EnableToothLogger() {
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
||||||
// Reset the last edge to now - this prevents the first edge logged from being bogus
|
// Reset the last edge to now - this prevents the first edge logged from being bogus
|
||||||
lastEdgeTimestamp = NT2US(getTimeNowNt());
|
lastEdgeTimestamp = getTimeNowUs();
|
||||||
|
|
||||||
// Reset write index
|
// Reset write index
|
||||||
NextIdx = 0;
|
NextIdx = 0;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include "efitime.h"
|
||||||
#include "rusefi_enums.h"
|
#include "rusefi_enums.h"
|
||||||
|
|
||||||
// Enable the tooth logger - this clears the buffer starts logging
|
// Enable the tooth logger - this clears the buffer starts logging
|
||||||
|
@ -18,7 +19,7 @@ void EnableToothLogger();
|
||||||
void DisableToothLogger();
|
void DisableToothLogger();
|
||||||
|
|
||||||
// A new tooth has arrived! Log to the buffer if enabled.
|
// A new tooth has arrived! Log to the buffer if enabled.
|
||||||
void LogTriggerTooth(trigger_event_e tooth);
|
void LogTriggerTooth(trigger_event_e tooth, efitick_t timestamp);
|
||||||
|
|
||||||
struct ToothLoggerBuffer
|
struct ToothLoggerBuffer
|
||||||
{
|
{
|
||||||
|
|
|
@ -213,7 +213,7 @@ Engine::Engine(persistent_config_s *config) {
|
||||||
*/
|
*/
|
||||||
bool Engine::needToStopEngine(efitick_t nowNt) const {
|
bool Engine::needToStopEngine(efitick_t nowNt) const {
|
||||||
return stopEngineRequestTimeNt != 0 &&
|
return stopEngineRequestTimeNt != 0 &&
|
||||||
nowNt - stopEngineRequestTimeNt < 3 * US2NT(US_PER_SECOND_LL);
|
nowNt - stopEngineRequestTimeNt < 3 * NT_PER_SECOND;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Engine::getGlobalConfigurationVersion(void) const {
|
int Engine::getGlobalConfigurationVersion(void) const {
|
||||||
|
|
|
@ -88,14 +88,14 @@ void FuelConsumptionState::addData(float durationMs) {
|
||||||
|
|
||||||
void FuelConsumptionState::update(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
void FuelConsumptionState::update(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
efitick_t deltaNt = nowNt - accumulatedSecondPrevNt;
|
efitick_t deltaNt = nowNt - accumulatedSecondPrevNt;
|
||||||
if (deltaNt >= US2NT(US_PER_SECOND_LL)) {
|
if (deltaNt >= NT_PER_SECOND) {
|
||||||
perSecondConsumption = getFuelRate(perSecondAccumulator, deltaNt PASS_ENGINE_PARAMETER_SUFFIX);
|
perSecondConsumption = getFuelRate(perSecondAccumulator, deltaNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
perSecondAccumulator = 0;
|
perSecondAccumulator = 0;
|
||||||
accumulatedSecondPrevNt = nowNt;
|
accumulatedSecondPrevNt = nowNt;
|
||||||
}
|
}
|
||||||
|
|
||||||
deltaNt = nowNt - accumulatedMinutePrevNt;
|
deltaNt = nowNt - accumulatedMinutePrevNt;
|
||||||
if (deltaNt >= US2NT(US_PER_SECOND_LL * 60)) {
|
if (deltaNt >= NT_PER_SECOND * 60) {
|
||||||
perMinuteConsumption = getFuelRate(perMinuteAccumulator, deltaNt PASS_ENGINE_PARAMETER_SUFFIX);
|
perMinuteConsumption = getFuelRate(perMinuteAccumulator, deltaNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
perMinuteAccumulator = 0;
|
perMinuteAccumulator = 0;
|
||||||
accumulatedMinutePrevNt = nowNt;
|
accumulatedMinutePrevNt = nowNt;
|
||||||
|
|
|
@ -96,7 +96,7 @@ RpmCalculator::RpmCalculator() {
|
||||||
// which we cannot provide inside this parameter-less constructor. need a solution for this minor mess
|
// which we cannot provide inside this parameter-less constructor. need a solution for this minor mess
|
||||||
|
|
||||||
// we need this initial to have not_running at first invocation
|
// we need this initial to have not_running at first invocation
|
||||||
lastRpmEventTimeNt = (efitick_t) -10 * US2NT(US_PER_SECOND_LL);
|
lastRpmEventTimeNt = (efitick_t) -10 * NT_PER_SECOND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,11 +118,11 @@ bool RpmCalculator::checkIfSpinning(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUF
|
||||||
* note that the result of this subtraction could be negative, that would happen if
|
* note that the result of this subtraction could be negative, that would happen if
|
||||||
* we have a trigger event between the time we've invoked 'getTimeNow' and here
|
* we have a trigger event between the time we've invoked 'getTimeNow' and here
|
||||||
*/
|
*/
|
||||||
bool noRpmEventsForTooLong = nowNt - lastRpmEventTimeNt >= US2NT(NO_RPM_EVENTS_TIMEOUT_SECS * US_PER_SECOND_LL); // Anything below 60 rpm is not running
|
bool noRpmEventsForTooLong = nowNt - lastRpmEventTimeNt >= NT_PER_SECOND * NO_RPM_EVENTS_TIMEOUT_SECS; // Anything below 60 rpm is not running
|
||||||
/**
|
/**
|
||||||
* Also check if there were no trigger events
|
* Also check if there were no trigger events
|
||||||
*/
|
*/
|
||||||
bool noTriggerEventsForTooLong = nowNt - engine->triggerCentral.previousShaftEventTimeNt >= US2NT(US_PER_SECOND_LL);
|
bool noTriggerEventsForTooLong = nowNt - engine->triggerCentral.previousShaftEventTimeNt >= NT_PER_SECOND;
|
||||||
if (noRpmEventsForTooLong || noTriggerEventsForTooLong) {
|
if (noRpmEventsForTooLong || noTriggerEventsForTooLong) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
|
||||||
rpmState->setRpmValue(NOISY_RPM PASS_ENGINE_PARAMETER_SUFFIX);
|
rpmState->setRpmValue(NOISY_RPM PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
} else {
|
} else {
|
||||||
int mult = (int)getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) / 360;
|
int mult = (int)getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) / 360;
|
||||||
float rpm = 60.0 * US2NT(US_PER_SECOND_LL) * mult / diffNt;
|
float rpm = 60.0 * NT_PER_SECOND * mult / diffNt;
|
||||||
rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ trigger_central_s::trigger_central_s() : hwEventCounters() {
|
||||||
|
|
||||||
TriggerCentral::TriggerCentral() : trigger_central_s() {
|
TriggerCentral::TriggerCentral() : trigger_central_s() {
|
||||||
// we need this initial to have not_running at first invocation
|
// we need this initial to have not_running at first invocation
|
||||||
previousShaftEventTimeNt = (efitimems_t) -10 * US2NT(US_PER_SECOND_LL);
|
previousShaftEventTimeNt = (efitimems_t) -10 * NT_PER_SECOND;
|
||||||
|
|
||||||
clearCallbacks(&triggerListeneres);
|
clearCallbacks(&triggerListeneres);
|
||||||
triggerState.resetTriggerState();
|
triggerState.resetTriggerState();
|
||||||
|
@ -198,7 +198,7 @@ void hwHandleShaftSignal(trigger_event_e signal, efitick_t timestamp) {
|
||||||
// Log to the Tunerstudio tooth logger
|
// Log to the Tunerstudio tooth logger
|
||||||
// We want to do this before anything else as we
|
// We want to do this before anything else as we
|
||||||
// actually want to capture any noise/jitter that may be occurring
|
// actually want to capture any noise/jitter that may be occurring
|
||||||
LogTriggerTooth(signal);
|
LogTriggerTooth(signal, timestamp);
|
||||||
#endif /* EFI_TOOTH_LOGGER */
|
#endif /* EFI_TOOTH_LOGGER */
|
||||||
|
|
||||||
// for effective noise filtering, we need both signal edges,
|
// for effective noise filtering, we need both signal edges,
|
||||||
|
@ -340,7 +340,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
||||||
efiAssertVoid(CUSTOM_ERR_6638, eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type");
|
efiAssertVoid(CUSTOM_ERR_6638, eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type");
|
||||||
hwEventCounters[eventIndex]++;
|
hwEventCounters[eventIndex]++;
|
||||||
|
|
||||||
if (timestamp - previousShaftEventTimeNt > US2NT(US_PER_SECOND_LL)) {
|
if (timestamp - previousShaftEventTimeNt > NT_PER_SECOND) {
|
||||||
/**
|
/**
|
||||||
* We are here if there is a time gap between now and previous shaft event - that means the engine is not running.
|
* We are here if there is a time gap between now and previous shaft event - that means the engine is not running.
|
||||||
* That means we have lost synchronization since the engine is not running :)
|
* That means we have lost synchronization since the engine is not running :)
|
||||||
|
|
|
@ -448,7 +448,7 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal
|
||||||
* 10 seconds since previous trigger event we do not really care.
|
* 10 seconds since previous trigger event we do not really care.
|
||||||
*/
|
*/
|
||||||
toothDurations[0] =
|
toothDurations[0] =
|
||||||
currentDurationLong > 10 * US2NT(US_PER_SECOND_LL) ? 10 * US2NT(US_PER_SECOND_LL) : currentDurationLong;
|
currentDurationLong > 10 * NT_PER_SECOND ? 10 * NT_PER_SECOND : currentDurationLong;
|
||||||
|
|
||||||
bool haveListener = triggerStateListener != NULL;
|
bool haveListener = triggerStateListener != NULL;
|
||||||
bool isPrimary = triggerWheel == T_PRIMARY;
|
bool isPrimary = triggerWheel == T_PRIMARY;
|
||||||
|
@ -693,7 +693,7 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (someSortOfTriggerError) {
|
if (someSortOfTriggerError) {
|
||||||
if (getTimeNowNt() - lastDecodingErrorTime > US2NT(US_PER_SECOND_LL)) {
|
if (getTimeNowNt() - lastDecodingErrorTime > NT_PER_SECOND) {
|
||||||
someSortOfTriggerError = false;
|
someSortOfTriggerError = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,12 +415,12 @@ static bool cj125periodic(CJ125 *instance DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
case CJ125_PREHEAT:
|
case CJ125_PREHEAT:
|
||||||
// use constant-speed startup heat-up
|
// use constant-speed startup heat-up
|
||||||
if (nowNt - instance->prevNt >= CJ125_HEATER_PREHEAT_PERIOD) {
|
if (nowNt - instance->prevNt >= CJ125_HEATER_PREHEAT_PERIOD) {
|
||||||
float periodSecs = (float)(nowNt - instance->prevNt) / US2NT(US_PER_SECOND_LL);
|
float periodSecs = (float)(nowNt - instance->prevNt) / NT_PER_SECOND;
|
||||||
// maintain speed at ~0.4V/sec
|
// maintain speed at ~0.4V/sec
|
||||||
float preheatDuty = instance->heaterDuty + periodSecs * CJ125_HEATER_PREHEAT_RATE;
|
float preheatDuty = instance->heaterDuty + periodSecs * CJ125_HEATER_PREHEAT_RATE;
|
||||||
instance->SetHeater(preheatDuty PASS_ENGINE_PARAMETER_SUFFIX);
|
instance->SetHeater(preheatDuty PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
// If we are heating too long, and there's still no result, then something is wrong...
|
// If we are heating too long, and there's still no result, then something is wrong...
|
||||||
if (nowNt - instance->startHeatingNt > US2NT(US_PER_SECOND_LL) * CJ125_PREHEAT_TIMEOUT) {
|
if (nowNt - instance->startHeatingNt > NT_PER_SECOND * CJ125_PREHEAT_TIMEOUT) {
|
||||||
instance->setError(CJ125_ERROR_HEATER_MALFUNCTION PASS_ENGINE_PARAMETER_SUFFIX);
|
instance->setError(CJ125_ERROR_HEATER_MALFUNCTION PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
}
|
}
|
||||||
cjPrintData();
|
cjPrintData();
|
||||||
|
|
|
@ -37,10 +37,10 @@ float getVehicleSpeed(void) {
|
||||||
if (!hasVehicleSpeedSensor())
|
if (!hasVehicleSpeedSensor())
|
||||||
return 0;
|
return 0;
|
||||||
efitick_t nowNt = getTimeNowNt();
|
efitick_t nowNt = getTimeNowNt();
|
||||||
if (nowNt - lastSignalTimeNt > US2NT(US_PER_SECOND_LL))
|
if (nowNt - lastSignalTimeNt > NT_PER_SECOND)
|
||||||
return 0; // previous signal time is too long ago - we are stopped
|
return 0; // previous signal time is too long ago - we are stopped
|
||||||
|
|
||||||
return engineConfiguration->vehicleSpeedCoef * US2NT(US_PER_SECOND_LL) / vssDiff;
|
return engineConfiguration->vehicleSpeedCoef * NT_PER_SECOND / vssDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vsAnaWidthCallback(void) {
|
static void vsAnaWidthCallback(void) {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#define US_PER_SECOND 1000000
|
#define US_PER_SECOND 1000000
|
||||||
#define US_PER_SECOND_F 1000000.0
|
#define US_PER_SECOND_F 1000000.0
|
||||||
#define US_PER_SECOND_LL 1000000LL
|
#define US_PER_SECOND_LL 1000000LL
|
||||||
|
#define NT_PER_SECOND (US2NT(US_PER_SECOND_LL))
|
||||||
|
|
||||||
#define MS2US(MS_TIME) ((MS_TIME) * 1000)
|
#define MS2US(MS_TIME) ((MS_TIME) * 1000)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue