2022-09-11 10:06:03 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2024-04-03 11:50:21 -07:00
|
|
|
/**
|
|
|
|
* problem: we have three files with bits and pieces of time API and documentation
|
|
|
|
* 1) this implementation class
|
|
|
|
* 2) rusEFI header efitime.h
|
|
|
|
* 3) libfirmware header rusefi_time_types.h
|
|
|
|
*/
|
|
|
|
|
2022-09-11 10:06:03 -07:00
|
|
|
#if !EFI_UNIT_TEST
|
|
|
|
|
2023-08-30 20:47:26 -07:00
|
|
|
#include <rusefi/rusefi_time_wraparound.h>
|
|
|
|
|
2022-09-11 10:06:03 -07:00
|
|
|
static WrapAround62 timeNt;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 64-bit counter CPU/timer cycles since MCU reset
|
|
|
|
*/
|
|
|
|
efitick_t getTimeNowNt() {
|
|
|
|
return timeNt.update(getTimeNowLowerNt());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 64-bit result would not overflow, but that's complex stuff for our 32-bit MCU
|
|
|
|
*/
|
|
|
|
efitimeus_t getTimeNowUs() {
|
|
|
|
ScopePerf perf(PE::GetTimeNowUs);
|
|
|
|
return NT2US(getTimeNowNt());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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?
|
|
|
|
*/
|
2024-04-03 10:08:42 -07:00
|
|
|
efitimems_t getTimeNowMs() {
|
2022-09-11 10:06:03 -07:00
|
|
|
return US2MS(getTimeNowUs());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-04-03 11:50:21 -07:00
|
|
|
* 32 bit integer number of seconds since ECU boot.
|
2022-09-11 10:06:03 -07:00
|
|
|
* 31,710 years - would not overflow during our life span.
|
|
|
|
*/
|
2024-04-03 10:08:42 -07:00
|
|
|
efitimesec_t getTimeNowS() {
|
2022-09-11 10:06:03 -07:00
|
|
|
return getTimeNowUs() / US_PER_SECOND;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !EFI_UNIT_TEST */
|