staging: csr: remove CsrInt32 typedef
[linux-2.6-block.git] / drivers / staging / csr / csr_time.h
1 #ifndef CSR_TIME_H__
2 #define CSR_TIME_H__
3 /*****************************************************************************
4
5             (c) Cambridge Silicon Radio Limited 2010
6             All rights reserved and confidential information of CSR
7
8             Refer to LICENSE.txt included with this source for details
9             on the license terms.
10
11 *****************************************************************************/
12
13 #include "csr_types.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /*******************************************************************************
20
21     NAME
22         CsrTime
23
24     DESCRIPTION
25         Type to hold a value describing the current system time, which is a
26         measure of time elapsed since some arbitrarily defined fixed time
27         reference, usually associated with system startup.
28
29 *******************************************************************************/
30 typedef u32 CsrTime;
31
32
33 /*******************************************************************************
34
35     NAME
36         CsrTimeUtc
37
38     DESCRIPTION
39         Type to hold a value describing a UTC wallclock time expressed in
40         seconds and milliseconds elapsed since midnight January 1st 1970.
41
42 *******************************************************************************/
43 typedef struct
44 {
45     u32 sec;
46     u16 msec;
47 } CsrTimeUtc;
48
49
50 /*******************************************************************************
51
52     NAME
53         CsrTimeGet
54
55     DESCRIPTION
56         Returns the current system time in a low and a high part. The low part
57         is expressed in microseconds. The high part is incremented when the low
58         part wraps to provide an extended range.
59
60         The caller may provide a NULL pointer as the high parameter. In this case
61         the function just returns the low part and ignores the high parameter.
62
63         Although the time is expressed in microseconds the actual resolution is
64         platform dependent and can be less. It is recommended that the
65         resolution is at least 10 milliseconds.
66
67     PARAMETERS
68         high - Pointer to variable that will receive the high part of the
69                current system time. Passing NULL is valid.
70
71     RETURNS
72         Low part of current system time in microseconds.
73
74 *******************************************************************************/
75 CsrTime CsrTimeGet(CsrTime *high);
76
77
78 /*******************************************************************************
79
80     NAME
81         CsrTimeUtcGet
82
83     DESCRIPTION
84         Get the current system wallclock time, and optionally the current system
85         time in a low and a high part as would have been returned by
86         CsrTimeGet.
87
88         Although CsrTimeUtc is expressed in seconds and milliseconds, the actual
89         resolution is platform dependent, and can be less. It is recommended
90         that the resolution is at least 1 second.
91
92     PARAMETERS
93         tod - Pointer to variable that will receive the current system
94               wallclock time.
95         low - The low part of the current system time in microseconds. Passing
96               NULL is valid.
97         high - The high part of the current system time in microseconds. Passing
98                NULL is valid.
99
100 *******************************************************************************/
101 void CsrTimeUtcGet(CsrTimeUtc *tod, CsrTime *low, CsrTime *high);
102
103
104 /*------------------------------------------------------------------*/
105 /* CsrTime Macros */
106 /*------------------------------------------------------------------*/
107
108 /*----------------------------------------------------------------------------*
109  *  NAME
110  *      CsrTimeAdd
111  *
112  *  DESCRIPTION
113  *      Add two time values. Adding the numbers can overflow the range of a
114  *      CsrTime, so the user must be cautious.
115  *
116  *  RETURNS
117  *      CsrTime - the sum of "t1" and "t2".
118  *
119  *----------------------------------------------------------------------------*/
120 #define CsrTimeAdd(t1, t2) ((t1) + (t2))
121
122 /*----------------------------------------------------------------------------*
123  *  NAME
124  *      CsrTimeSub
125  *
126  *  DESCRIPTION
127  *      Subtract two time values. Subtracting the numbers can provoke an
128  *      underflow, so the user must be cautious.
129  *
130  *  RETURNS
131  *      CsrTime - "t1" - "t2".
132  *
133  *----------------------------------------------------------------------------*/
134 #define CsrTimeSub(t1, t2)    ((s32) (t1) - (s32) (t2))
135
136 /*----------------------------------------------------------------------------*
137  *  NAME
138  *      CsrTimeEq
139  *
140  *  DESCRIPTION
141  *      Compare two time values.
142  *
143  *  RETURNS
144  *      !0 if "t1" equal "t2", else 0.
145  *
146  *----------------------------------------------------------------------------*/
147 #define CsrTimeEq(t1, t2) ((t1) == (t2))
148
149 /*----------------------------------------------------------------------------*
150  *  NAME
151  *      CsrTimeGt
152  *
153  *  DESCRIPTION
154  *      Compare two time values.
155  *
156  *  RETURNS
157  *      !0 if "t1" is greater than "t2", else 0.
158  *
159  *----------------------------------------------------------------------------*/
160 #define CsrTimeGt(t1, t2) (CsrTimeSub((t1), (t2)) > 0)
161
162 /*----------------------------------------------------------------------------*
163  *  NAME
164  *      CsrTimeGe
165  *
166  *  DESCRIPTION
167  *      Compare two time values.
168  *
169  *  RETURNS
170  *      !0 if "t1" is greater than, or equal to "t2", else 0.
171  *
172  *----------------------------------------------------------------------------*/
173 #define CsrTimeGe(t1, t2) (CsrTimeSub((t1), (t2)) >= 0)
174
175 /*----------------------------------------------------------------------------*
176  *  NAME
177  *      CsrTimeLt
178  *
179  *  DESCRIPTION
180  *      Compare two time values.
181  *
182  *  RETURNS
183  *      !0 if "t1" is less than "t2", else 0.
184  *
185  *----------------------------------------------------------------------------*/
186 #define CsrTimeLt(t1, t2) (CsrTimeSub((t1), (t2)) < 0)
187
188 /*----------------------------------------------------------------------------*
189  *  NAME
190  *      CsrTimeLe
191  *
192  *  DESCRIPTION
193  *      Compare two time values.
194  *
195  *  RETURNS
196  *      !0 if "t1" is less than, or equal to "t2", else 0.
197  *
198  *----------------------------------------------------------------------------*/
199 #define CsrTimeLe(t1, t2) (CsrTimeSub((t1), (t2)) <= 0)
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif