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