RTEMS
6.3
Toggle main menu visibility
Loading...
Searching...
No Matches
cpukit
include
rtems
score
timestampimpl.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: BSD-2-Clause */
2
11
12
/*
13
* COPYRIGHT (c) 1989-2009.
14
* On-Line Applications Research Corporation (OAR).
15
*
16
* Redistribution and use in source and binary forms, with or without
17
* modification, are permitted provided that the following conditions
18
* are met:
19
* 1. Redistributions of source code must retain the above copyright
20
* notice, this list of conditions and the following disclaimer.
21
* 2. Redistributions in binary form must reproduce the above copyright
22
* notice, this list of conditions and the following disclaimer in the
23
* documentation and/or other materials provided with the distribution.
24
*
25
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
* POSSIBILITY OF SUCH DAMAGE.
36
*/
37
38
#ifndef _RTEMS_SCORE_TIMESTAMPIMPL_H
39
#define _RTEMS_SCORE_TIMESTAMPIMPL_H
40
46
47
#include <
rtems/score/timestamp.h
>
48
#include <
rtems/score/basedefs.h
>
49
50
#include <sys/time.h>
51
52
#ifdef __cplusplus
53
extern
"C"
{
54
#endif
55
66
static
inline
void
_Timestamp_Set(
67
Timestamp_Control
*_time,
68
time_t _seconds,
69
long
_nanoseconds
70
)
71
{
72
struct
timespec _ts;
73
74
_ts.tv_sec = _seconds;
75
_ts.tv_nsec = _nanoseconds;
76
77
*_time = tstosbt(_ts);
78
}
79
88
89
static
inline
void
_Timestamp_Set_to_zero(
90
Timestamp_Control
*_time
91
)
92
{
93
*_time = 0;
94
}
95
107
108
static
inline
bool
_Timestamp_Less_than(
109
const
Timestamp_Control
*_lhs,
110
const
Timestamp_Control
*_rhs
111
)
112
{
113
return
*_lhs < *_rhs;
114
}
115
127
128
static
inline
bool
_Timestamp_Greater_than(
129
const
Timestamp_Control
*_lhs,
130
const
Timestamp_Control
*_rhs
131
)
132
{
133
return
*_lhs > *_rhs;
134
}
135
147
148
static
inline
bool
_Timestamp_Equal_to(
149
const
Timestamp_Control
*_lhs,
150
const
Timestamp_Control
*_rhs
151
)
152
{
153
return
*_lhs == *_rhs;
154
}
155
165
static
inline
void
_Timestamp_Add_to(
166
Timestamp_Control
*_time,
167
const
Timestamp_Control
*_add
168
)
169
{
170
*_time += *_add;
171
}
172
184
static
inline
void
_Timestamp_Subtract(
185
const
Timestamp_Control
*
_start
,
186
const
Timestamp_Control
*_end,
187
Timestamp_Control
*_result
188
)
189
{
190
*_result = *_end - *
_start
;
191
}
192
204
static
inline
void
_Timestamp_Divide(
205
const
Timestamp_Control
*_lhs,
206
const
Timestamp_Control
*_rhs,
207
uint32_t *_ival_percentage,
208
uint32_t *_fval_percentage
209
)
210
{
211
struct
timespec _ts_left;
212
struct
timespec _ts_right;
213
214
_ts_left = sbttots( *_lhs );
215
_ts_right = sbttots( *_rhs );
216
217
_Timespec_Divide
(
218
&_ts_left,
219
&_ts_right,
220
_ival_percentage,
221
_fval_percentage
222
);
223
}
224
234
static
inline
time_t _Timestamp_Get_seconds(
235
const
Timestamp_Control
*_time
236
)
237
{
238
return
(*_time >> 32);
239
}
240
250
static
inline
uint32_t _Timestamp_Get_nanoseconds(
251
const
Timestamp_Control
*_time
252
)
253
{
254
struct
timespec _ts;
255
256
_ts = sbttots( *_time );
257
258
return
(uint32_t) _ts.tv_nsec;
259
}
260
270
static
inline
uint64_t _Timestamp_Get_as_nanoseconds(
271
const
Timestamp_Control
*_time
272
)
273
{
274
struct
timespec _ts;
275
276
_ts = sbttots( *_time );
277
278
return
_Timespec_Get_as_nanoseconds
( &_ts );
279
}
280
287
static
inline
void
_Timestamp_To_timespec(
288
const
Timestamp_Control
*_timestamp,
289
struct
timespec *_timespec
290
)
291
{
292
*_timespec = sbttots( *_timestamp );
293
}
294
301
static
inline
void
_Timestamp_To_timeval(
302
const
Timestamp_Control
*_timestamp,
303
struct
timeval *_timeval
304
)
305
{
306
*_timeval = sbttotv( *_timestamp );
307
}
308
309
#ifdef __cplusplus
310
}
311
#endif
312
314
315
#endif
316
/* end of include file */
basedefs.h
This header file provides basic definitions used by the API and the implementation.
_Timespec_Divide
void _Timespec_Divide(const struct timespec *lhs, const struct timespec *rhs, uint32_t *ival_percentage, uint32_t *fval_percentage)
Divides a timespec by another timespec.
Definition
timespecdivide.c:45
_Timespec_Get_as_nanoseconds
uint64_t _Timespec_Get_as_nanoseconds(const struct timespec *time)
Gets the timestamp as nanoseconds.
Definition
timespecgetasnanoseconds.c:44
Timestamp_Control
int64_t Timestamp_Control
Definition
timestamp.h:76
_start
void _start(void)
System start entry.
timestamp.h
This header file provides interfaces of the Timestamp Handler which are used by the implementation an...
Generated by
1.18.0