100 #if !defined( MBG_TGT_KERNEL ) || defined( MBG_TGT_WIN32 ) 130 #define GPS_SEC_BIAS 315964800UL // ( ( ( 10UL * 365UL ) + 2 + 5 ) * SECS_PER_DAY ) 142 #define NTP_SEC_BIAS 2208988800UL 144 #if !defined( MBG_TGT_MISSING_64_BIT_TYPES ) 145 #define NTP_FRAC_PER_SEC (uint64_t) 4294967296.0 154 #define MJD_AT_GPS_EPOCH 44244UL // MJD at 1980-01-06 155 #define MJD_AT_UNIX_EPOCH 40587UL // MJD at 1970-01-01 156 #define MJD_AT_NTP_EPOCH 40587UL // MJD at 1900-01-01 162 #if !defined( FILETIME_1970 ) 165 #if MBG_TGT_C99 || defined( __GNUC__ ) 167 #define FILETIME_1970 0x019db1ded53e8000ULL // Epoch offset from FILETIME to UNIX 168 #elif defined( MBG_TGT_WIN32 ) 170 #define FILETIME_1970 0x019db1ded53e8000ui64 177 #define MASK_CLOCK_T 0x7FFFFFFFL 179 #define MASK_CLOCK_T 0x7FFF 183 #if defined( __WATCOMC__ ) 184 #define MASK_CLOCK_T 0x7FFFFFFFL 187 #if defined( _CVI ) || defined( _CVI_ ) 188 #define MASK_CLOCK_T 0x7FFFFFFFL 191 #if defined( _MSC_VER ) 192 #define MASK_CLOCK_T 0x7FFFFFFFL 195 #if defined( __NETWARE_386__ ) 196 #define MASK_CLOCK_T 0x7FFFFFFFL 200 #define MASK_CLOCK_T 0x7FFFFFFFL 203 #if defined( __ARMCC_VERSION ) 204 #define MASK_CLOCK_T ( ( (ulong) (clock_t) -1 ) >> 1 ) 207 #if defined( __GNUC__ ) 208 #if defined( __linux ) 209 #define MASK_CLOCK_T ( ( (ulong) (clock_t) -1 ) >> 1 ) 210 #else // Windows / MinGW 211 #define MASK_CLOCK_T 0x7FFFFFFFL 216 #if !defined( MASK_CLOCK_T ) 217 #if sizeof( clock_t ) == sizeof( short ) 218 #define MASK_CLOCK_T 0x7FFF 219 #elif sizeof( clock_t ) == sizeof( long ) 220 #define MASK_CLOCK_T 0x7FFFFFFFL 233 #define DAYS_PER_WEEK 7 235 #define SECS_PER_MIN 60 236 #define MINS_PER_HOUR 60 237 #define HOURS_PER_DAY 24 238 #define DAYS_PER_WEEK 7 240 #define MINS_PER_DAY ( MINS_PER_HOUR * HOURS_PER_DAY ) 242 #define SECS_PER_HOUR 3600 243 #define SECS_PER_DAY 86400L 244 #define SECS_PER_WEEK 604800L 246 #define SEC100S_PER_SEC 100L 247 #define SEC100S_PER_MIN ( SEC100S_PER_SEC * SECS_PER_MIN ) 248 #define SEC100S_PER_HOUR ( SEC100S_PER_SEC * SECS_PER_HOUR ) 249 #define SEC100S_PER_DAY ( SEC100S_PER_SEC * SECS_PER_DAY ) 251 #if !defined( MSEC_PER_SEC ) 252 #define MSEC_PER_SEC 1000L 255 #define MSEC_PER_MIN ( MSEC_PER_SEC * SECS_PER_MIN ) 256 #define MSEC_PER_HOUR ( MSEC_PER_SEC * SECS_PER_HOUR ) 257 #define MSEC_PER_DAY ( MSEC_PER_SEC * SECS_PER_DAY ) 259 #if !defined( USEC_PER_SEC ) 260 #define USEC_PER_SEC 1000000L 263 #if !defined( NSEC_PER_SEC ) 264 #define NSEC_PER_SEC 1000000000L 267 #if !defined( HNS_PER_SEC ) 268 #define HNS_PER_SEC 10000000L 271 #if !defined( HNS_PER_MS ) 272 #define HNS_PER_MS 10000L 275 #if !defined( HNS_PER_MIN ) 276 #define HNS_PER_MIN ( HNS_PER_SEC * SECS_PER_MIN ) 279 #define MSEC_TO_NSEC_MULTIPLIER ( NSEC_PER_SEC / MSEC_PER_SEC ) 280 #define MSEC_TO_USEC_MULTIPLIER ( USEC_PER_SEC / MSEC_PER_SEC ) 297 #define DAYS_OF_MONTH_TABLE_INIT \ 299 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, \ 300 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } \ 324 =
"%2i:%02i:%02i.%02i" 336 =
"%s, %2i.%02i.%04i" 342 = {
"Su",
"Mo",
"Tu",
"We",
"Th",
"Fr",
"Sa" }
348 = {
"So",
"Mo",
"Di",
"Mi",
"Do",
"Fr",
"Sa" }
354 = { 1980, 1, 1, 0, 0, 0, 0, 0, 0, 0 }
367 #define _n_days( _s ) \ 368 n_days( (_s)->mday, (_s)->month, (_s)->year ) 371 #define _is_leap_year( _y ) \ 372 ( ( ( ( (_y) % 4 ) == 0 ) && ( ( (_y) % 100 ) != 0 ) ) || ( ( (_y) % 400 ) == 0 ) ) 375 #define _get_days_of_month( _y, _m ) \ 376 days_of_month[ _is_leap_year( _y ) ][_m] 380 #if !defined( MBG_TGT_KERNEL ) 389 #if defined( MBG_TGT_MISSING_64_BIT_TYPES ) 390 #define MBG_FRAC32_CONVERSION_TYPE double 392 #define MBG_FRAC32_CONVERSION_TYPE int64_t 400 #define MBG_FRAC32_UNITS_PER_SEC ( (MBG_FRAC32_CONVERSION_TYPE) 4294967296.0 ) // == 0x100000000 448 #if !defined( MBG_TGT_MISSING_64_BIT_TYPES ) 472 #endif // !defined( MBG_TGT_MISSING_64_BIT_TYPES ) 476 #define bin_frac_32_to_msec( _bin ) bin_frac_32_to_dec_frac( (_bin), 1000L ) 477 #define bin_frac_32_to_usec( _bin ) bin_frac_32_to_dec_frac( (_bin), 1000000L ) 478 #define bin_frac_32_to_nsec( _bin ) bin_frac_32_to_dec_frac( (_bin), 1000000000L ) 479 #define bin_frac_16_to_msec( _bin ) bin_frac_16_to_dec_frac( (_bin), 1000L ) 480 #define bin_frac_16_to_usec( _bin ) bin_frac_16_to_dec_frac( (_bin), 1000000L ) 481 #define bin_frac_16_to_nsec( _bin ) bin_frac_16_to_dec_frac( (_bin), 1000000000L ) 484 #define msec_to_bin_frac_32( _msec ) dec_frac_to_bin_frac_32( (_msec), 1000L ) 485 #define usec_to_bin_frac_32( _usec ) dec_frac_to_bin_frac_32( (_usec), 1000000L ) 486 #define nsec_to_bin_frac_32( _nsec ) dec_frac_to_bin_frac_32( (_nsec), 1000000000L ) 487 #define msec_to_bin_frac_16( _msec ) dec_frac_to_bin_frac_16( (_msec), 1000L ) 488 #define usec_to_bin_frac_16( _usec ) dec_frac_to_bin_frac_16( (_usec), 1000000L ) 489 #define nsec_to_bin_frac_16( _nsec ) dec_frac_to_bin_frac_16( (_nsec), 1000000000L ) 509 uint32_t _DEPRECATED_BY(
"bin_frac_32_to_dec_frac" )
frac_sec_from_bin( uint32_t b, uint32_t scale )
540 #endif // !defined( MBG_TGT_KERNEL ) int sprint_short_time(char *s, const TM_GPS *tm)
Print time with hours, minutes to a string.
void sscan_date(char *s, TM_GPS *tm)
Extract a date from a string.
bit check_timeout(TIMEOUT *t, clock_t clk)
Check if a timeout object has expired.
const char * short_time_fmt
#define MBG_FRAC32_CONVERSION_TYPE
Data type used for intermediate results on 32 bit multiplications.
Local date and time computed from GPS time.
const char * long_time_fmt
void sscan_time(const char *s, TM_GPS *tm)
Extract a time from a string.
int day_of_year(int day, int month, int year)
Compute the day-of-year from a given date.
static __mbg_inline uint32_t bin_frac_16_to_dec_frac(uint16_t bin, uint32_t scale)
Convert a 16 bit binary fraction to a scaled decimal.
TM_GPS * wsec_to_tm(long wsec, TM_GPS *tm)
Convert second-of-week to day-of-week and time-of-day.
const char * day_name_eng[]
static __mbg_inline uint32_t frac_sec_from_bin(uint32_t b, uint32_t scale)
Convert a binary fraction to a scaled decimal.
void date_of_year(int year, int day_num, TM_GPS *tm)
Compute a date from a given year and day-of-year.
long tm_to_wsec(const TM_GPS *tm)
Compute second-of-week from day-of-week and time-of-day.
void stretch_timeout(TIMEOUT *t, clock_t interval)
Stretch a timeout specified in given timeout object.
TM_GPS * clear_time(TM_GPS *tm)
Set the time in a TM_GPS structure to 00:00:00.000.
int day_of_week(int day, int month, int year)
Compute day-of-week from a given date.
long n_days(ushort mday, ushort month, ushort year)
Compute number of days after Jan 1, 0000 for a given date.
int is_leap_year(int y)
Check if a specific year is a leap year.
static __mbg_inline uint16_t dec_frac_to_bin_frac_16(uint32_t dec, uint32_t scale)
int sprint_time(char *s, const TM_GPS *tm)
Print time with hours, minutes, seconds to a string.
static __mbg_inline uint32_t dec_frac_to_bin_frac_32(uint32_t dec, uint32_t scale)
void set_timeout(TIMEOUT *t, clock_t clk, clock_t interval)
Set a timeout object to specified interval.
#define MBG_FRAC32_UNITS_PER_SEC
Constant used to convert e.g. PCPS_TIME_STAMP::frac values.
char DAYS_OF_MONTH_TABLE[2][12]
A table with the days of month.
DAYS_OF_MONTH_TABLE days_of_month
const char * day_name_ger[]
int sprint_tm(char *s, const TM_GPS *tm)
Print day-of-week, date and time to a string.
static __mbg_inline uint32_t bin_frac_32_to_dec_frac(uint32_t bin, uint32_t scale)
Convert a 32 bit binary fraction to a scaled decimal.
int sprint_day_date(char *s, const TM_GPS *tm)
Print day-of-week and date to a string.
int sprint_date(char *s, const TM_GPS *tm)
Print date to a string.
int err_tm(const TM_GPS *tm)
Check if a TM_GPS structure contains a valid date and time.
int days_to_years(long *day_num, int year)
Update a year number by a number of days, accounting for leap years.
#define DAYS_OF_MONTH_TABLE_INIT
An initializer for a DAYS_OF_MONTH_TABLE.
static __mbg_inline double dfrac_sec_from_bin(uint32_t b)
Convert a binary fraction to "double" fractions.
const char * day_date_fmt