Embedded Multicore Building Blocks V1.0.0
duration.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_BASE_C_DURATION_H_
28 #define EMBB_BASE_C_DURATION_H_
29 
30 #include <embb/base/c/errors.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
51 #ifdef DOXYGEN
52 typedef opaque_type embb_duration_t;
53 #else
54 typedef struct embb_duration_t {
58  unsigned long long seconds;
62  unsigned long nanoseconds;
64 #endif /* else defined(DOXYGEN) */
65 
69 #ifdef DOXYGEN
70 #define EMBB_DURATION_INIT
71 #else
72 #define EMBB_DURATION_INIT {0, 0}
73 #endif /* defined(DOXYGEN) */
74 
82 const embb_duration_t* embb_duration_max();
83 
91 const embb_duration_t* embb_duration_min();
92 
99 const embb_duration_t* embb_duration_zero();
100 
112  embb_duration_t* duration,
114  unsigned long long nanoseconds
116  );
117 
129  embb_duration_t* duration,
131  unsigned long long microseconds
133  );
134 
146  embb_duration_t* duration,
148  unsigned long long milliseconds
150  );
151 
163  embb_duration_t* duration,
165  unsigned long long seconds
167  );
168 
179  embb_duration_t* lhs,
181  const embb_duration_t* rhs
183  );
184 
195  const embb_duration_t* duration,
197  unsigned long long* nanoseconds
199  );
200 
211  const embb_duration_t* duration,
213  unsigned long long* microseconds
215  );
216 
227  const embb_duration_t* duration,
229  unsigned long long* milliseconds
231  );
232 
243  const embb_duration_t* duration,
245  unsigned long long* seconds
247  );
248 
260  const embb_duration_t* lhs,
262  const embb_duration_t* rhs
264  );
265 
271 #ifdef __cplusplus
272 } /* Close extern "C" { */
273 #endif
274 
275 #endif /* EMBB_BASE_C_DURATION_H_ */
int embb_duration_set_milliseconds(embb_duration_t *duration, unsigned long long milliseconds)
Sets duration from millisecond ticks.
int embb_duration_add(embb_duration_t *lhs, const embb_duration_t *rhs)
Adds two durations.
int embb_duration_as_microseconds(const embb_duration_t *duration, unsigned long long *microseconds)
Converts duration to microsecond ticks.
int embb_duration_compare(const embb_duration_t *lhs, const embb_duration_t *rhs)
Compares two durations.
int embb_duration_set_nanoseconds(embb_duration_t *duration, unsigned long long nanoseconds)
Set duration from nanosecond ticks.
int embb_duration_set_microseconds(embb_duration_t *duration, unsigned long long microseconds)
Sets duration from microsecond ticks.
int embb_duration_set_seconds(embb_duration_t *duration, unsigned long long seconds)
Sets duration from second ticks.
int embb_duration_as_milliseconds(const embb_duration_t *duration, unsigned long long *milliseconds)
Converts duration to millisecond ticks.
const embb_duration_t * embb_duration_max()
Returns duration with maximum ticks representable by implementation.
const embb_duration_t * embb_duration_zero()
Returns duration of length zero.
opaque_type embb_duration_t
Opaque type representing a relative time duration.
Definition: duration.h:52
int embb_duration_as_seconds(const embb_duration_t *duration, unsigned long long *seconds)
Converts duration to second ticks.
int embb_duration_as_nanoseconds(const embb_duration_t *duration, unsigned long long *nanoseconds)
Converts duration to nanosecond ticks.
const embb_duration_t * embb_duration_min()
Returns duration with minimum ticks representable by implementation.