41 #define NSEC_PER_SEC 1000000000L 42 #define NSEC_PER_USEC 1000L 44 #define TIMECOMPENSATION 2 46 #define SEC_MOD_STOP (60) 48 static struct timespec started_time;
49 static struct timespec last_time;
50 static struct timespec cur_time;
52 static uint64_t curr_tick;
53 static uint64_t last_tick;
55 static struct timespec* p_cur_time = &cur_time;
56 static struct timespec* p_last_time = &last_time;
59 static struct timespec* p_temp_time;
61 static unsigned long current_second = 0;
62 static unsigned long started_second = 0;
63 static uint8_t numerlogy = 0;
68 static int debugStop = 0;
69 static int debugStopCount = 0;
71 static long fine_tuning[5][2] =
80 static uint8_t slots_per_subframe[4] =
90 return current_second;
102 debugStopCount = count;
105 clock_gettime(CLOCK_REALTIME, &started_time);
106 started_second =started_time.tv_sec;
120 long nsec = p_time->tv_nsec + p_xran_dev_ctx->
offset_nsec;
127 p_time->tv_nsec = nsec;
134 __asm
volatile (
"rdtsc" :
"=a"(lo),
"=d"(hi));
135 return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 );
140 if (curr_tick >= last_tick)
141 return (
unsigned long)(curr_tick - last_tick);
143 return (
unsigned long)(0xFFFFFFFFFFFFFFFF - last_tick + curr_tick);
151 static int counter = 0;
152 static long sym_acc = 0;
153 static long sym_cnt = 0;
156 clock_gettime(CLOCK_REALTIME, p_last_time);
160 current_second = p_last_time->tv_sec;
164 target_time = (p_last_time->tv_sec *
NSEC_PER_SEC + p_last_time->tv_nsec + interval_ns);
167 clock_gettime(CLOCK_REALTIME, p_cur_time);
171 delta = (p_cur_time->tv_sec *
NSEC_PER_SEC + p_cur_time->tv_nsec) - target_time;
172 if(delta > 0 || (delta < 0 && abs(delta) <
THRESHOLD)) {
173 if (debugStop &&(debugStopCount > 0) && (
tx_counter >= debugStopCount)){
175 printf(
"STOP:[%ld.%09ld], debugStopCount %d, tx_counter %ld\n", p_cur_time->tv_sec, p_cur_time->tv_nsec, debugStopCount,
tx_counter);
181 if(current_second != p_cur_time->tv_sec){
182 current_second = p_cur_time->tv_sec;
189 print_dbg(
"ToS:C Sync timestamp: [%ld.%09ld]\n", p_cur_time->tv_sec, p_cur_time->tv_nsec);
191 if(p_cur_time->tv_sec > started_second && ((p_cur_time->tv_sec %
SEC_MOD_STOP) == 0)){
193 printf(
"STOP:[%ld.%09ld]\n", p_cur_time->tv_sec, p_cur_time->tv_nsec);
200 p_cur_time->tv_nsec = 0;
205 sym_acc += fine_tuning[numerlogy][0];
207 sym_acc += fine_tuning[numerlogy][1];
209 if(sym_cnt % 13 == 0)
212 p_cur_time->tv_nsec = sym_acc;
217 if(debugStop && delta < interval_ns*10)
221 last_tick = curr_tick;
225 p_temp_time = p_last_time;
226 p_last_time = p_cur_time;
227 p_cur_time = p_temp_time;
248 struct timespec start_time;
249 struct timespec cur_time;
251 struct timespec sleep_target_time_convert;
253 long sleep_target_time;
256 clock_gettime(CLOCK_REALTIME, &start_time);
260 sleep_target_time_convert.tv_sec = sleep_target_time * NSEC_PER_USEC /
NSEC_PER_SEC;
266 clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &sleep_target_time_convert, NULL);
268 clock_gettime(CLOCK_REALTIME, &cur_time);
270 delta = (cur_time.tv_sec *
NSEC_PER_SEC + cur_time.tv_nsec) - target_time * NSEC_PER_USEC;
uint32_t xran_lib_ota_sym
#define print_dbg(fmt, args...)
int timing_set_debug_stop(int value, int count)
enum xran_if_state xran_if_current_state
int32_t ring_processing_func(void)
#define PID_TIME_SYSTIME_STOP
long poll_next_tick(long interval_ns, unsigned long *used_tick)
uint32_t xran_lib_ota_sym_idx
void timing_adjust_gps_second(struct timespec *p_time)
struct xran_device_ctx * xran_dev_get_ctx(void)
This file provides interface to Timing for XRAN.
int32_t process_dpdk_io(void)
uint64_t timing_get_current_second(void)
int timing_get_debug_stop(void)
int timing_set_numerology(uint8_t value)
This file has all definitions for the Ethernet Data Interface Layer.
Modules provide debug prints and utility functions.
uint32_t xran_lib_ota_tti
XRAN layer common functionality for both lls-CU and RU as well as C-plane and U-plane.
#define XranIncrementSymIdx(sym_idx, numSymPerMs)
#define XRAN_NUM_OF_SYMBOL_PER_SLOT
void xran_updateSfnSecStart(void)
This file provides public interface to xRAN Front Haul layer implementation as defined in the ORAN-WG...
unsigned long get_ticks_diff(unsigned long curr_tick, unsigned long last_tick)
long sleep_next_tick(long interval)
#define MLogTask(w, x, y)
#define PID_TIME_SYSTIME_POLL