rusefi/firmware/util/efitime.h

48 lines
1.2 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file efitime.h
*
* By the way, there are 86400000 milliseconds in a day
*
* @date Apr 14, 2014
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
2020-01-20 22:40:11 -08:00
#pragma once
2015-07-10 06:01:56 -07:00
#include "efifeatures.h"
#include "rusefi_types.h"
2022-10-26 07:37:07 -07:00
#include "global.h"
2023-08-30 20:11:24 -07:00
#include <rusefi/rusefi_time_math.h>
2015-07-10 06:01:56 -07:00
#if EFI_PROD_CODE
// for US_TO_NT_MULTIPLIER which is port-specific
#include "port_mpu_util.h"
#endif
// microseconds to ticks
// since only about 20 seconds of ticks fit in 32 bits this macro is casting parameter into 64 bits 'efitick_t' type
2020-12-03 07:31:16 -08:00
// please note that int64 <-> float is a heavy operation thus we have 'USF2NT' below
#define US2NT(us) (((efitick_t)(us)) * US_TO_NT_MULTIPLIER)
2020-12-03 07:26:50 -08:00
2019-12-21 18:18:38 -08:00
// milliseconds to ticks
#define MS2NT(msTime) US2NT(MS2US(msTime))
2020-12-03 07:26:50 -08:00
// See USF2NT above for when to use MSF2NT
#define MSF2NT(msTimeFloat) USF2NT(MS2US(msTimeFloat))
2019-12-21 18:18:38 -08:00
/**
* 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
*/
uint32_t getTimeNowLowerNt();
2015-07-10 06:01:56 -07:00
/**
* @brief Returns the number of milliseconds since the board initialization.
*/
efitimems_t getTimeNowMs();
2015-07-10 06:01:56 -07:00
/**
* @brief Current system time in seconds.
*/
efitimesec_t getTimeNowS();