summaryrefslogtreecommitdiffstats
path: root/drivers/staging/csr/csr_time.h
blob: 0ede47e911f1c3745bcaffc585e7730d4d1cae55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef CSR_TIME_H__
#define CSR_TIME_H__
/*****************************************************************************

            (c) Cambridge Silicon Radio Limited 2010
            All rights reserved and confidential information of CSR

            Refer to LICENSE.txt included with this source for details
            on the license terms.

*****************************************************************************/

#include "csr_types.h"

#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************

    NAME
        CsrTime

    DESCRIPTION
        Type to hold a value describing the current system time, which is a
        measure of time elapsed since some arbitrarily defined fixed time
        reference, usually associated with system startup.

*******************************************************************************/
typedef CsrUint32 CsrTime;


/*******************************************************************************

    NAME
        CsrTimeUtc

    DESCRIPTION
        Type to hold a value describing a UTC wallclock time expressed in
        seconds and milliseconds elapsed since midnight January 1st 1970.

*******************************************************************************/
typedef struct
{
    CsrUint32 sec;
    CsrUint16 msec;
} CsrTimeUtc;


/*******************************************************************************

    NAME
        CsrTimeGet

    DESCRIPTION
        Returns the current system time in a low and a high part. The low part
        is expressed in microseconds. The high part is incremented when the low
        part wraps to provide an extended range.

        The caller may provide a NULL pointer as the high parameter. In this case
        the function just returns the low part and ignores the high parameter.

        Although the time is expressed in microseconds the actual resolution is
        platform dependent and can be less. It is recommended that the
        resolution is at least 10 milliseconds.

    PARAMETERS
        high - Pointer to variable that will receive the high part of the
               current system time. Passing NULL is valid.

    RETURNS
        Low part of current system time in microseconds.

*******************************************************************************/
CsrTime CsrTimeGet(CsrTime *high);


/*******************************************************************************

    NAME
        CsrTimeUtcGet

    DESCRIPTION
        Get the current system wallclock time, and optionally the current system
        time in a low and a high part as would have been returned by
        CsrTimeGet.

        Although CsrTimeUtc is expressed in seconds and milliseconds, the actual
        resolution is platform dependent, and can be less. It is recommended
        that the resolution is at least 1 second.

    PARAMETERS
        tod - Pointer to variable that will receive the current system
              wallclock time.
        low - The low part of the current system time in microseconds. Passing
              NULL is valid.
        high - The high part of the current system time in microseconds. Passing
               NULL is valid.

*******************************************************************************/
void CsrTimeUtcGet(CsrTimeUtc *tod, CsrTime *low, CsrTime *high);


/*------------------------------------------------------------------*/
/* CsrTime Macros */
/*------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*
 *  NAME
 *      CsrTimeAdd
 *
 *  DESCRIPTION
 *      Add two time values. Adding the numbers can overflow the range of a
 *      CsrTime, so the user must be cautious.
 *
 *  RETURNS
 *      CsrTime - the sum of "t1" and "t2".
 *
 *----------------------------------------------------------------------------*/
#define CsrTimeAdd(t1, t2) ((t1) + (t2))

/*----------------------------------------------------------------------------*
 *  NAME
 *      CsrTimeSub
 *
 *  DESCRIPTION
 *      Subtract two time values. Subtracting the numbers can provoke an
 *      underflow, so the user must be cautious.
 *
 *  RETURNS
 *      CsrTime - "t1" - "t2".
 *
 *----------------------------------------------------------------------------*/
#define CsrTimeSub(t1, t2)    ((CsrInt32) (t1) - (CsrInt32) (t2))

/*----------------------------------------------------------------------------*
 *  NAME
 *      CsrTimeEq
 *
 *  DESCRIPTION
 *      Compare two time values.
 *
 *  RETURNS
 *      !0 if "t1" equal "t2", else 0.
 *
 *----------------------------------------------------------------------------*/
#define CsrTimeEq(t1, t2) ((t1) == (t2))

/*----------------------------------------------------------------------------*
 *  NAME
 *      CsrTimeGt
 *
 *  DESCRIPTION
 *      Compare two time values.
 *
 *  RETURNS
 *      !0 if "t1" is greater than "t2", else 0.
 *
 *----------------------------------------------------------------------------*/
#define CsrTimeGt(t1, t2) (CsrTimeSub((t1), (t2)) > 0)

/*----------------------------------------------------------------------------*
 *  NAME
 *      CsrTimeGe
 *
 *  DESCRIPTION
 *      Compare two time values.
 *
 *  RETURNS
 *      !0 if "t1" is greater than, or equal to "t2", else 0.
 *
 *----------------------------------------------------------------------------*/
#define CsrTimeGe(t1, t2) (CsrTimeSub((t1), (t2)) >= 0)

/*----------------------------------------------------------------------------*
 *  NAME
 *      CsrTimeLt
 *
 *  DESCRIPTION
 *      Compare two time values.
 *
 *  RETURNS
 *      !0 if "t1" is less than "t2", else 0.
 *
 *----------------------------------------------------------------------------*/
#define CsrTimeLt(t1, t2) (CsrTimeSub((t1), (t2)) < 0)

/*----------------------------------------------------------------------------*
 *  NAME
 *      CsrTimeLe
 *
 *  DESCRIPTION
 *      Compare two time values.
 *
 *  RETURNS
 *      !0 if "t1" is less than, or equal to "t2", else 0.
 *
 *----------------------------------------------------------------------------*/
#define CsrTimeLe(t1, t2) (CsrTimeSub((t1), (t2)) <= 0)

#ifdef __cplusplus
}
#endif

#endif