//***************************************************************************** // (C) Automotive Lighting Reutlingen GmbH // Tuebinger Strasse 123, 72762 Reutlingen, Germany // // Automotive Lighting Reutlingen GmbH owns all the rights to this work. // This work shall not be copied, reproduced, used, modified, transferred // or its information shall not be disclosed without the prior written // authorization of Automotive Lighting Reutlingen GmbH. //***************************************************************************** //----------------------------------------------------------------------------- /// \file Util_Time.h /// /// \brief /// //----------------------------------------------------------------------------- #ifndef UTIL_TIME_2020_06_15_H_ #define UTIL_TIME_2020_06_15_H_ //***************************************************************************** // includes //***************************************************************************** #include #include // Define UTIL_TIME_GPT_CHANNEL and ticks Located in Project specific folder #if !defined(UNIT_TEST) #include "Gpt32bit.h" #else // get system tick start from windows startup, in Milliseconds extern uint32 GetTickCount(); #endif //***************************************************************************** // types //***************************************************************************** typedef uint16 STIMER; typedef uint32 TIMER; typedef sint16 STIMER_SIGNED; typedef sint32 TIMER_SIGNED; typedef TIMER tFTimer; //***************************************************************************** // macros //***************************************************************************** #if !defined(UNIT_TEST) #define UTILTIME_USEC(x) ((TIMER) ((x) * UTIL_GPT_TICK_PER_MICROSECOND)) #define UTILTIME_MSEC(x) ((TIMER) ( 1000UL * UTILTIME_USEC((x)))) #define UTILTIME_SEC(x) ((TIMER) (1000000UL * UTILTIME_USEC((x)))) #else // for UNIT TEST only. convert time parater to millisecond #define UTILTIME_USEC(x) ((TIMER) ((x) / 1000) #define UTILTIME_MSEC(x) ((TIMER) ( x )) #define UTILTIME_SEC(x) ((TIMER) (1000UL * (x))) #define Gpt_GetTimeElapsed_32bit(x) GetTickCount() #define Gpt_GetTimeElapsed(x) GetTickCount() #endif #define UTILTIME_TICK2USEC(ticks) ((uint32) ((ticks) / UTIL_GPT_TICK_PER_MICROSECOND)) #define TimerShortStart(T) ( (STIMER) ( (STIMER) Gpt_GetTimeElapsed((Gpt_ChannelType) UTIL_TIME_GPT_CHANNEL) + (STIMER) (T))) #define TimerShortTimeout(T) ((boolean) (((STIMER) (((STIMER) ((STIMER) Gpt_GetTimeElapsed((Gpt_ChannelType) UTIL_TIME_GPT_CHANNEL) - (STIMER) (T)) & (STIMER) 0x00008000UL)) == (STIMER) 0U) ? TRUE : FALSE)) #define TimerShortTimeoutOfCustomTick(T, CT) ((boolean) (((STIMER) (((STIMER) ((STIMER) (CT) - (STIMER) (T)) & (STIMER) 0x00008000UL)) == (STIMER) 0U) ? TRUE : FALSE)) #define TimerShortGetTimeSince(T) ((STIMER) ((STIMER) Gpt_GetTimeElapsed((Gpt_ChannelType) UTIL_TIME_GPT_CHANNEL) - (STIMER) (T))) #define TimerShortGetTick() ((STIMER) Gpt_GetTimeElapsed((Gpt_ChannelType) UTIL_TIME_GPT_CHANNEL)) #define TimerStart(T) ( ( TIMER) ( ( TIMER) Gpt_GetTimeElapsed_32bit((Gpt_ChannelType) UTIL_TIME_GPT_CHANNEL) + ( TIMER) (T))) #define TimerTimeout(T) ((boolean) ((( TIMER) ((( TIMER) (( TIMER) Gpt_GetTimeElapsed_32bit((Gpt_ChannelType) UTIL_TIME_GPT_CHANNEL) - ( TIMER) (T)) & ( TIMER) 0x80000000UL)) == ( TIMER) 0U) ? TRUE : FALSE)) #define TimerTimeoutOfCustomTick(T, CT) ((boolean) ((( TIMER) ((( TIMER) (( TIMER) (CT) - ( TIMER) (T)) & ( TIMER) 0x80000000UL)) == ( TIMER) 0U) ? TRUE : FALSE)) #define TimerGetTimeSince(T) ( ( TIMER) (( TIMER) Gpt_GetTimeElapsed_32bit((Gpt_ChannelType) UTIL_TIME_GPT_CHANNEL) - ( TIMER) (T))) #define TimerGetTick() (( TIMER) Gpt_GetTimeElapsed_32bit((Gpt_ChannelType) UTIL_TIME_GPT_CHANNEL)) #define UTILTIME_TIMER_START(T) TimerStart(T) #define UTILTIME_TIMER_TIMEOUT(T) TimerTimeout(T) #define UTILTIME_TIMER_TIMEOUT_OF_CUSTOM_TICK(T, CT) TimerTimeoutOfCustomTick(T, CT) #define UTILTIME_TIMER_GET_TIME_SINCE(T) TimerGetTimeSince(T) #define UTILTIME_TIMER_GET_TICK() TimerGetTick() #define UTILTIME_TIMER_SHORT_START(T) TimerShortStart(T) #define UTILTIME_TIMER_SHORT_TIMEOUT(T) TimerShortTimeout(T) #define UTILTIME_TIMER_SHORT_TIMEOUT_OF_CUSTOM_TICK(T, CT) TimerShortTimeoutOfCustomTick(T, CT) #define UTILTIME_TIMER_SHORT_GET_TIME_SINCE(T) TimerShortGetTimeSince(T) #define UTILTIME_TIMER_SHORT_GET_TICK() TimerShortGetTick() #endif // UTIL_TIME_2020_06_15_H_