fome-fw/firmware/controllers/math/efitime.h

65 lines
1.4 KiB
C
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file efitime.h
*
* By the way, there are 86400000 milliseconds in a day
*
* @date Apr 14, 2014
2015-01-12 15:04:10 -08:00
* @author Andrey Belomutskiy, (c) 2012-2015
2014-08-29 07:52:33 -07:00
*/
#ifndef EFITIME_H_
#define EFITIME_H_
#include "efifeatures.h"
2015-01-12 19:03:53 -08:00
#include "rusefi_types.h"
2014-08-29 07:52:33 -07:00
#define US_PER_SECOND 1000000
2014-11-06 18:05:30 -08:00
#define US_PER_SECOND_LL 1000000LL
2014-08-29 07:52:33 -07:00
#define MS2US(MS_TIME) ((MS_TIME) * 1000)
#define US_TO_TI_TEMP 10
// todo: implement a function to work with times considering counter overflow
#define overflowDiff(now, time) ((now) - (time))
2015-01-12 19:03:53 -08:00
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
2014-08-29 07:52:33 -07:00
/**
* 64-bit counter of microseconds (1/1 000 000 of a second) since MCU reset
*
2014-09-12 20:04:25 -07:00
* By using 64 bit, we can achieve a very precise timestamp which does not overflow.
2014-08-29 07:52:33 -07:00
* The primary implementation counts the number of CPU cycles from MCU reset.
2014-10-02 21:02:57 -07:00
*
* WARNING: you should use getTimeNowNt where possible for performance reasons.
* The heaviest part is '__aeabi_ildivmod' - non-native 64 bit division
2014-08-29 07:52:33 -07:00
*/
2015-01-02 18:03:33 -08:00
efitimeus_t getTimeNowUs(void);
2014-08-29 07:52:33 -07:00
2014-09-12 20:04:25 -07:00
/**
* 64-bit counter CPU cycles since MCU reset
*/
2015-01-02 18:03:33 -08:00
efitick_t getTimeNowNt(void);
2014-09-12 20:04:25 -07:00
2014-08-29 07:52:33 -07:00
uint64_t getHalTimer(void);
/**
* @brief Returns the number of milliseconds since the board initialization.
*/
efitimems_t currentTimeMillis(void);
/**
* @brief Current system time in seconds.
*/
int getTimeNowSeconds(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* EFITIME_H_ */