rusEFI
The most advanced open source ECU
efitime.cpp
Go to the documentation of this file.
1 #include "pch.h"
2 
3 /**
4  * problem: we have three files with bits and pieces of time API and documentation
5  * 1) this implementation class
6  * 2) rusEFI header efitime.h
7  * 3) libfirmware header rusefi_time_types.h
8  */
9 
10 #if !EFI_UNIT_TEST
11 
12 #include <rusefi/rusefi_time_wraparound.h>
13 
14 static WrapAround62 timeNt;
15 
16 /**
17  * 64-bit counter CPU/timer cycles since MCU reset
18  */
19 efitick_t getTimeNowNt() {
20  return timeNt.update(getTimeNowLowerNt());
21 }
22 
23 /**
24  * 64-bit result would not overflow, but that's complex stuff for our 32-bit MCU
25  */
26 efitimeus_t getTimeNowUs() {
28  return NT2US(getTimeNowNt());
29 }
30 
31 /**
32  * 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?
33  */
35  return US2MS(getTimeNowUs());
36 }
37 
38 /**
39  * 32 bit integer number of seconds since ECU boot.
40  * 31,710 years - would not overflow during our life span.
41  */
42 efitimesec_t getTimeNowS() {
43  return getTimeNowUs() / US_PER_SECOND;
44 }
45 
46 #endif /* !EFI_UNIT_TEST */
efitick_t getTimeNowNt()
Definition: efitime.cpp:19
efitimeus_t getTimeNowUs()
Definition: efitime.cpp:26
efitimesec_t getTimeNowS()
Current system time in seconds (32 bits)
Definition: efitime.cpp:42
static WrapAround62 timeNt
Definition: efitime.cpp:14
efitimems_t getTimeNowMs()
Returns the 32 bit number of milliseconds since the board initialization.
Definition: efitime.cpp:34
uint32_t getTimeNowLowerNt()
@ GetTimeNowUs
uint32_t efitimems_t
Definition: rusefi_types.h:43