time.h (2259B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: time.h 8 * Purpose: SAL time definitions 9 * 10 * Microsecond Time Routines 11 * 12 * The main clock abstraction is sal_usecs_t, an unsigned 32-bit 13 * counter that increments every microsecond and wraps around every 14 * 4294.967296 seconds (~71.5 minutes) 15 */ 16 17 #ifndef _SAL_TIME_H 18 #define _SAL_TIME_H 19 20 #include <sal/types.h> 21 22 /* 23 * Constants 24 */ 25 26 #define MILLISECOND_USEC (1000) 27 #define SECOND_USEC (1000000) 28 #define MINUTE_USEC (60 * SECOND_USEC) 29 #define HOUR_USEC (60 * MINUTE_USEC) 30 31 #define SECOND_MSEC (1000) 32 #define MINUTE_MSEC (60 * SECOND_MSEC) 33 34 #define SAL_USECS_TIMESTAMP_ROLLOVER ((uint32)(0xFFFFFFFF)) 35 36 typedef unsigned long sal_time_t; 37 typedef uint32 sal_usecs_t; 38 39 void sal_time_usecs_register(sal_usecs_t (*f)(void)); 40 void sal_time_register(sal_time_t (*f)(void)); 41 42 /* Relative time in microseconds modulo 2^32 */ 43 extern sal_usecs_t sal_time_usecs(void); 44 45 /* Absolute time in seconds ala Unix time, interrupt-safe */ 46 extern sal_time_t sal_time(void); 47 48 #ifdef COMPILER_HAS_DOUBLE 49 50 void sal_time_double_register(double (*f)(void)); 51 52 /* 53 * Time since boot in seconds as a double precision value, useful for 54 * benchmarking. Precision is platform-dependent and may be limited to 55 * scheduler clock period. On a Mousse it uses the timebase and has a 56 * precision of 80 ns (0.00000008). 57 */ 58 extern double sal_time_double(void); 59 #define SAL_TIME_DOUBLE() sal_time_double() 60 61 #else /* COMPILER_HAS_DOUBLE */ 62 #define SAL_TIME_DOUBLE() sal_time() 63 #endif 64 65 66 /* 67 * SAL_USECS_SUB 68 * 69 * Subtracts two sal_usecs_t and returns signed integer microseconds. 70 * Can be used as a comparison because it returns: 71 * 72 * integer < 0 if A < B 73 * integer > 0 if A > B 74 * integer = 0 if A == B 75 * 76 * SAL_USECS_ADD 77 * 78 * Adds usec to time. Wrap-around is OK as long as the total 79 * amount added is less than 0x7fffffff. 80 */ 81 82 #define SAL_USECS_SUB(_t2, _t1) (((int) ((_t2) - (_t1)))) 83 #define SAL_USECS_ADD(_t, _us) ((_t) + (_us)) 84 85 #endif /* !_SAL_TIME_H */