diff --git a/firmware/controllers/algo/obd_error_codes.h b/firmware/controllers/algo/obd_error_codes.h index fb7e0bfc59..479d862e10 100644 --- a/firmware/controllers/algo/obd_error_codes.h +++ b/firmware/controllers/algo/obd_error_codes.h @@ -2082,7 +2082,7 @@ typedef enum { CUSTOM_INVALID_ADC = 6720, CUSTOM_INVALID_MODE_SETTING = 6721, - CUSTOM_ERR_6722 = 6722, + CUSTOM_ERR_TASK_TIMER_OVERFLOW = 6722, CUSTOM_ERR_6723 = 6723, CUSTOM_ERR_6724 = 6724, CUSTOM_ERR_6725 = 6725, diff --git a/firmware/controllers/system/timer/single_timer_executor.cpp b/firmware/controllers/system/timer/single_timer_executor.cpp index 928e9f6e9c..3c1fe8689a 100644 --- a/firmware/controllers/system/timer/single_timer_executor.cpp +++ b/firmware/controllers/system/timer/single_timer_executor.cpp @@ -87,6 +87,16 @@ void SingleTimerExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeu void SingleTimerExecutor::scheduleByTimestampNt(scheduling_s* scheduling, efitime_t nt, action_s action) { ScopePerf perf(PE::SingleTimerExecutorScheduleByTimestamp); +#if EFI_ENABLE_ASSERTS + int deltaTimeUs = nt - getTimeNowNt(); + + if (deltaTimeUs >= TOO_FAR_INTO_FUTURE) { + // we are trying to set callback for too far into the future. This does not look right at all + firmwareError(CUSTOM_ERR_TASK_TIMER_OVERFLOW, "scheduleByTimestampNt() too far: %d", deltaTimeUs); + return; + } +#endif + scheduleCounter++; bool alreadyLocked = true; if (!reentrantFlag) { diff --git a/firmware/hw_layer/microsecond_timer.cpp b/firmware/hw_layer/microsecond_timer.cpp index 38e95bcf18..8b43f9fd8c 100644 --- a/firmware/hw_layer/microsecond_timer.cpp +++ b/firmware/hw_layer/microsecond_timer.cpp @@ -82,9 +82,9 @@ void setHardwareUsTimer(int32_t deltaTimeUs) { 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) { + if (deltaTimeUs >= TOO_FAR_INTO_FUTURE) { // 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); + firmwareError(CUSTOM_ERR_TIMER_OVERFLOW, "setHardwareUsTimer() too far: %d", deltaTimeUs); // let's make this look special and NOT toggle enginePins.debugSetTimer return; } diff --git a/firmware/hw_layer/microsecond_timer.h b/firmware/hw_layer/microsecond_timer.h index 3a4ce98aee..52e02d7cc2 100644 --- a/firmware/hw_layer/microsecond_timer.h +++ b/firmware/hw_layer/microsecond_timer.h @@ -15,6 +15,8 @@ extern "C" void initMicrosecondTimer(void); void setHardwareUsTimer(int32_t deltaTimeUs); +#define TOO_FAR_INTO_FUTURE 10 * US_PER_SECOND + #ifdef __cplusplus } #endif /* __cplusplus */