RTEMS 6.1-rc7
Loading...
Searching...
No Matches
timespec.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR).
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_SCORE_TIMESPEC_H
38#define _RTEMS_SCORE_TIMESPEC_H
39
51#include <stdbool.h> /* bool */
52#include <stdint.h> /* uint32_t */
53#include <time.h> /* struct timespec */
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
69#define _Timespec_Set( _time, _seconds, _nanoseconds ) \
70 do { \
71 (_time)->tv_sec = (_seconds); \
72 (_time)->tv_nsec = (_nanoseconds); \
73 } while (0)
74
83#define _Timespec_Set_to_zero( _time ) \
84 do { \
85 (_time)->tv_sec = 0; \
86 (_time)->tv_nsec = 0; \
87 } while (0)
88
98#define _Timespec_Get_seconds( _time ) \
99 ((_time)->tv_sec)
100
110#define _Timespec_Get_nanoseconds( _time ) \
111 ((_time)->tv_nsec)
112
123 const struct timespec *time
124);
125
135 const struct timespec *time
136);
137
149 const struct timespec *time
150);
151
164 const struct timespec *lhs,
165 const struct timespec *rhs
166);
167
179#define _Timespec_Greater_than( _lhs, _rhs ) \
180 _Timespec_Less_than( _rhs, _lhs )
181
193#define _Timespec_Equal_to( lhs, rhs ) \
194 ( ((lhs)->tv_sec == (rhs)->tv_sec) && \
195 ((lhs)->tv_nsec == (rhs)->tv_nsec) \
196 )
197
209time_t _Timespec_Add_to(
210 struct timespec *time,
211 const struct timespec *add
212);
213
224uint32_t _Timespec_To_ticks(
225 const struct timespec *time
226);
227
238 uint32_t ticks,
239 struct timespec *time
240);
241
253 const struct timespec *start,
254 const struct timespec *end,
255 struct timespec *result
256);
257
270 const struct timespec *time,
271 uint32_t iterations,
272 struct timespec *result
273);
274
287 const struct timespec *lhs,
288 const struct timespec *rhs,
289 uint32_t *ival_percentage,
290 uint32_t *fval_percentage
291);
292
293#ifdef __cplusplus
294}
295#endif
296
299#endif
300/* end of include file */
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
bool _Timespec_Less_than(const struct timespec *lhs, const struct timespec *rhs)
Checks if the left hand side timespec is less than the right one.
Definition: timespeclessthan.c:46
uint32_t _Timespec_To_ticks(const struct timespec *time)
Converts timespec to number of ticks.
Definition: timespectoticks.c:51
uint64_t _Timespec_Get_as_nanoseconds(const struct timespec *time)
Gets the timestamp as nanoseconds.
Definition: timespecgetasnanoseconds.c:44
void _Timespec_From_ticks(uint32_t ticks, struct timespec *time)
Converts ticks to timespec.
Definition: timespecfromticks.c:46
bool _Timespec_Is_non_negative(const struct timespec *time)
Checks if the values in time are non-negative.
Definition: timespecisnonnegative.c:43
bool _Timespec_Is_valid(const struct timespec *time)
Checks if timespec is valid.
Definition: timespecisvalid.c:45
void _Timespec_Subtract(const struct timespec *start, const struct timespec *end, struct timespec *result)
Subtracts two timespec.
Definition: timespecsubtract.c:45
time_t _Timespec_Add_to(struct timespec *time, const struct timespec *add)
Adds two timespecs.
Definition: timespecaddto.c:46
void _Timespec_Divide_by_integer(const struct timespec *time, uint32_t iterations, struct timespec *result)
Divides timespec by an integer.
Definition: timespecdividebyinteger.c:45