From ea07f695adc2d7e4c3d8c46500ddf63a9e4dfb9f Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 18:07:39 +0100 Subject: [PATCH 1/6] Removed printf --- lib/src/phy/phch/prach.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/src/phy/phch/prach.c b/lib/src/phy/phch/prach.c index 74356417a..f6d9b31d9 100644 --- a/lib/src/phy/phch/prach.c +++ b/lib/src/phy/phch/prach.c @@ -316,9 +316,6 @@ int srslte_prach_gen_seqs(srslte_prach_t *p) { } else { C_v = v * p->N_cs; } - if (i == 46) { - printf("i=%d, C_v=%d\n", i, C_v); - } for (int j = 0; j < p->N_zc; j++) { p->seqs[i][j] = root[(j + C_v) % p->N_zc]; } From 230364a6046bd3b2fbc1d8d88442e2fa4df560a3 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 00:05:52 +0100 Subject: [PATCH 2/6] Defaut in-sync for neighbour cell to true --- srsue/hdr/upper/rrc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsue/hdr/upper/rrc.h b/srsue/hdr/upper/rrc.h index 4ac2dfa2f..1aaf6f29b 100644 --- a/srsue/hdr/upper/rrc.h +++ b/srsue/hdr/upper/rrc.h @@ -87,7 +87,7 @@ class cell_t this->phy_cell = phy_cell; this->rsrp = rsrp; this->earfcn = earfcn; - in_sync = false; + in_sync = true; bzero(&sib1, sizeof(sib1)); bzero(&sib2, sizeof(sib2)); bzero(&sib3, sizeof(sib3)); From c78a6e4c0ddb5189b17c08a18591f4ac9450c826 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 00:47:08 +0100 Subject: [PATCH 3/6] Changed SSS algorithm --- lib/src/phy/sync/sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/phy/sync/sync.c b/lib/src/phy/sync/sync.c index a49311fea..c948a53d4 100644 --- a/lib/src/phy/sync/sync.c +++ b/lib/src/phy/sync/sync.c @@ -71,7 +71,7 @@ int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_o q->N_id_1 = 1000; q->cfo_ema_alpha = CFO_EMA_ALPHA; - q->sss_alg = SSS_PARTIAL_3; + q->sss_alg = SSS_FULL; q->detect_cp = true; q->sss_en = true; From fd1e22a7103a04e2b2be4d2873d658e6d49a224d Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 00:47:22 +0100 Subject: [PATCH 4/6] Fixed Measure neighbour exiting too early --- srsue/src/phy/phch_recv.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index c46316af9..c8f804031 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -1169,6 +1169,9 @@ phch_recv::measure::ret_code phch_recv::measure::run_multiple_subframes(cf_t *in return ret; } } + if (ret != ERROR) { + return MEASURE_OK; + } } else { Info("INTRA: not running because offset=%d, sf_len*max_sf=%d*%d\n", offset, sf_len, max_sf); } @@ -1261,13 +1264,11 @@ void phch_recv::scell_recv::init(srslte::log *log_h, bool sic_pss_enabled, uint3 srslte_sync_set_cfo_i_enable(&sync_find, false); srslte_sync_set_cfo_pss_enable(&sync_find, true); srslte_sync_set_pss_filt_enable(&sync_find, true); - srslte_sync_set_sss_eq_enable(&sync_find, false); + srslte_sync_set_sss_eq_enable(&sync_find, true); sync_find.pss.chest_on_filter = true; - if (!sic_pss_enabled) { - sync_find.sss_channel_equalize = false; - } + sync_find.sss_channel_equalize = true; reset(); } @@ -1308,13 +1309,12 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, if (n_id_2 != (cell.id%3) || sic_pss_enabled) { srslte_sync_set_N_id_2(&sync_find, n_id_2); - srslte_sync_find_ret_t sync_res, best_sync_res; + srslte_sync_find_ret_t sync_res; do { srslte_sync_reset(&sync_find); srslte_sync_cfo_reset(&sync_find); - best_sync_res = SRSLTE_SYNC_NOFOUND; sync_res = SRSLTE_SYNC_NOFOUND; cell_id = 0; float max_peak = -1; @@ -1327,14 +1327,13 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, n_id_2, sf5_cnt, nof_sf/5, sync_res, srslte_sync_get_sf_idx(&sync_find), peak_idx, sync_find.peak_value); if (sync_find.peak_value > max_peak && sync_res == SRSLTE_SYNC_FOUND) { - best_sync_res = sync_res; max_sf5 = sf5_cnt; max_sf_idx = srslte_sync_get_sf_idx(&sync_find); cell_id = srslte_sync_get_cell_id(&sync_find); } } - switch(best_sync_res) { + switch(sync_res) { case SRSLTE_SYNC_ERROR: return SRSLTE_ERROR; fprintf(stderr, "Error finding correlation peak\n"); From 70dfa3b2a971785995a52157d05e99e63c81ade4 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 15:06:22 +0100 Subject: [PATCH 5/6] Fixes #6 AGC --- lib/include/srslte/phy/agc/agc.h | 4 ++-- lib/src/phy/agc/agc.c | 2 +- lib/src/phy/ue/ue_sync.c | 14 +++----------- srsue/hdr/phy/phch_recv.h | 1 + srsue/src/phy/phch_recv.cc | 24 ++++++++++++++++++------ srsue/src/phy/phch_worker.cc | 2 +- srsue/src/ue.cc | 11 ++++++----- srsue/src/upper/rrc.cc | 1 + 8 files changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/include/srslte/phy/agc/agc.h b/lib/include/srslte/phy/agc/agc.h index 941983806..0a6bba8c1 100644 --- a/lib/include/srslte/phy/agc/agc.h +++ b/lib/include/srslte/phy/agc/agc.h @@ -42,8 +42,8 @@ #include "srslte/config.h" -#define SRSLTE_AGC_DEFAULT_TARGET 0.7 -#define SRSLTE_AGC_DEFAULT_BW (5e-1) +#define SRSLTE_AGC_DEFAULT_TARGET 0.3 +#define SRSLTE_AGC_DEFAULT_BW 0.7 typedef enum SRSLTE_API { SRSLTE_AGC_MODE_ENERGY = 0, diff --git a/lib/src/phy/agc/agc.c b/lib/src/phy/agc/agc.c index 42a6ef09d..ef09307c1 100644 --- a/lib/src/phy/agc/agc.c +++ b/lib/src/phy/agc/agc.c @@ -177,7 +177,7 @@ void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) { gg = expf(-0.5*q->bandwidth*logf(q->y_out/q->target)); q->gain *= gg; } - DEBUG("AGC gain: %.2f (%.2f) y_out=%.3f, y=%.3f target=%.1f gg=%.2f\n", gain_db, gain_uhd_db, q->y_out, y, q->target, gg); + INFO("AGC gain: %.2f (%.2f) y_out=%.3f, y=%.3f target=%.1f gg=%.2f\n", gain_db, gain_uhd_db, q->y_out, y, q->target, gg); } } } diff --git a/lib/src/phy/ue/ue_sync.c b/lib/src/phy/ue/ue_sync.c index 7ee97c21b..d99bff89a 100644 --- a/lib/src/phy/ue/ue_sync.c +++ b/lib/src/phy/ue/ue_sync.c @@ -144,18 +144,11 @@ void srslte_ue_sync_reset(srslte_ue_sync_t *q) { int srslte_ue_sync_start_agc(srslte_ue_sync_t *q, double (set_gain_callback)(void*, double), float init_gain_value) { - uint32_t nframes; - if (q->nof_recv_sf == 1) { - nframes = 10; - } else { - nframes = 0; - } - int n = srslte_agc_init_uhd(&q->agc, SRSLTE_AGC_MODE_PEAK_AMPLITUDE, nframes, set_gain_callback, q->stream); + int n = srslte_agc_init_uhd(&q->agc, SRSLTE_AGC_MODE_PEAK_AMPLITUDE, 0, set_gain_callback, q->stream); q->do_agc = n==0?true:false; if (q->do_agc) { srslte_agc_set_gain(&q->agc, init_gain_value); - srslte_agc_set_target(&q->agc, 0.3); - srslte_agc_set_bandwidth(&q->agc, 0.8); + srslte_ue_sync_set_agc_period(q, 4); } return n; } @@ -329,7 +322,6 @@ int srslte_ue_sync_set_cell(srslte_ue_sync_t *q, srslte_cell_t cell) memcpy(&q->cell, &cell, sizeof(srslte_cell_t)); q->fft_size = srslte_symbol_sz(q->cell.nof_prb); q->sf_len = SRSLTE_SF_LEN(q->fft_size); - q->agc_period = 0; if (cell.id == 1000) { @@ -789,7 +781,7 @@ int srslte_ue_sync_zerocopy_multi(srslte_ue_sync_t *q, cf_t *input_buffer[SRSLTE if (q->do_agc && (q->agc_period == 0 || (q->agc_period && (q->frame_total_cnt%q->agc_period) == 0))) { - srslte_agc_process(&q->agc, input_buffer[0], q->sf_len); + srslte_agc_process(&q->agc, input_buffer[0], q->sf_len); } /* Track PSS/SSS around the expected PSS position diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index efe46d63e..66c3342fb 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -125,6 +125,7 @@ private: float get_last_gain(); float get_last_cfo(); void set_N_id_2(int N_id_2); + void set_agc_enable(bool enable); ret_code run(srslte_cell_t *cell); private: diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index c8f804031..bf09f5f34 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -174,6 +174,16 @@ bool phch_recv::wait_radio_reset() { void phch_recv::set_agc_enable(bool enable) { do_agc = enable; + if (do_agc) { + if (running && radio_h) { + srslte_ue_sync_start_agc(&ue_sync, callback_set_rx_gain, radio_h->get_rx_gain()); + search_p.set_agc_enable(true); + } else { + fprintf(stderr, "Error setting AGC: PHY not initiatec\n"); + } + } else { + fprintf(stderr, "Error stopping AGC: not implemented\n"); + } } void phch_recv::set_time_adv_sec(float _time_adv_sec) @@ -832,6 +842,14 @@ float phch_recv::search::get_last_cfo() return srslte_ue_sync_get_cfo(&ue_mib_sync.ue_sync); } +void phch_recv::search::set_agc_enable(bool enable) { + if (enable) { + srslte_ue_sync_start_agc(&ue_mib_sync.ue_sync, callback_set_rx_gain, p->radio_h->get_rx_gain()); + } else { + fprintf(stderr, "Error stop AGC not implemented\n"); + } +} + phch_recv::search::ret_code phch_recv::search::run(srslte_cell_t *cell) { @@ -891,11 +909,6 @@ phch_recv::search::ret_code phch_recv::search::run(srslte_cell_t *cell) // Set options defined in expert section p->set_ue_sync_opts(&ue_mib_sync.ue_sync, cfo); - // Start AGC after initial cell search - if (p->do_agc) { - srslte_ue_sync_start_agc(&ue_mib_sync.ue_sync, callback_set_rx_gain, p->radio_h->get_rx_gain()); - } - srslte_ue_sync_reset(&ue_mib_sync.ue_sync); /* Find and decode MIB */ @@ -1011,7 +1024,6 @@ phch_recv::sfn_sync::ret_code phch_recv::sfn_sync::run_subframe(srslte_cell_t *c Info("SYNC: DONE, TTI=%d, sfn_offset=%d\n", *tti_cnt, sfn_offset); } - srslte_ue_sync_set_agc_period(ue_sync, 20); srslte_ue_sync_decode_sss_on_track(ue_sync, true); reset(); return SFN_FOUND; diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index f7e1381f8..a4e6eeb47 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -1436,7 +1436,7 @@ void phch_worker::update_measurements() dl_metrics.rsrp = phy->avg_rsrp_dbm; dl_metrics.rsrq = phy->avg_rsrq_db; dl_metrics.rssi = phy->avg_rssi_dbm; - dl_metrics.pathloss = phy->pathloss; + dl_metrics.pathloss = phy->get_radio()->get_rx_gain(); dl_metrics.sinr = phy->avg_snr_db; dl_metrics.turbo_iters = srslte_pdsch_last_noi(&ue_dl.pdsch); phy->set_dl_metrics(dl_metrics); diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index a9277e62c..611bac620 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -130,11 +130,7 @@ bool ue::init(all_args_t *args_) // Init layers - if (args->rf.rx_gain < 0) { - phy.set_agc_enable(true); - } - - // PHY initis in background, start before radio + // PHY inits in background, start before radio args->expert.phy.nof_rx_ant = args->rf.nof_rx_ant; phy.init(&radio, &mac, &rrc, phy_log, &args->expert.phy); @@ -222,6 +218,11 @@ bool ue::init(all_args_t *args_) phy.wait_initialize(); phy.configure_ul_params(); + // Enable AGC once PHY is initialized + if (args->rf.rx_gain < 0) { + phy.set_agc_enable(true); + } + printf("...\n"); nas.attach_request(); diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index f2e410e5d..f93401fc5 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -1062,6 +1062,7 @@ bool rrc::ho_prepare() { int target_cell_idx = find_neighbour_cell(serving_cell->earfcn, mob_reconf.mob_ctrl_info.target_pci); if (target_cell_idx < 0) { + rrc_log->console("Received HO command to unknown PCI=%d\n", mob_reconf.mob_ctrl_info.target_pci); rrc_log->error("Could not find target cell earfcn=%d, pci=%d\n", serving_cell->earfcn, mob_reconf.mob_ctrl_info.target_pci); return false; } From 411711951079a8165f5a7cfe8c4fcd8492258f7f Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 18:17:15 +0100 Subject: [PATCH 6/6] Correct a possible sign overflow --- lib/src/phy/phch/prach.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/phy/phch/prach.c b/lib/src/phy/phch/prach.c index f6d9b31d9..b5d51ba0b 100644 --- a/lib/src/phy/phch/prach.c +++ b/lib/src/phy/phch/prach.c @@ -282,9 +282,11 @@ int srslte_prach_gen_seqs(srslte_prach_t *p) { N_shift = (p->N_zc - 2 * d_u) / p->N_cs; d_start = p->N_zc - 2 * d_u + N_shift * p->N_cs; N_group = d_u / d_start; - N_neg_shift = (d_u - N_group * d_start) / p->N_cs; - if (N_neg_shift < 0) + if (d_u > N_group * d_start) { + N_neg_shift = (d_u - N_group * d_start) / p->N_cs; + } else { N_neg_shift = 0; + } if (N_neg_shift > N_shift) N_neg_shift = N_shift; } else {