From b1f32ea049113e4f4cbedefecbddd1fd942e9ed7 Mon Sep 17 00:00:00 2001 From: Rakesh Mundlamuri Date: Fri, 30 Jan 2026 12:04:55 +0530 Subject: [PATCH] Synchronize multiple gNBs by aliging to the slot boundary Currently, we derive frame and slot number based on `proc->timestamp_rx` using `proc->frame_rx = (proc->timestamp_rx / (fp->samples_per_subframe*10))&1023;` and `proc->tti_rx = get_slot_from_timestamp(proc->timestamp_rx, fp);` This ignores the samples `proc->timestamp_rx % fp->samples_per_frame` while computing the frame and slot number creating a mis-alignment with the slot boundaries. We fix this alignment by compensating these samples during the first reception. --- executables/nr-ru.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/executables/nr-ru.c b/executables/nr-ru.c index 397f940745..cd91abb086 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -609,6 +609,25 @@ static void rx_rf(RU_t *ru, int *frame, int *slot) proc->first_rx = 0; *frame = proc->frame_rx; *slot = proc->tti_rx; + + // Align to slot boundary + uint64_t samples_to_slot_boundary = 0; + uint64_t sample_offset_within_frame = proc->timestamp_rx % fp->samples_per_frame; + uint64_t sample_offset_within_slot = sample_offset_within_frame - get_samples_slot_timestamp(fp, *slot); + if (sample_offset_within_slot > 0) { + samples_to_slot_boundary = get_samples_per_slot(*slot, fp) - sample_offset_within_slot; + LOG_A(NR_PHY, "Aligning to the slot boundary %lu\n", samples_to_slot_boundary); + + // Read and discard the samples in the first_rx to align to the slot boundary + rxs = ru->rfdevice.trx_read_func(&ru->rfdevice, &ts, rxp, samples_to_slot_boundary, nb); + if (rxs != samples_to_slot_boundary) + LOG_E(PHY, "rx_rf: Asked for %ld samples, got %d from USRP\n", samples_to_slot_boundary, rxs); + + proc->timestamp_rx += samples_to_slot_boundary; + if (*slot + 1 >= fp->slots_per_frame) + *frame = *frame + 1; + *slot = (*slot + 1) % fp->slots_per_frame; + } } metadata mt = {.slot = *slot, .frame = *frame};