move US_TO_NT_MULTIPLIER macro definition in Makefile

This commit is contained in:
kifir 2024-05-02 01:04:56 +03:00
parent 315b8ad9e1
commit 1efbb324f5
3 changed files with 18 additions and 7 deletions

View File

@ -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).

View File

@ -1,3 +0,0 @@
// test value just for unit tests
#define US_TO_NT_MULTIPLIER 100

View File

@ -1,16 +1,27 @@
#pragma once
#include <type_traits>
#include <global.h>
#include <rusefi/rusefi_time_types.h>
static_assert(
std::is_same_v<decltype(US_TO_NT_MULTIPLIER), int>,
"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))