1 /*
2  * Copyright (c) 2018 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief API to the native_posix (Real) Time Clock
10  */
11 
12 
13 #ifndef _NATIVE_POSIX_RTC_H
14 #define _NATIVE_POSIX_RTC_H
15 
16 #include "hw_models_top.h"
17 #include <stdbool.h>
18 #include <zephyr/types.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /*
25  * Types of clocks this RTC provides:
26  */
27 /** Time since boot, cannot be offset. Microsecond resolution */
28 #define RTC_CLOCK_BOOT               0
29 /** Persistent clock, can be offset. Microsecond resolution */
30 #define RTC_CLOCK_REALTIME           1
31 /**
32  * Pseudo-host real time clock (Please see documentation).
33  * Nanosecond resolution
34  */
35 #define RTC_CLOCK_PSEUDOHOSTREALTIME 2
36 
37 /**
38  * @brief Get the value of a clock in microseconds
39  *
40  * @param clock_type Which clock to measure from
41  *
42  * @return Number of microseconds
43  */
44 uint64_t native_rtc_gettime_us(int clock_type);
45 
46 /**
47  * @brief Get the value of a clock split in nsec and seconds
48  *
49  * @param clock_type Which clock to measure from
50  * @param nsec Pointer to store the nanoseconds
51  * @param nsec Pointer to store the seconds
52  */
53 void native_rtc_gettime(int clock_type, uint32_t *nsec, uint64_t *sec);
54 
55 /**
56  * @brief Offset the real time clock by a number of microseconds.
57  * Note that this only affects the RTC_CLOCK_REALTIME and
58  * RTC_CLOCK_PSEUDOHOSTREALTIME clocks.
59  *
60  * @param delta_us Number of microseconds to offset. The value is added to all
61  * offsetable clocks.
62  */
63 void native_rtc_offset(int64_t delta_us);
64 
65 /**
66  * @brief Adjust the speed of the clock source by a multiplicative factor
67  *
68  * @param clock_correction Factor by which to correct the clock speed
69  */
70 void native_rtc_adjust_clock(double clock_correction);
71 
72 #ifdef __cplusplus
73 }
74 #endif
75 
76 #endif /* _NATIVE_POSIX_RTC_H */
77