From b377e1f2f0197fdf9dea98827bff52b72ad318a4 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 19 Jan 2020 00:16:19 -0500 Subject: [PATCH] better variable name & docs --- firmware/hw_layer/microsecond_timer.cpp | 21 +++++++++++---------- firmware/hw_layer/microsecond_timer.h | 6 ++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/firmware/hw_layer/microsecond_timer.cpp b/firmware/hw_layer/microsecond_timer.cpp index ee65154423..38e95bcf18 100644 --- a/firmware/hw_layer/microsecond_timer.cpp +++ b/firmware/hw_layer/microsecond_timer.cpp @@ -67,23 +67,24 @@ extern bool hasFirmwareErrorFlag; * sets the alarm to the specified number of microseconds from now. * This function should be invoked under kernel lock which would disable interrupts. */ -void setHardwareUsTimer(int32_t timeUs) { +void setHardwareUsTimer(int32_t deltaTimeUs) { enginePins.debugSetTimer.setValue(1); efiAssertVoid(OBD_PCM_Processor_Fault, hwStarted, "HW.started"); setHwTimerCounter++; /** - * #259 BUG error: not positive timeUs + * #259 BUG error: not positive deltaTimeUs * Once in a while we night get an interrupt where we do not expect it */ - if (timeUs <= 0) { + if (deltaTimeUs <= 0) { timerFreezeCounter++; warning(CUSTOM_OBD_LOCAL_FREEZE, "local freeze cnt=%d", timerFreezeCounter); } - if (timeUs < 2) - timeUs = 2; // for some reason '1' does not really work - efiAssertVoid(CUSTOM_ERR_6681, timeUs > 0, "not positive timeUs"); - if (timeUs >= 10 * US_PER_SECOND) { - firmwareError(CUSTOM_ERR_TIMER_OVERFLOW, "setHardwareUsTimer() too long: %d", timeUs); + if (deltaTimeUs < 2) + deltaTimeUs = 2; // for some reason '1' does not really work + efiAssertVoid(CUSTOM_ERR_6681, deltaTimeUs > 0, "not positive deltaTimeUs"); + if (deltaTimeUs >= 10 * US_PER_SECOND) { + // we are trying to set callback for too far into the future. This does not look right at all + firmwareError(CUSTOM_ERR_TIMER_OVERFLOW, "setHardwareUsTimer() too long: %d", deltaTimeUs); // let's make this look special and NOT toggle enginePins.debugSetTimer return; } @@ -100,10 +101,10 @@ void setHardwareUsTimer(int32_t timeUs) { // let's make this look special and NOT toggle enginePins.debugSetTimer return; } - gptStartOneShotI(&GPTDEVICE, timeUs); + gptStartOneShotI(&GPTDEVICE, deltaTimeUs); lastSetTimerTimeNt = getTimeNowNt(); - lastSetTimerValue = timeUs; + lastSetTimerValue = deltaTimeUs; isTimerPending = TRUE; timerRestartCounter++; enginePins.debugSetTimer.setValue(0); diff --git a/firmware/hw_layer/microsecond_timer.h b/firmware/hw_layer/microsecond_timer.h index 68824cc0e0..3a4ce98aee 100644 --- a/firmware/hw_layer/microsecond_timer.h +++ b/firmware/hw_layer/microsecond_timer.h @@ -5,8 +5,7 @@ * @author Andrey Belomutskiy, (c) 2012-2020 */ -#ifndef SIGNAL_TEMP_H_ -#define SIGNAL_TEMP_H_ +#pragma once #ifdef __cplusplus extern "C" @@ -14,10 +13,9 @@ extern "C" #endif /* __cplusplus */ void initMicrosecondTimer(void); -void setHardwareUsTimer(int32_t timeUs); +void setHardwareUsTimer(int32_t deltaTimeUs); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* SIGNAL_TEMP_H_ */