diff --git a/Makefile b/Makefile index 5b5a4c5..ff16a61 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ PROJECT_DIR = . +US_TO_NT_MULTIPLIER = 100 + # Imported source files and paths RUSEFI_LIB = . include $(RUSEFI_LIB)/util/util.mk @@ -57,6 +59,7 @@ ifeq ($(USE_OPT),) #USE_OPT = $(RFLAGS) -O2 -fgnu89-inline -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99 -Werror-implicit-function-declaration -Werror -Wno-error=pointer-sign -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers USE_OPT = -c -Wall -O0 -ggdb -g USE_OPT += -Werror=missing-field-initializers -Werror=shadow + USE_OPT += -D US_TO_NT_MULTIPLIER=$(US_TO_NT_MULTIPLIER) endif # C specific options here (added to USE_OPT). diff --git a/mock/global.h b/mock/global.h index 7dbf2f7..e69de29 100644 --- a/mock/global.h +++ b/mock/global.h @@ -1,3 +0,0 @@ -// test value just for unit tests - -#define US_TO_NT_MULTIPLIER 100 \ No newline at end of file diff --git a/util/include/rusefi/rusefi_time_math.h b/util/include/rusefi/rusefi_time_math.h index 6fdbd34..ec8346c 100644 --- a/util/include/rusefi/rusefi_time_math.h +++ b/util/include/rusefi/rusefi_time_math.h @@ -1,16 +1,27 @@ +#pragma once + +#include -#include #include +static_assert( + std::is_same_v, + "US_TO_NT_MULTIPLIER macro should be defined as a positive integer value" +); + +constexpr int TICKS_IN_US = US_TO_NT_MULTIPLIER; + +static_assert(0 < TICKS_IN_US, "US_TO_NT_MULTIPLIER macro should be defined as a positive integer value"); + // microseconds to ticks, but floating point // If converting a floating point time period, use this macro to avoid // the expensive conversions from int64 <-> float -#define USF2NT(us_float) ((us_float) * US_TO_NT_MULTIPLIER) +#define USF2NT(us_float) ((us_float) * TICKS_IN_US) #define USF2MS(us_float) (0.001f * (us_float)) // And back -#define NT2US(x) ((x) / US_TO_NT_MULTIPLIER) -#define NT2USF(x) (((float)(x)) / US_TO_NT_MULTIPLIER) +#define NT2US(x) ((x) / TICKS_IN_US) +#define NT2USF(x) (((float)(x)) / TICKS_IN_US) #define NT_PER_SECOND (US2NT(US_PER_SECOND_LL))