rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
efitime.h File Reference

Detailed Description

By the way, there are 86400000 milliseconds in a day

Date
Apr 14, 2014
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file efitime.h.

Functions

int time2print (int64_t time)
 
constexpr bool constexpr_isfinite (float f)
 
constexpr bool _assertFloatFitsInto32BitsAndCast (float value)
 
constexpr int32_t assertFloatFitsInto32BitsAndCast (const char *msg, float value)
 
efitick_t sumTickAndFloat (efitick_t ticks, float extra)
 
uint32_t getTimeNowLowerNt ()
 
efitimems_t getTimeNowMs ()
 Returns the 32 bit number of milliseconds since the board initialization.
 
efitimesec_t getTimeNowS ()
 Current system time in seconds (32 bits)
 
void setTimeNowUs (int us)
 
void advanceTimeUs (int us)
 

Function Documentation

◆ _assertFloatFitsInto32BitsAndCast()

constexpr bool _assertFloatFitsInto32BitsAndCast ( float  value)
constexpr

Definition at line 40 of file efitime.h.

40 {
41 constexpr auto FirstUnrepresentableBigFloat = static_cast<float>(INT32_MAX);
42 constexpr auto kInt32MinF = static_cast<float>(INT32_MIN);
43
44 // 32bit float has 24bit precision that lead to fiasco like:
45 // 2147483648.0 > 2147483647 == false
46 // Also at 2147483648.0 we need 2^7=128 step to go to next value of 2147483904.0f
47 // And 2147483648.0f is already non-representable in 32 bit int
48 // So if someone using corner value of max int for smth like invalid float
49 // we might accidentally give green light if we are not strictly under 2147483648.0
50 // i.e. do not change this check to implicit convertion int->float with non strict condition!
51 return constexpr_isfinite(value) && value >= kInt32MinF && value < FirstUnrepresentableBigFloat;
52}
constexpr bool constexpr_isfinite(float f)
Definition efitime.h:27

Referenced by assertFloatFitsInto32BitsAndCast().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ advanceTimeUs()

void advanceTimeUs ( int  us)

Referenced by configureRusefiLuaHooks(), LuaPid::get(), and LuaIndustrialPid::get().

Here is the caller graph for this function:

◆ assertFloatFitsInto32BitsAndCast()

constexpr int32_t assertFloatFitsInto32BitsAndCast ( const char msg,
float  value 
)
constexpr

Definition at line 82 of file efitime.h.

82 {
84 criticalError("%s value is not representable in 32bit int: %f", msg, value);
85 }
86
87 return static_cast<int32_t>(value);
88}
constexpr bool _assertFloatFitsInto32BitsAndCast(float value)
Definition efitime.h:40

Referenced by PrimeController::onIgnitionStateChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ constexpr_isfinite()

constexpr bool constexpr_isfinite ( float  f)
constexpr

Definition at line 27 of file efitime.h.

27 {
28#if __cplusplus >= 202302L
29 // In C++23, std::isfinite is officially constexpr
30 return std::isfinite(f);
31#elif defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
32 // On Windows and macOS, std::isfinite might not be constexpr pre-C++23
33 return true;
34#else
35 // This is meant to correspond to normal/target platforms
36 return std::isfinite(f);
37#endif
38}

Referenced by _assertFloatFitsInto32BitsAndCast().

Here is the caller graph for this function:

◆ getTimeNowLowerNt()

uint32_t getTimeNowLowerNt ( )

Get a monotonically increasing (but wrapping) 32-bit timer value Implemented at port level, based on timer or CPU tick counter Main source of EFI clock, SW-extended to 64bits

2147483648 / ~168MHz = ~12 seconds to overflow

Definition at line 43 of file microsecond_timer_gpt.cpp.

43 {
44 return port_rt_get_counter_value();
45}

Referenced by getTimeNowNt(), handleShaftSignal(), onLockHook(), onUnlockHook(), and portMicrosecondTimerCallback().

Here is the caller graph for this function:

◆ getTimeNowMs()

efitimems_t getTimeNowMs ( )

Returns the 32 bit number of milliseconds since the board initialization.

32 bit return type overflows in 23(or46?) days. tag#4554. I think we do not expect rusEFI to run for 23 days straight days any time soon?

Definition at line 34 of file efitime.cpp.

34 {
35 return US2MS(getTimeNowUs());
36}
efitimeus_t getTimeNowUs()
Definition efitime.cpp:26

Referenced by assertTimeIsLinear(), printGpsInfo(), sayHello(), StepperMotorBase::setInitialPosition(), testMath(), testRusefiMethods(), testSystemCalls(), updateTriggerWaveformIfNeeded(), and MLG::writeSdBlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTimeNowS()

efitimesec_t getTimeNowS ( )

Current system time in seconds (32 bits)

32 bit integer number of seconds since ECU boot. 31,710 years - would not overflow during our life span.

Definition at line 42 of file efitime.cpp.

42 {
43 return getTimeNowUs() / US_PER_SECOND;
44}

Referenced by boardSdCardEnable(), configureRusefiLuaUtilHooks(), AdcDevice::getAvgAdcValue(), handleTestCommand(), TriggerDecoderBase::printGaps(), printVersionForConsole(), sendQcBenchBoardStatus(), timeInfo(), updateDevConsoleState(), and updateTunerStudioState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTimeNowUs()

void setTimeNowUs ( int  us)

◆ sumTickAndFloat()

efitick_t sumTickAndFloat ( efitick_t  ticks,
float  extra 
)
inline

Definition at line 90 of file efitime.h.

90 {
91 // we have a peculiar case of type compiler uses to evaluate expression vs precision here
92 // we need 64 bit precision not (lower) float precision
93 // 32 bits is 11 or 23 seconds if US_TO_NT_MULTIPLIER = 168 like on kinetis/cypress
94 // 32 bits is 500 or 1000 seconds if US_TO_NT_MULTIPLIER = 4 like on stm32
95 // 'extra' is below 10 seconds here so we use 32 bit type for performance reasons
96 return ticks + (int32_t) extra;
97}

Referenced by PrimeController::onPrimeStart(), scheduleByAngle(), and scheduleSparkEvent().

Here is the caller graph for this function:

◆ time2print()

int time2print ( int64_t  time)
inline

Go to the source code of this file.