clarify and indent correctly the function initial sync

This commit is contained in:
Laurent THOMAS
2025-06-27 15:21:47 +02:00
parent 10ff80815f
commit fb85a8cda3
+66 -64
View File
@@ -311,7 +311,7 @@ nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc,
fp->dl_CarrierFreq, fp->dl_CarrierFreq,
fp->N_RB_DL, fp->N_RB_DL,
numGscn); numGscn);
DevAssert(numGscn);
task_ans_t ans; task_ans_t ans;
init_task_ans(&ans, numGscn); init_task_ans(&ans, numGscn);
nr_ue_ssb_scan_t ssb_info[numGscn]; nr_ue_ssb_scan_t ssb_info[numGscn];
@@ -342,39 +342,38 @@ nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc,
} }
// Collect the scan results // Collect the scan results
nr_ue_ssb_scan_t res = {0}; nr_ue_ssb_scan_t *res = NULL;
if (numGscn > 0) { join_task_ans(&ans);
join_task_ans(&ans); for (int i = 0; i < numGscn; i++) {
for (int i = 0; i < numGscn; i++) { nr_ue_ssb_scan_t *ssbInfo = &ssb_info[i];
nr_ue_ssb_scan_t *ssbInfo = &ssb_info[i]; if (ssbInfo->syncRes.cell_detected) {
if (ssbInfo->syncRes.cell_detected) { LOG_I(NR_PHY,
LOG_I(NR_PHY, "Cell Detected with GSCN: %d, SSB SC offset: %d, SSB Ref: %lf, PSS Corr peak: %d dB, PSS Corr Average: %d\n",
"Cell Detected with GSCN: %d, SSB SC offset: %d, SSB Ref: %lf, PSS Corr peak: %d dB, PSS Corr Average: %d\n", ssbInfo->gscnInfo.gscn,
ssbInfo->gscnInfo.gscn, ssbInfo->gscnInfo.ssbFirstSC,
ssbInfo->gscnInfo.ssbFirstSC, ssbInfo->gscnInfo.ssRef,
ssbInfo->gscnInfo.ssRef, ssbInfo->pssCorrPeakPower,
ssbInfo->pssCorrPeakPower, ssbInfo->pssCorrAvgPower);
ssbInfo->pssCorrAvgPower); // take the first cell detected
if (!res.syncRes.cell_detected) { // take the first cell detected if (!res)
res = *ssbInfo; res = ssbInfo;
}
}
for (int ant = 0; ant < fp->nb_antennas_rx; ant++) {
free(ssbInfo->rxdata[ant]);
}
free(ssbInfo->rxdata);
} }
for (int ant = 0; ant < fp->nb_antennas_rx; ant++) {
free(ssbInfo->rxdata[ant]);
}
free(ssbInfo->rxdata);
ssbInfo->rxdata = NULL;
} }
// Set globals based on detected cell // Set globals based on detected cell
if (res.syncRes.cell_detected) { if (res) {
fp->Nid_cell = res.nidCell; fp->Nid_cell = res->nidCell;
fp->ssb_start_subcarrier = res.gscnInfo.ssbFirstSC; fp->ssb_start_subcarrier = res->gscnInfo.ssbFirstSC;
fp->half_frame_bit = res.halfFrameBit; fp->half_frame_bit = res->halfFrameBit;
fp->ssb_index = res.ssbIndex; fp->ssb_index = res->ssbIndex;
ue->symbol_offset = res.symbolOffset; ue->symbol_offset = res->symbolOffset;
ue->common_vars.freq_offset = res.freqOffset; ue->common_vars.freq_offset = res->freqOffset;
ue->adjust_rxgain = res.adjust_rxgain; ue->adjust_rxgain = res->adjust_rxgain;
} }
// In initial sync, we indicate PBCH to MAC after the scan is complete. // In initial sync, we indicate PBCH to MAC after the scan is complete.
@@ -389,7 +388,7 @@ nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc,
NULL, NULL,
number_pdus, number_pdus,
proc, proc,
res.syncRes.cell_detected ? (void *)&res.pbchResult : NULL, res ? (void *)&res->pbchResult : NULL,
NULL); NULL);
if (ue->if_inst && ue->if_inst->dl_indication) if (ue->if_inst && ue->if_inst->dl_indication)
@@ -398,73 +397,76 @@ nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc,
LOG_D(PHY, "nr_initial sync ue RB_DL %d\n", fp->N_RB_DL); LOG_D(PHY, "nr_initial sync ue RB_DL %d\n", fp->N_RB_DL);
if (res.syncRes.cell_detected) { if (res) {
// digital compensation of FFO for SSB symbols // digital compensation of FFO for SSB symbols
if (res.freqOffset && ue->UE_fo_compensation) { if (res->freqOffset && ue->UE_fo_compensation) {
// In SA we need to perform frequency offset correction until the end of buffer because we need to decode SIB1 // In SA we need to perform frequency offset correction until the end of buffer because we need to decode SIB1
// and we do not know yet in which slot it goes. // and we do not know yet in which slot it goes.
compensate_freq_offset(ue->common_vars.rxdata, fp, res.freqOffset, res.syncRes.frame_id); compensate_freq_offset(ue->common_vars.rxdata, fp, res->freqOffset, res->syncRes.frame_id);
} }
// sync at symbol ue->symbol_offset // sync at symbol ue->symbol_offset
// computing the offset wrt the beginning of the frame // computing the offset wrt the beginning of the frame
int mu = fp->numerology_index; int mu = fp->numerology_index;
// number of symbols with different prefix length // number of symbols with different prefix length
// every 7*(1<<mu) symbols there is a different prefix length (38.211 5.3.1) // every 7*(1<<mu) symbols there is a different prefix length (38.211 5.3.1)
int n_symb_prefix0 = (res.symbolOffset / (7 * (1 << mu))) + 1; int n_symb_prefix0 = (res->symbolOffset / (7 * (1 << mu))) + 1;
const int sync_pos_frame = n_symb_prefix0 * (fp->ofdm_symbol_size + fp->nb_prefix_samples0) const int sync_pos_frame = n_symb_prefix0 * (fp->ofdm_symbol_size + fp->nb_prefix_samples0)
+ (res.symbolOffset - n_symb_prefix0) * (fp->ofdm_symbol_size + fp->nb_prefix_samples); + (res->symbolOffset - n_symb_prefix0) * (fp->ofdm_symbol_size + fp->nb_prefix_samples);
// for a correct computation of frame number to sync with the one decoded at MIB we need to take into account in which of // for a correct computation of frame number to sync with the one decoded at MIB we need to take into account in which of
// the n_frames we got sync // the n_frames we got sync
ue->init_sync_frame = n_frames - 1 - res.syncRes.frame_id; ue->init_sync_frame = n_frames - 1 - res->syncRes.frame_id;
// we also need to take into account the shift by samples_per_frame in case the if is true // we also need to take into account the shift by samples_per_frame in case the if is true
if (res.ssbOffset < sync_pos_frame) { if (res->ssbOffset < sync_pos_frame) {
res.syncRes.rx_offset = fp->samples_per_frame - sync_pos_frame + res.ssbOffset; res->syncRes.rx_offset = fp->samples_per_frame - sync_pos_frame + res->ssbOffset;
ue->init_sync_frame += 1; ue->init_sync_frame += 1;
} else } else
res.syncRes.rx_offset = res.ssbOffset - sync_pos_frame; res->syncRes.rx_offset = res->ssbOffset - sync_pos_frame;
} }
if (res.syncRes.cell_detected) { if (res) {
LOG_I(PHY, "[UE%d] In synch, rx_offset %d samples\n", ue->Mod_id, res.syncRes.rx_offset); LOG_I(PHY, "[UE%d] In synch, rx_offset %d samples\n", ue->Mod_id, res->syncRes.rx_offset);
LOG_I(PHY, "[UE %d] Measured Carrier Frequency offset %d Hz\n", ue->Mod_id, res.freqOffset); LOG_I(PHY, "[UE %d] Measured Carrier Frequency offset %d Hz\n", ue->Mod_id, res->freqOffset);
} else { } else {
#ifdef DEBUG_INITIAL_SYNC #ifdef DEBUG_INITIAL_SYNC
LOG_I(PHY,"[UE%d] Initial sync : PBCH not ok\n",ue->Mod_id); LOG_I(PHY,"[UE%d] Initial sync : PBCH not ok\n",ue->Mod_id);
LOG_I(PHY, "[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n", ue->Mod_id, sync_pos, ue->common_vars.nid2); LOG_I(PHY, "[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n", ue->Mod_id, sync_pos, ue->common_vars.nid2);
LOG_I(PHY,"[UE%d] Initial sync : Estimated Nid_cell %d, Frame_type %d\n",ue->Mod_id, LOG_I(PHY,"[UE%d] Initial sync : Estimated Nid_cell %d, Frame_type %d\n",ue->Mod_id,
fp->Nid_cell,fp->frame_type); fp->Nid_cell,fp->frame_type);
#endif #endif
} }
// gain control // gain control
if (!res.syncRes.cell_detected) { // we are not synched, so we cannot use rssi measurement (which is based on channel estimates) if (!res) { // we are not synched, so we cannot use rssi measurement (which is based on channel estimates)
int rx_power = 0; int rx_power = 0;
// do a measurement on the best guess of the PSS // do a measurement on the best guess of the PSS
// for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) // for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++)
// rx_power += signal_energy(&ue->common_vars.rxdata[aarx][sync_pos2], // rx_power += signal_energy(&ue->common_vars.rxdata[aarx][sync_pos2],
// frame_parms->ofdm_symbol_size+frame_parms->nb_prefix_samples); // frame_parms->ofdm_symbol_size+frame_parms->nb_prefix_samples);
/* /*
// do a measurement on the full frame // do a measurement on the full frame
for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++)
rx_power += signal_energy(&ue->common_vars.rxdata[aarx][0], rx_power += signal_energy(&ue->common_vars.rxdata[aarx][0],
frame_parms->samples_per_subframe*10); frame_parms->samples_per_subframe*10);
*/ */
// we might add a low-pass filter here later // we might add a low-pass filter here later
ue->measurements.rx_power_avg[0] = rx_power / fp->nb_antennas_rx; ue->measurements.rx_power_avg[0] = rx_power / fp->nb_antennas_rx;
ue->measurements.rx_power_avg_dB[0] = dB_fixed(ue->measurements.rx_power_avg[0]); ue->measurements.rx_power_avg_dB[0] = dB_fixed(ue->measurements.rx_power_avg[0]);
#ifdef DEBUG_INITIAL_SYNCH #ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY, "[UE%d] Initial sync failed : Estimated power: %d dB\n", ue->Mod_id, ue->measurements.rx_power_avg_dB[0]); LOG_I(PHY, "[UE%d] Initial sync failed : Estimated power: %d dB\n", ue->Mod_id, ue->measurements.rx_power_avg_dB[0]);
#endif #endif
} else { } else {
LOG_A(PHY, "Initial sync successful, PCI: %d\n",fp->Nid_cell); LOG_A(PHY, "Initial sync successful, PCI: %d\n", fp->Nid_cell);
} }
// exit_fun("debug exit"); // exit_fun("debug exit");
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC, VCD_FUNCTION_OUT); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC, VCD_FUNCTION_OUT);
return res.syncRes; if (res)
return res->syncRes;
else
return (nr_initial_sync_t){.cell_detected = false};
} }