From 04188d818acdfd78b7c524a5a9ee89128fa15093 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 31 Jan 2018 15:34:01 +0100 Subject: [PATCH 01/74] disable neighbour cell measurement --- srsue/src/phy/phch_recv.cc | 5 ++++- srsue/src/phy/phch_worker.cc | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 7d89892c9..c9982b03e 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -1462,6 +1462,7 @@ void phch_recv::intra_measure::rem_cell(int pci) { } void phch_recv::intra_measure::write(uint32_t tti, cf_t *data, uint32_t nsamples) { + /* if (receive_enabled) { if ((tti%INTRA_FREQ_MEAS_PERIOD_MS) == 0) { receiving = true; @@ -1482,6 +1483,7 @@ void phch_recv::intra_measure::write(uint32_t tti, cf_t *data, uint32_t nsamples } } } + */ } void phch_recv::intra_measure::run_thread() @@ -1493,13 +1495,14 @@ void phch_recv::intra_measure::run_thread() if (running) { // Read 15 ms data from buffer + /* srslte_ringbuffer_read(&ring_buffer, search_buffer, CAPTURE_LEN_SF*current_sflen*sizeof(cf_t)); int found_cells = scell.find_cells(search_buffer, common->rx_gain_offset, primary_cell, CAPTURE_LEN_SF, info); receiving = false; for (int i=0;inew_phy_meas(info[i].rsrp, info[i].rsrq, measure_tti, current_earfcn, info[i].pci); - } + }*/ // Look for other cells not found automatically } } diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 1569b0860..58da457f1 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -1388,7 +1388,7 @@ void phch_worker::update_measurements() phy->avg_rsrp_dbm = SRSLTE_VEC_EMA(rsrp_dbm, phy->avg_rsrp_dbm, snr_ema_coeff); } if ((tti%phy->pcell_report_period) == 0 && phy->pcell_meas_enabled) { - phy->rrc->new_phy_meas(phy->avg_rsrp_dbm, phy->avg_rsrq_db, tti); + //phy->rrc->new_phy_meas(phy->avg_rsrp_dbm, phy->avg_rsrq_db, tti); } } From 19129cf152313d2fd1a81fc4bd779323a68008ea Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 2 Feb 2018 20:07:58 +0100 Subject: [PATCH 02/74] Test change SSS to Full --- lib/src/phy/sync/sync.c | 2 +- srsue/src/phy/phch_recv.cc | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) 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; diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 0449aaf9d..6480f8e7b 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -1326,8 +1326,9 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, for (uint32_t sf5_cnt=0;sf5_cnt max_peak && sync_res == SRSLTE_SYNC_FOUND) { best_sync_res = sync_res; From 8f206eb438d625a5edb27c499f4b71c2e7fca075 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 2 Feb 2018 20:17:58 +0100 Subject: [PATCH 03/74] Fixed PRACH preamble when non-contention based RA --- srsue/src/mac/proc_ra.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsue/src/mac/proc_ra.cc b/srsue/src/mac/proc_ra.cc index d9a3e0d4d..f513324e9 100644 --- a/srsue/src/mac/proc_ra.cc +++ b/srsue/src/mac/proc_ra.cc @@ -222,7 +222,7 @@ void ra_proc::step_resource_selection() { if (preambleIndex > 0) { // Preamble is chosen by Higher layers (ie Network) sel_maskIndex = maskIndex; - sel_preamble = (uint32_t) preambleIndex%nof_preambles; + sel_preamble = (uint32_t) preambleIndex; } else { // Preamble is chosen by MAC UE if (!msg3_transmitted) { From 013c39abff24622de9955af05ea2fa976db6b318 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 2 Feb 2018 20:21:38 +0100 Subject: [PATCH 04/74] Revert "Test change SSS to Full" This reverts commit 19129cf152313d2fd1a81fc4bd779323a68008ea. --- lib/src/phy/sync/sync.c | 2 +- srsue/src/phy/phch_recv.cc | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/src/phy/sync/sync.c b/lib/src/phy/sync/sync.c index c948a53d4..a49311fea 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_FULL; + q->sss_alg = SSS_PARTIAL_3; q->detect_cp = true; q->sss_en = true; diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 6480f8e7b..0449aaf9d 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -1326,9 +1326,8 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, for (uint32_t sf5_cnt=0;sf5_cnt max_peak && sync_res == SRSLTE_SYNC_FOUND) { best_sync_res = sync_res; From 6ca74929a23f2a3adda221b029cd28412f5b5947 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 2 Feb 2018 20:23:55 +0100 Subject: [PATCH 05/74] Revert "Fixed PRACH preamble when non-contention based RA" This reverts commit 8f206eb438d625a5edb27c499f4b71c2e7fca075. --- srsue/src/mac/proc_ra.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsue/src/mac/proc_ra.cc b/srsue/src/mac/proc_ra.cc index f513324e9..d9a3e0d4d 100644 --- a/srsue/src/mac/proc_ra.cc +++ b/srsue/src/mac/proc_ra.cc @@ -222,7 +222,7 @@ void ra_proc::step_resource_selection() { if (preambleIndex > 0) { // Preamble is chosen by Higher layers (ie Network) sel_maskIndex = maskIndex; - sel_preamble = (uint32_t) preambleIndex; + sel_preamble = (uint32_t) preambleIndex%nof_preambles; } else { // Preamble is chosen by MAC UE if (!msg3_transmitted) { From ee12051b33ddee2f9fa9c78cf88f09d741f569b0 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 9 Feb 2018 17:56:50 +0100 Subject: [PATCH 06/74] Removed unused options in ue.conf. Fixes #143 --- srsue/ue.conf.example | 8 -------- 1 file changed, 8 deletions(-) diff --git a/srsue/ue.conf.example b/srsue/ue.conf.example index 83bd8c67a..2b8da9643 100644 --- a/srsue/ue.conf.example +++ b/srsue/ue.conf.example @@ -101,19 +101,11 @@ imei = 353490069873319 ##################################################################### # RRC configuration # -# stimsi_attach: If enabled, always tries first an S-TMSI attach using the -# S-TMSI value stored in .stimsi file generated in previous run -# mmec_value: If defined (non-zero), overwrites the value stored in .stimsi file -# m_tmsi_value: If defined (non-zero), overwrites the value stored in .stimsi file -# # ue_category: Sets UE category (range 1-5). Default: 4 # feature_group: Hex value of the featureGroupIndicators field in the # UECapabilityInformation message. Default 0xe6041c00 ##################################################################### [rrc] -#stmsi_attach = false -#mmec_value = 0 -#mtmsi_value = 0 #ue_category = 4 #feature_group = 0xe6041c00 From ccfb9314bc0f248204963d10e60005fed5e46e46 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Sun, 11 Feb 2018 10:59:56 +0100 Subject: [PATCH 07/74] fix various coverity bugs --- lib/src/common/logger_file.cc | 2 +- lib/src/phy/utils/ringbuffer.c | 2 ++ lib/src/upper/rlc_am.cc | 2 +- lib/test/upper/rlc_am_stress_test.cc | 1 + srsue/hdr/upper/rrc.h | 12 +++++++++--- srsue/src/upper/rrc.cc | 8 ++++++++ 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/src/common/logger_file.cc b/lib/src/common/logger_file.cc index f7532fdd1..25155da08 100644 --- a/lib/src/common/logger_file.cc +++ b/lib/src/common/logger_file.cc @@ -54,7 +54,7 @@ void logger_file::init(std::string file, int max_length_) { pthread_mutex_init(&mutex, NULL); pthread_cond_init(¬_empty, NULL); pthread_cond_init(¬_full, NULL); - max_length = max_length_*1024; + max_length = (int64_t)max_length_*1024; name_idx = 0; filename = file; logfile = fopen(filename.c_str(), "w"); diff --git a/lib/src/phy/utils/ringbuffer.c b/lib/src/phy/utils/ringbuffer.c index d5f99fd87..8f0c3edf2 100644 --- a/lib/src/phy/utils/ringbuffer.c +++ b/lib/src/phy/utils/ringbuffer.c @@ -54,6 +54,7 @@ int srslte_ringbuffer_write(srslte_ringbuffer_t *q, void *p, int nof_bytes) int w_bytes = nof_bytes; pthread_mutex_lock(&q->mutex); if (!q->active) { + pthread_mutex_unlock(&q->mutex); return 0; } if (q->count + w_bytes > q->capacity) { @@ -85,6 +86,7 @@ int srslte_ringbuffer_read(srslte_ringbuffer_t *q, void *p, int nof_bytes) pthread_cond_wait(&q->cvar, &q->mutex); } if (!q->active) { + pthread_mutex_unlock(&q->mutex); return 0; } if (nof_bytes + q->rpm > q->capacity) { diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 2c8b1fbfc..e4a6242fa 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -1085,11 +1085,11 @@ void rlc_am::handle_control_pdu(uint8_t *payload, uint32_t nof_bytes) it = tx_window.find(i); if (it != tx_window.end()) { if(update_vt_a) { - tx_window.erase(it); if(it->second.buf) { pool->deallocate(it->second.buf); it->second.buf = 0; } + tx_window.erase(it); vt_a = (vt_a + 1)%MOD; vt_ms = (vt_ms + 1)%MOD; } diff --git a/lib/test/upper/rlc_am_stress_test.cc b/lib/test/upper/rlc_am_stress_test.cc index d6fb0882d..548feb818 100644 --- a/lib/test/upper/rlc_am_stress_test.cc +++ b/lib/test/upper/rlc_am_stress_test.cc @@ -47,6 +47,7 @@ public: rlc2 = rlc2_; fail_rate = fail_rate_; run_enable = true; + running = false; } void stop() diff --git a/srsue/hdr/upper/rrc.h b/srsue/hdr/upper/rrc.h index 27764bd02..4ac2dfa2f 100644 --- a/srsue/hdr/upper/rrc.h +++ b/srsue/hdr/upper/rrc.h @@ -76,17 +76,22 @@ class cell_t return false; } cell_t() { - this->has_valid_sib1 = false; - this->has_valid_sib2 = false; - this->has_valid_sib3 = false; + srslte_cell_t tmp = {}; + cell_t(tmp, 0, 0); } cell_t(srslte_cell_t phy_cell, uint32_t earfcn, float rsrp) { this->has_valid_sib1 = false; this->has_valid_sib2 = false; this->has_valid_sib3 = false; + this->has_valid_sib13 = false; this->phy_cell = phy_cell; this->rsrp = rsrp; this->earfcn = earfcn; + in_sync = false; + bzero(&sib1, sizeof(sib1)); + bzero(&sib2, sizeof(sib2)); + bzero(&sib3, sizeof(sib3)); + bzero(&sib13, sizeof(sib13)); } uint32_t earfcn; @@ -114,6 +119,7 @@ class rrc { public: rrc(); + ~rrc(); void init(phy_interface_rrc *phy_, mac_interface_rrc *mac_, diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 24ccbb4c0..ad5cf29b2 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -49,12 +49,20 @@ rrc::rrc() :state(RRC_STATE_IDLE) ,drb_up(false) ,sysinfo_index(0) + ,serving_cell(NULL) { n310_cnt = 0; n311_cnt = 0; serving_cell = new cell_t(); } +rrc::~rrc() +{ + if (serving_cell) { + delete(serving_cell); + } +} + static void liblte_rrc_handler(void *ctx, char *str) { rrc *r = (rrc *) ctx; r->liblte_rrc_log(str); From 4222c6b9a09426168769b260e7ea469d250284c3 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Sun, 11 Feb 2018 16:38:04 +0100 Subject: [PATCH 08/74] fix mem leak in log_filter --- lib/src/common/log_filter.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index b498d466c..4d80a8523 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -91,6 +91,7 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, str_ptr s_ptr(new std::string(ss.str())); logger_h->log(s_ptr); + delete(s_ptr); } } @@ -131,6 +132,7 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, } str_ptr s_ptr(new std::string(ss.str())); logger_h->log(s_ptr); + delete s_ptr; } } From 1daf7b04bcd069cd0c069fe036067f85534283da Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Sun, 11 Feb 2018 19:32:07 +0100 Subject: [PATCH 09/74] add copyright header --- srsenb/src/mac/scheduler.cc | 25 +++++++++++++++++++++++++ srsenb/test/mac/scheduler_test.cc | 25 +++++++++++++++++++++++++ srsenb/test/upper/ip_test.cc | 26 ++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/srsenb/src/mac/scheduler.cc b/srsenb/src/mac/scheduler.cc index 1f1a72764..51f161d4a 100644 --- a/srsenb/src/mac/scheduler.cc +++ b/srsenb/src/mac/scheduler.cc @@ -1,3 +1,28 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2017 Software Radio Systems Limited + * + * \section LICENSE + * + * This file is part of srsLTE. + * + * srsUE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsUE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ #include diff --git a/srsenb/test/mac/scheduler_test.cc b/srsenb/test/mac/scheduler_test.cc index e9afd61cb..73dd531b0 100644 --- a/srsenb/test/mac/scheduler_test.cc +++ b/srsenb/test/mac/scheduler_test.cc @@ -1,3 +1,28 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2017 Software Radio Systems Limited + * + * \section LICENSE + * + * This file is part of srsLTE. + * + * srsUE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsUE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ #include diff --git a/srsenb/test/upper/ip_test.cc b/srsenb/test/upper/ip_test.cc index e1edf981b..8052ed4d7 100644 --- a/srsenb/test/upper/ip_test.cc +++ b/srsenb/test/upper/ip_test.cc @@ -1,3 +1,29 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2017 Software Radio Systems Limited + * + * \section LICENSE + * + * This file is part of srsLTE. + * + * srsUE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsUE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ + #include #include #include From ad703d5758137842933e855104bada4fbc8f680d Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Mon, 12 Feb 2018 09:57:37 +0100 Subject: [PATCH 10/74] Add missing include --- srsepc/src/mme/s1ap_nas_transport.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 083201ff6..d4f0702de 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -24,6 +24,7 @@ * */ +#include #include "mme/s1ap.h" #include "mme/s1ap_nas_transport.h" #include "srslte/common/security.h" From 237770fcc29cc9b9455ebbc497167c68dc179812 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Mon, 12 Feb 2018 12:24:04 +0000 Subject: [PATCH 11/74] Update coverity badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1567c7c71..fa4355408 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ srsLTE ======== -[![Coverity Scan Build Status](https://scan.coverity.com/projects/10045/badge.svg)](https://scan.coverity.com/projects/10045) +[![Coverity Scan Build Status](https://scan.coverity.com/projects/4721/badge.svg)](https://scan.coverity.com/projects/4721) srsLTE is a free and open-source LTE software suite developed by SRS (www.softwareradiosystems.com). From 59e425608fea666c3d35e0b4c7aeafa2848e6506 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Mon, 12 Feb 2018 12:44:55 +0000 Subject: [PATCH 12/74] Better fix for buffer size issue --- lib/src/upper/rlc_am.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index e4a6242fa..26f42af84 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -587,7 +587,8 @@ int rlc_am::build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t r rrc->get_rb_name(lcid).c_str(), nof_bytes, head_len); return 0; } - pdu_space = nof_bytes-head_len-2; + + pdu_space = nof_bytes-head_len; if(pdu_space < (retx.so_end-retx.so_start)) retx.so_end = retx.so_start+pdu_space; @@ -603,10 +604,13 @@ int rlc_am::build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t r if(lower >= retx.so_end) break; + if(pdu_space <= 2) + break; + upper += old_header.li[i]; head_len = rlc_am_packed_length(&new_header); - pdu_space = nof_bytes-head_len-2; + pdu_space = nof_bytes-head_len; if(pdu_space < (retx.so_end-retx.so_start)) retx.so_end = retx.so_start+pdu_space; From 4cf79c1eadd0ffd24d4cb03d4d8106737971c245 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Mon, 12 Feb 2018 13:09:31 +0000 Subject: [PATCH 13/74] Initial fix for segment handling in RLC AM --- lib/src/upper/rlc_am.cc | 19 +++++++++++++------ lib/test/upper/rlc_am_stress_test.cc | 6 +++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 26f42af84..72fbbde17 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -1221,15 +1221,22 @@ void rlc_am::print_rx_segments() bool rlc_am::add_segment_and_check(rlc_amd_rx_pdu_segments_t *pdu, rlc_amd_rx_pdu_t *segment) { - // Ordered insert - std::list::iterator tmpit; - std::list::iterator it = pdu->segments.begin(); - while(it != pdu->segments.end() && it->header.so < segment->header.so) - it++; - pdu->segments.insert(it, *segment); + // Check segment offset + uint32_t n = 0; + if(!pdu->segments.empty()) { + rlc_amd_rx_pdu_t &back = pdu->segments.back(); + n = back.header.so + back.buf->N_bytes; + } + if(segment->header.so != n) { + pool->deallocate(segment->buf); + return false; + } else { + pdu->segments.push_back(*segment); + } // Check for complete uint32_t so = 0; + std::list::iterator it, tmpit; for(it = pdu->segments.begin(); it != pdu->segments.end(); it++) { if(so != it->header.so) return false; diff --git a/lib/test/upper/rlc_am_stress_test.cc b/lib/test/upper/rlc_am_stress_test.cc index 548feb818..cfed3d6e7 100644 --- a/lib/test/upper/rlc_am_stress_test.cc +++ b/lib/test/upper/rlc_am_stress_test.cc @@ -82,7 +82,7 @@ private: if(((float)rand()/RAND_MAX > fail_rate) && read>0) { rlc2->write_pdu(1, pdu->msg, opp_size); } - usleep(1000); + usleep(100); } running = false; } @@ -187,7 +187,7 @@ private: pdu->N_bytes = 1500; pdu->msg[0] = sn++; rlc->write_sdu(1, pdu); - usleep(1000); + usleep(100); } running = false; } @@ -207,7 +207,7 @@ void stress_test() log1.set_hex_limit(-1); log2.set_hex_limit(-1); - float fail_rate = 0.1; + float fail_rate = 0.01; rlc rlc1; rlc rlc2; From e18cb5ba5ba3d3561d5648f17cc2cd0f5663fcaf Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Mon, 12 Feb 2018 13:42:59 +0000 Subject: [PATCH 14/74] Fixing RLC AM tests, adding extra check for segment handling --- lib/src/upper/rlc_am.cc | 11 +++++++++++ lib/test/upper/rlc_am_stress_test.cc | 12 +++++++++--- lib/test/upper/rlc_am_test.cc | 28 ++++++++++++++-------------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 72fbbde17..59ce25576 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -1221,6 +1221,17 @@ void rlc_am::print_rx_segments() bool rlc_am::add_segment_and_check(rlc_amd_rx_pdu_segments_t *pdu, rlc_amd_rx_pdu_t *segment) { + // Check for first segment + if(0 == segment->header.so) { + std::list::iterator it; + for(it = pdu->segments.begin(); it != pdu->segments.end(); it++) { + pool->deallocate(it->buf); + } + pdu->segments.clear(); + pdu->segments.push_back(*segment); + return false; + } + // Check segment offset uint32_t n = 0; if(!pdu->segments.empty()) { diff --git a/lib/test/upper/rlc_am_stress_test.cc b/lib/test/upper/rlc_am_stress_test.cc index cfed3d6e7..dc1540c96 100644 --- a/lib/test/upper/rlc_am_stress_test.cc +++ b/lib/test/upper/rlc_am_stress_test.cc @@ -139,10 +139,12 @@ class rlc_am_tester ,public thread { public: - rlc_am_tester(rlc_interface_pdcp *rlc_){ + rlc_am_tester(rlc_interface_pdcp *rlc_, std::string name_=""){ rlc = rlc_; run_enable = true; running = false; + rx_pdus = 0; + name = name_; } void stop() @@ -164,6 +166,7 @@ public: { assert(lcid == 1); byte_buffer_pool::get_instance()->deallocate(sdu); + std::cout << "rlc_am_tester " << name << " received " << rx_pdus++ << " PDUs" << std::endl; } void write_pdu_bcch_bch(byte_buffer_t *sdu) {} void write_pdu_bcch_dlsch(byte_buffer_t *sdu) {} @@ -194,6 +197,9 @@ private: bool run_enable; bool running; + long rx_pdus; + + std::string name; rlc_interface_pdcp *rlc; }; @@ -212,8 +218,8 @@ void stress_test() rlc rlc1; rlc rlc2; - rlc_am_tester tester1(&rlc1); - rlc_am_tester tester2(&rlc2); + rlc_am_tester tester1(&rlc1, "tester1"); + rlc_am_tester tester2(&rlc2, "tester2"); mac_dummy mac(&rlc1, &rlc2, fail_rate); ue_interface ue; diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index fbd013e3b..0b8c63668 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -482,17 +482,17 @@ void resegment_test_1() // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; - len = rlc1.read_pdu(retx1.msg, 11); // 4 byte header + 5 data + len = rlc1.read_pdu(retx1.msg, 9); // 4 byte header + 5 data retx1.N_bytes = len; // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); - assert(9 == rlc1.get_buffer_state()); // 4 byte header + 5 data + assert(9 == rlc1.get_buffer_state()); // Read the remaining segment byte_buffer_t retx2; - len = rlc1.read_pdu(retx2.msg, 11); // 4 byte header + 5 data + len = rlc1.read_pdu(retx2.msg, 9); // 4 byte header + 5 data retx2.N_bytes = len; // Write the retx PDU to RLC2 @@ -591,16 +591,16 @@ void resegment_test_2() // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; - retx1.N_bytes = rlc1.read_pdu(retx1.msg, 18); // 6 byte header + 10 data + retx1.N_bytes = rlc1.read_pdu(retx1.msg, 16); // 6 byte header + 10 data // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); - assert(16 == rlc1.get_buffer_state()); // 6 byte header + 10 data + assert(16 == rlc1.get_buffer_state()); // Read the remaining segment byte_buffer_t retx2; - retx2.N_bytes = rlc1.read_pdu(retx2.msg, 18); // 6 byte header + 10 data + retx2.N_bytes = rlc1.read_pdu(retx2.msg, 16); // 6 byte header + 10 data // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); @@ -696,14 +696,14 @@ void resegment_test_3() // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; - retx1.N_bytes = rlc1.read_pdu(retx1.msg, 16); // 4 byte header + 10 data + retx1.N_bytes = rlc1.read_pdu(retx1.msg, 14); // 4 byte header + 10 data // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); // Read the remaining segment byte_buffer_t retx2; - retx2.N_bytes = rlc1.read_pdu(retx2.msg, 16); // 4 byte header + 10 data + retx2.N_bytes = rlc1.read_pdu(retx2.msg, 14); // 4 byte header + 10 data // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); @@ -799,14 +799,14 @@ void resegment_test_4() // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; - retx1.N_bytes = rlc1.read_pdu(retx1.msg, 23); // 6 byte header + 15 data + retx1.N_bytes = rlc1.read_pdu(retx1.msg, 21); // 6 byte header + 15 data // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); // Read the remaining segment byte_buffer_t retx2; - retx2.N_bytes = rlc1.read_pdu(retx2.msg, 23); // 6 byte header + 15 data + retx2.N_bytes = rlc1.read_pdu(retx2.msg, 21); // 6 byte header + 15 data // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); @@ -902,14 +902,14 @@ void resegment_test_5() // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; - retx1.N_bytes = rlc1.read_pdu(retx1.msg, 29); // 7 byte header + 20 data + retx1.N_bytes = rlc1.read_pdu(retx1.msg, 27); // 7 byte header + 20 data // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); // Read the remaining segment byte_buffer_t retx2; - retx2.N_bytes = rlc1.read_pdu(retx2.msg, 29); // 7 byte header + 20 data + retx2.N_bytes = rlc1.read_pdu(retx2.msg, 27); // 7 byte header + 20 data // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); @@ -1023,11 +1023,11 @@ void resegment_test_6() // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); - assert(157 == rlc1.get_buffer_state()); + assert(155 == rlc1.get_buffer_state()); // Read the remaining segment byte_buffer_t retx2; - len = rlc1.read_pdu(retx2.msg, 159); + len = rlc1.read_pdu(retx2.msg, 157); retx2.N_bytes = len; // Write the retx PDU to RLC2 From 2734ce6600ea1da68c343d10c700cd4b16f01e1e Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Mon, 12 Feb 2018 15:33:57 +0000 Subject: [PATCH 15/74] Revert coverity badge change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa4355408..1567c7c71 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ srsLTE ======== -[![Coverity Scan Build Status](https://scan.coverity.com/projects/4721/badge.svg)](https://scan.coverity.com/projects/4721) +[![Coverity Scan Build Status](https://scan.coverity.com/projects/10045/badge.svg)](https://scan.coverity.com/projects/10045) srsLTE is a free and open-source LTE software suite developed by SRS (www.softwareradiosystems.com). From 913be7b29005cc35f7ad8294233bd6a764753609 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Mon, 12 Feb 2018 17:28:46 +0100 Subject: [PATCH 16/74] Fix sensor calibration on sync measure --- srsue/src/phy/phch_recv.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 6c7a8c1ea..c46316af9 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -1216,9 +1216,6 @@ phch_recv::measure::ret_code phch_recv::measure::run_subframe(uint32_t sf_idx) } mean_rsrp -= temporal_offset; } - } - - if (cnt > 2) { return MEASURE_OK; } else { return IDLE; From 81d8e7f70da56600b950ba4c5bf445b5ff8df738 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Mon, 12 Feb 2018 17:17:27 +0000 Subject: [PATCH 17/74] Fix memory leak --- lib/src/upper/rlc_am.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 59ce25576..413a02ac1 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -1309,6 +1309,7 @@ bool rlc_am::add_segment_and_check(rlc_amd_rx_pdu_segments_t *pdu, rlc_amd_rx_pd } handle_data_pdu(full_pdu->msg, full_pdu->N_bytes, header); + pool->deallocate(full_pdu); return true; } From bf0ff783e909ff06f16937af03254f59bb44c9cf Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Mon, 12 Feb 2018 18:24:31 +0100 Subject: [PATCH 18/74] Fixed Msg3 HARQ retx when HO --- srsue/src/upper/rrc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index ad5cf29b2..f2e410e5d 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -1770,9 +1770,9 @@ void rrc::apply_rr_config_common_dl(LIBLTE_RRC_RR_CONFIG_COMMON_STRUCT *config) mac->get_config(&mac_cfg); if (config->rach_cnfg_present) { memcpy(&mac_cfg.rach, &config->rach_cnfg, sizeof(LIBLTE_RRC_RACH_CONFIG_COMMON_STRUCT)); + mac_cfg.ul_harq_params.max_harq_msg3_tx = config->rach_cnfg.max_harq_msg3_tx; } mac_cfg.prach_config_index = config->prach_cnfg.root_sequence_index; - mac_cfg.ul_harq_params.max_harq_msg3_tx = config->rach_cnfg.max_harq_msg3_tx; mac->set_config(&mac_cfg); From a1f9b35db32da4a8df52710ec50fc85c33a647b2 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Mon, 12 Feb 2018 17:24:48 +0000 Subject: [PATCH 19/74] Minor rlc_am_stress_test fix --- lib/test/upper/rlc_am_stress_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/test/upper/rlc_am_stress_test.cc b/lib/test/upper/rlc_am_stress_test.cc index dc1540c96..086a41bd8 100644 --- a/lib/test/upper/rlc_am_stress_test.cc +++ b/lib/test/upper/rlc_am_stress_test.cc @@ -213,7 +213,7 @@ void stress_test() log1.set_hex_limit(-1); log2.set_hex_limit(-1); - float fail_rate = 0.01; + float fail_rate = 0.1; rlc rlc1; rlc rlc2; @@ -224,7 +224,7 @@ void stress_test() ue_interface ue; rlc1.init(&tester1, &tester1, &ue, &log1, &mac, 0); - rlc2.init(&tester1, &tester1, &ue, &log2, &mac, 0); + rlc2.init(&tester2, &tester2, &ue, &log2, &mac, 0); LIBLTE_RRC_RLC_CONFIG_STRUCT cnfg; cnfg.rlc_mode = LIBLTE_RRC_RLC_MODE_AM; @@ -241,7 +241,7 @@ void stress_test() rlc2.add_bearer(1, cnfg_); tester1.start(7); - //tester2.start(7); + tester2.start(7); mac.start(); usleep(100e6); From 6f80144fbe3f873e86d9196db076e52fec71afec Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Mon, 12 Feb 2018 19:23:57 +0100 Subject: [PATCH 20/74] Revert "fix mem leak in log_filter" This reverts commit 4222c6b9a09426168769b260e7ea469d250284c3. --- lib/src/common/log_filter.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index 4d80a8523..b498d466c 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -91,7 +91,6 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, str_ptr s_ptr(new std::string(ss.str())); logger_h->log(s_ptr); - delete(s_ptr); } } @@ -132,7 +131,6 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, } str_ptr s_ptr(new std::string(ss.str())); logger_h->log(s_ptr); - delete s_ptr; } } From 4e1d2cdf05133832be551f3eb0defb9014353d0a Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 00:05:52 +0100 Subject: [PATCH 21/74] 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 45629d4c8641d0f611baa0164ffc76981852868a Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 00:47:08 +0100 Subject: [PATCH 22/74] 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 21edf74b06aa40b56f45d35b46343f9b26f99e43 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 00:47:22 +0100 Subject: [PATCH 23/74] 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 2cf6f96f241c6e531310ad4bf7e4999be3896a74 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 15:06:22 +0100 Subject: [PATCH 24/74] 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 a568db3b04c11d43deebf7a705b46bf6a7cc31a4 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 18:03:44 +0100 Subject: [PATCH 25/74] Fixed PRACH HS=TRUE bug and indentation --- lib/src/phy/phch/prach.c | 613 +++++++++++++++++++-------------------- 1 file changed, 298 insertions(+), 315 deletions(-) diff --git a/lib/src/phy/phch/prach.c b/lib/src/phy/phch/prach.c index ffd8b51e7..74356417a 100644 --- a/lib/src/phy/phch/prach.c +++ b/lib/src/phy/phch/prach.c @@ -57,185 +57,177 @@ float save_corr[4096]; uint32_t prach_Tcp[5] = {3168, 21024, 6240, 21024, 448}; // Table 5.7.1-1 T_seq for preamble formats -uint32_t prach_Tseq[5] = {24576, 24576, 2*24576, 2*24576, 4096}; +uint32_t prach_Tseq[5] = {24576, 24576, 2 * 24576, 2 * 24576, 4096}; // Table 5.7.2-2 - N_cs values for unrestricted sets -uint32_t prach_Ncs_unrestricted[16] = {0,13,15,18,22,26,32,38,46,59,76,93,119,167,279,419}; +uint32_t prach_Ncs_unrestricted[16] = {0, 13, 15, 18, 22, 26, 32, 38, 46, 59, 76, 93, 119, 167, 279, 419}; #define MAX_N_zc 839 // Table 5.7.2-2 - N_cs values for restricted sets -uint32_t prach_Ncs_restricted[15] = {15,18,22,26,32,38,46,55,68,82,100,128,158,202,237}; +uint32_t prach_Ncs_restricted[15] = {15, 18, 22, 26, 32, 38, 46, 55, 68, 82, 100, 128, 158, 202, 237}; // Table 5.7.2-3 - N_cs values for preamble format 4 -uint32_t prach_Ncs_format4[7] = {2,4,6,8,10,12,15}; +uint32_t prach_Ncs_format4[7] = {2, 4, 6, 8, 10, 12, 15}; // Table 5.7.2-4 - Root ZC sequence order uint32_t prach_zc_roots[838] = { - 129, 710, 140, 699, 120, 719, 210, 629, 168, 671, 84, 755, - 105, 734, 93, 746, 70, 769, 60, 779, 2, 837, 1, 838, - 56, 783, 112, 727, 148, 691, 80, 759, 42, 797, 40, 799, - 35, 804, 73, 766, 146, 693, 31, 808, 28, 811, 30, 809, - 27, 812, 29, 810, 24, 815, 48, 791, 68, 771, 74, 765, - 178, 661, 136, 703, 86, 753, 78, 761, 43, 796, 39, 800, - 20, 819, 21, 818, 95, 744, 202, 637, 190, 649, 181, 658, - 137, 702, 125, 714, 151, 688, 217, 622, 128, 711, 142, 697, - 122, 717, 203, 636, 118, 721, 110, 729, 89, 750, 103, 736, - 61, 778, 55, 784, 15, 824, 14, 825, 12, 827, 23, 816, - 34, 805, 37, 802, 46, 793, 207, 632, 179, 660, 145, 694, - 130, 709, 223, 616, 228, 611, 227, 612, 132, 707, 133, 706, - 143, 696, 135, 704, 161, 678, 201, 638, 173, 666, 106, 733, - 83, 756, 91, 748, 66, 773, 53, 786, 10, 829, 9, 830, - 7, 832, 8, 831, 16, 823, 47, 792, 64, 775, 57, 782, - 104, 735, 101, 738, 108, 731, 208, 631, 184, 655, 197, 642, - 191, 648, 121, 718, 141, 698, 149, 690, 216, 623, 218, 621, - 152, 687, 144, 695, 134, 705, 138, 701, 199, 640, 162, 677, - 176, 663, 119, 720, 158, 681, 164, 675, 174, 665, 171, 668, - 170, 669, 87, 752, 169, 670, 88, 751, 107, 732, 81, 758, - 82, 757, 100, 739, 98, 741, 71, 768, 59, 780, 65, 774, - 50, 789, 49, 790, 26, 813, 17, 822, 13, 826, 6, 833, - 5, 834, 33, 806, 51, 788, 75, 764, 99, 740, 96, 743, - 97, 742, 166, 673, 172, 667, 175, 664, 187, 652, 163, 676, - 185, 654, 200, 639, 114, 725, 189, 650, 115, 724, 194, 645, - 195, 644, 192, 647, 182, 657, 157, 682, 156, 683, 211, 628, - 154, 685, 123, 716, 139, 700, 212, 627, 153, 686, 213, 626, - 215, 624, 150, 689, 225, 614, 224, 615, 221, 618, 220, 619, - 127, 712, 147, 692, 124, 715, 193, 646, 205, 634, 206, 633, - 116, 723, 160, 679, 186, 653, 167, 672, 79, 760, 85, 754, - 77, 762, 92, 747, 58, 781, 62, 777, 69, 770, 54, 785, - 36, 803, 32, 807, 25, 814, 18, 821, 11, 828, 4, 835, - 3, 836, 19, 820, 22, 817, 41, 798, 38, 801, 44, 795, - 52, 787, 45, 794, 63, 776, 67, 772, 72, 767, 76, 763, - 94, 745, 102, 737, 90, 749, 109, 730, 165, 674, 111, 728, - 209, 630, 204, 635, 117, 722, 188, 651, 159, 680, 198, 641, - 113, 726, 183, 656, 180, 659, 177, 662, 196, 643, 155, 684, - 214, 625, 126, 713, 131, 708, 219, 620, 222, 617, 226, 613, - 230, 609, 232, 607, 262, 577, 252, 587, 418, 421, 416, 423, - 413, 426, 411, 428, 376, 463, 395, 444, 283, 556, 285, 554, - 379, 460, 390, 449, 363, 476, 384, 455, 388, 451, 386, 453, - 361, 478, 387, 452, 360, 479, 310, 529, 354, 485, 328, 511, - 315, 524, 337, 502, 349, 490, 335, 504, 324, 515, 323, 516, - 320, 519, 334, 505, 359, 480, 295, 544, 385, 454, 292, 547, - 291, 548, 381, 458, 399, 440, 380, 459, 397, 442, 369, 470, - 377, 462, 410, 429, 407, 432, 281, 558, 414, 425, 247, 592, - 277, 562, 271, 568, 272, 567, 264, 575, 259, 580, 237, 602, - 239, 600, 244, 595, 243, 596, 275, 564, 278, 561, 250, 589, - 246, 593, 417, 422, 248, 591, 394, 445, 393, 446, 370, 469, - 365, 474, 300, 539, 299, 540, 364, 475, 362, 477, 298, 541, - 312, 527, 313, 526, 314, 525, 353, 486, 352, 487, 343, 496, - 327, 512, 350, 489, 326, 513, 319, 520, 332, 507, 333, 506, - 348, 491, 347, 492, 322, 517, 330, 509, 338, 501, 341, 498, - 340, 499, 342, 497, 301, 538, 366, 473, 401, 438, 371, 468, - 408, 431, 375, 464, 249, 590, 269, 570, 238, 601, 234, 605, - 257, 582, 273, 566, 255, 584, 254, 585, 245, 594, 251, 588, - 412, 427, 372, 467, 282, 557, 403, 436, 396, 443, 392, 447, - 391, 448, 382, 457, 389, 450, 294, 545, 297, 542, 311, 528, - 344, 495, 345, 494, 318, 521, 331, 508, 325, 514, 321, 518, - 346, 493, 339, 500, 351, 488, 306, 533, 289, 550, 400, 439, - 378, 461, 374, 465, 415, 424, 270, 569, 241, 598, 231, 608, - 260, 579, 268, 571, 276, 563, 409, 430, 398, 441, 290, 549, - 304, 535, 308, 531, 358, 481, 316, 523, 293, 546, 288, 551, - 284, 555, 368, 471, 253, 586, 256, 583, 263, 576, 242, 597, - 274, 565, 402, 437, 383, 456, 357, 482, 329, 510, 317, 522, - 307, 532, 286, 553, 287, 552, 266, 573, 261, 578, 236, 603, - 303, 536, 356, 483, 355, 484, 405, 434, 404, 435, 406, 433, - 235, 604, 267, 572, 302, 537, 309, 530, 265, 574, 233, 606, - 367, 472, 296, 543, 336, 503, 305, 534, 373, 466, 280, 559, - 279, 560, 419, 420, 240, 599, 258, 581, 229, 610}; + 129, 710, 140, 699, 120, 719, 210, 629, 168, 671, 84, 755, + 105, 734, 93, 746, 70, 769, 60, 779, 2, 837, 1, 838, + 56, 783, 112, 727, 148, 691, 80, 759, 42, 797, 40, 799, + 35, 804, 73, 766, 146, 693, 31, 808, 28, 811, 30, 809, + 27, 812, 29, 810, 24, 815, 48, 791, 68, 771, 74, 765, + 178, 661, 136, 703, 86, 753, 78, 761, 43, 796, 39, 800, + 20, 819, 21, 818, 95, 744, 202, 637, 190, 649, 181, 658, + 137, 702, 125, 714, 151, 688, 217, 622, 128, 711, 142, 697, + 122, 717, 203, 636, 118, 721, 110, 729, 89, 750, 103, 736, + 61, 778, 55, 784, 15, 824, 14, 825, 12, 827, 23, 816, + 34, 805, 37, 802, 46, 793, 207, 632, 179, 660, 145, 694, + 130, 709, 223, 616, 228, 611, 227, 612, 132, 707, 133, 706, + 143, 696, 135, 704, 161, 678, 201, 638, 173, 666, 106, 733, + 83, 756, 91, 748, 66, 773, 53, 786, 10, 829, 9, 830, + 7, 832, 8, 831, 16, 823, 47, 792, 64, 775, 57, 782, + 104, 735, 101, 738, 108, 731, 208, 631, 184, 655, 197, 642, + 191, 648, 121, 718, 141, 698, 149, 690, 216, 623, 218, 621, + 152, 687, 144, 695, 134, 705, 138, 701, 199, 640, 162, 677, + 176, 663, 119, 720, 158, 681, 164, 675, 174, 665, 171, 668, + 170, 669, 87, 752, 169, 670, 88, 751, 107, 732, 81, 758, + 82, 757, 100, 739, 98, 741, 71, 768, 59, 780, 65, 774, + 50, 789, 49, 790, 26, 813, 17, 822, 13, 826, 6, 833, + 5, 834, 33, 806, 51, 788, 75, 764, 99, 740, 96, 743, + 97, 742, 166, 673, 172, 667, 175, 664, 187, 652, 163, 676, + 185, 654, 200, 639, 114, 725, 189, 650, 115, 724, 194, 645, + 195, 644, 192, 647, 182, 657, 157, 682, 156, 683, 211, 628, + 154, 685, 123, 716, 139, 700, 212, 627, 153, 686, 213, 626, + 215, 624, 150, 689, 225, 614, 224, 615, 221, 618, 220, 619, + 127, 712, 147, 692, 124, 715, 193, 646, 205, 634, 206, 633, + 116, 723, 160, 679, 186, 653, 167, 672, 79, 760, 85, 754, + 77, 762, 92, 747, 58, 781, 62, 777, 69, 770, 54, 785, + 36, 803, 32, 807, 25, 814, 18, 821, 11, 828, 4, 835, + 3, 836, 19, 820, 22, 817, 41, 798, 38, 801, 44, 795, + 52, 787, 45, 794, 63, 776, 67, 772, 72, 767, 76, 763, + 94, 745, 102, 737, 90, 749, 109, 730, 165, 674, 111, 728, + 209, 630, 204, 635, 117, 722, 188, 651, 159, 680, 198, 641, + 113, 726, 183, 656, 180, 659, 177, 662, 196, 643, 155, 684, + 214, 625, 126, 713, 131, 708, 219, 620, 222, 617, 226, 613, + 230, 609, 232, 607, 262, 577, 252, 587, 418, 421, 416, 423, + 413, 426, 411, 428, 376, 463, 395, 444, 283, 556, 285, 554, + 379, 460, 390, 449, 363, 476, 384, 455, 388, 451, 386, 453, + 361, 478, 387, 452, 360, 479, 310, 529, 354, 485, 328, 511, + 315, 524, 337, 502, 349, 490, 335, 504, 324, 515, 323, 516, + 320, 519, 334, 505, 359, 480, 295, 544, 385, 454, 292, 547, + 291, 548, 381, 458, 399, 440, 380, 459, 397, 442, 369, 470, + 377, 462, 410, 429, 407, 432, 281, 558, 414, 425, 247, 592, + 277, 562, 271, 568, 272, 567, 264, 575, 259, 580, 237, 602, + 239, 600, 244, 595, 243, 596, 275, 564, 278, 561, 250, 589, + 246, 593, 417, 422, 248, 591, 394, 445, 393, 446, 370, 469, + 365, 474, 300, 539, 299, 540, 364, 475, 362, 477, 298, 541, + 312, 527, 313, 526, 314, 525, 353, 486, 352, 487, 343, 496, + 327, 512, 350, 489, 326, 513, 319, 520, 332, 507, 333, 506, + 348, 491, 347, 492, 322, 517, 330, 509, 338, 501, 341, 498, + 340, 499, 342, 497, 301, 538, 366, 473, 401, 438, 371, 468, + 408, 431, 375, 464, 249, 590, 269, 570, 238, 601, 234, 605, + 257, 582, 273, 566, 255, 584, 254, 585, 245, 594, 251, 588, + 412, 427, 372, 467, 282, 557, 403, 436, 396, 443, 392, 447, + 391, 448, 382, 457, 389, 450, 294, 545, 297, 542, 311, 528, + 344, 495, 345, 494, 318, 521, 331, 508, 325, 514, 321, 518, + 346, 493, 339, 500, 351, 488, 306, 533, 289, 550, 400, 439, + 378, 461, 374, 465, 415, 424, 270, 569, 241, 598, 231, 608, + 260, 579, 268, 571, 276, 563, 409, 430, 398, 441, 290, 549, + 304, 535, 308, 531, 358, 481, 316, 523, 293, 546, 288, 551, + 284, 555, 368, 471, 253, 586, 256, 583, 263, 576, 242, 597, + 274, 565, 402, 437, 383, 456, 357, 482, 329, 510, 317, 522, + 307, 532, 286, 553, 287, 552, 266, 573, 261, 578, 236, 603, + 303, 536, 356, 483, 355, 484, 405, 434, 404, 435, 406, 433, + 235, 604, 267, 572, 302, 537, 309, 530, 265, 574, 233, 606, + 367, 472, 296, 543, 336, 503, 305, 534, 373, 466, 280, 559, + 279, 560, 419, 420, 240, 599, 258, 581, 229, 610}; // Table 5.7.2-5 - Root ZC sequence order for preamble format 4 uint32_t prach_zc_roots_format4[138] = { - 1, 138, 2, 137, 3, 136, 4, 135, 5, 134, 6, 133, - 7, 132, 8, 131, 9, 130, 10, 129, 11, 128, 12, 127, - 13, 126, 14, 125, 15, 124, 16, 123, 17, 122, 18, 121, - 19, 120, 20, 119, 21, 118, 22, 117, 23, 116, 24, 115, - 25, 114, 26, 113, 27, 112, 28, 111, 29, 110, 30, 109, - 31, 108, 32, 107, 33, 106, 34, 105, 35, 104, 36, 103, - 37, 102, 38, 101, 39, 100, 40, 99, 41, 98, 42, 97, - 43, 96, 44, 95, 45, 94, 46, 93, 47, 92, 48, 91, - 49, 90, 50, 89, 51, 88, 52, 87, 53, 86, 54, 85, - 55, 84, 56, 83, 57, 82, 58, 81, 59, 80, 60, 79, - 61, 78, 62, 77, 63, 76, 64, 75, 65, 74, 66, 73, - 67, 72, 68, 71, 69, 70}; - - + 1, 138, 2, 137, 3, 136, 4, 135, 5, 134, 6, 133, + 7, 132, 8, 131, 9, 130, 10, 129, 11, 128, 12, 127, + 13, 126, 14, 125, 15, 124, 16, 123, 17, 122, 18, 121, + 19, 120, 20, 119, 21, 118, 22, 117, 23, 116, 24, 115, + 25, 114, 26, 113, 27, 112, 28, 111, 29, 110, 30, 109, + 31, 108, 32, 107, 33, 106, 34, 105, 35, 104, 36, 103, + 37, 102, 38, 101, 39, 100, 40, 99, 41, 98, 42, 97, + 43, 96, 44, 95, 45, 94, 46, 93, 47, 92, 48, 91, + 49, 90, 50, 89, 51, 88, 52, 87, 53, 86, 54, 85, + 55, 84, 56, 83, 57, 82, 58, 81, 59, 80, 60, 79, + 61, 78, 62, 77, 63, 76, 64, 75, 65, 74, 66, 73, + 67, 72, 68, 71, 69, 70}; + srslte_prach_sf_config_t prach_sf_config[16] = { - {1, {1, 0, 0, 0, 0}}, - {1, {4, 0, 0, 0, 0}}, - {1, {7, 0, 0, 0, 0}}, - {1, {1, 0, 0, 0, 0}}, - {1, {4, 0, 0, 0, 0}}, - {1, {7, 0, 0, 0, 0}}, - {2, {1, 6, 0, 0, 0}}, - {2, {2, 7, 0, 0, 0}}, - {2, {3, 8, 0, 0, 0}}, - {3, {1, 4, 7, 0, 0}}, - {3, {2, 5, 8, 0, 0}}, - {3, {3, 6, 9, 0, 0}}, - {5, {0, 2, 4, 6, 8}}, - {5, {1, 3, 5, 7, 9}}, - {-1, {0, 0, 0, 0, 0}}, // this means all subframes - {1, {9, 0, 0, 0, 0}}}; + {1, {1, 0, 0, 0, 0}}, + {1, {4, 0, 0, 0, 0}}, + {1, {7, 0, 0, 0, 0}}, + {1, {1, 0, 0, 0, 0}}, + {1, {4, 0, 0, 0, 0}}, + {1, {7, 0, 0, 0, 0}}, + {2, {1, 6, 0, 0, 0}}, + {2, {2, 7, 0, 0, 0}}, + {2, {3, 8, 0, 0, 0}}, + {3, {1, 4, 7, 0, 0}}, + {3, {2, 5, 8, 0, 0}}, + {3, {3, 6, 9, 0, 0}}, + {5, {0, 2, 4, 6, 8}}, + {5, {1, 3, 5, 7, 9}}, + {-1, {0, 0, 0, 0, 0}}, // this means all subframes + {1, {9, 0, 0, 0, 0}}}; uint32_t srslte_prach_get_preamble_format(uint32_t config_idx) { - return config_idx/16; + return config_idx / 16; } srslte_prach_sfn_t srslte_prach_get_sfn(uint32_t config_idx) { - if ((config_idx%16)<3 || (config_idx%16)==15) { + if ((config_idx % 16) < 3 || (config_idx % 16) == 15) { return SRSLTE_PRACH_SFN_EVEN; } else { - return SRSLTE_PRACH_SFN_ANY; + return SRSLTE_PRACH_SFN_ANY; } } /* Returns true if current_tti is a valid opportunity for PRACH transmission and the is an allowed subframe, * or allowed_subframe == -1 */ -bool srslte_prach_tti_opportunity(srslte_prach_t *p, uint32_t current_tti, int allowed_subframe) -{ - uint32_t config_idx = p->config_idx; +bool srslte_prach_tti_opportunity(srslte_prach_t *p, uint32_t current_tti, int allowed_subframe) { + uint32_t config_idx = p->config_idx; // Get SFN and sf_idx from the PRACH configuration index - srslte_prach_sfn_t prach_sfn = srslte_prach_get_sfn(config_idx); + srslte_prach_sfn_t prach_sfn = srslte_prach_get_sfn(config_idx); // This is the only option which provides always an opportunity for PRACH transmission. - if(config_idx == 14) { + if (config_idx == 14) { return true; } - if ((prach_sfn == SRSLTE_PRACH_SFN_EVEN && ((current_tti/10)%2)==0) || - prach_sfn == SRSLTE_PRACH_SFN_ANY) - { + if ((prach_sfn == SRSLTE_PRACH_SFN_EVEN && ((current_tti / 10) % 2) == 0) || + prach_sfn == SRSLTE_PRACH_SFN_ANY) { srslte_prach_sf_config_t sf_config; srslte_prach_sf_config(config_idx, &sf_config); - for (int i=0;i v_max){ + if (v > v_max) { // Get a new root sequence - if(4 == p->f){ - u = prach_zc_roots_format4[(p->rsi + p->N_roots)%138]; - }else{ - u = prach_zc_roots[(p->rsi + p->N_roots)%838]; + if (4 == p->f) { + u = prach_zc_roots_format4[(p->rsi + p->N_roots) % 138]; + } else { + u = prach_zc_roots[(p->rsi + p->N_roots) % 838]; } - for(int j=0;jN_zc;j++){ - double phase = -M_PI*u*j*(j+1)/p->N_zc; - root[j] = cexp(phase*I); + for (int j = 0; j < p->N_zc; j++) { + double phase = -M_PI * u * j * (j + 1) / p->N_zc; + root[j] = cexp(phase * I); } p->root_seqs_idx[p->N_roots++] = i; // Determine v_max - if(p->hs){ + if (p->hs) { // High-speed cell - for(p_=1; p_<=p->N_zc; p_++){ - if(((p_*u) % p->N_zc) == 1) - break; + for (p_ = 1; p_ <= p->N_zc; p_++) { + if (((p_ * u) % p->N_zc) == 1) + break; } - if(p_ < p->N_zc/2){ - d_u = p_; - }else{ - d_u = p->N_zc - p_; + if (p_ < p->N_zc / 2) { + d_u = p_; + } else { + d_u = p->N_zc - p_; } - if(d_u >= p->N_cs && d_u < p->N_zc/3){ - N_shift = d_u/p->N_cs; - d_start = 2*d_u + N_shift*p->N_cs; - N_group = p->N_zc/d_start; - N_neg_shift = (p->N_zc - 2*d_u - N_group*d_start)/p->N_cs; - if(N_neg_shift < 0) - N_neg_shift = 0; - }else{ - 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) - N_neg_shift = 0; - if(N_neg_shift > N_shift) - N_neg_shift = N_shift; + if (d_u >= p->N_cs && d_u < p->N_zc / 3) { + N_shift = d_u / p->N_cs; + d_start = 2 * d_u + N_shift * p->N_cs; + N_group = p->N_zc / d_start; + if (p->N_zc > 2 * d_u + N_group * d_start) { + N_neg_shift = (p->N_zc - 2 * d_u - N_group * d_start) / p->N_cs; + } else { + N_neg_shift = 0; + } + } else if (p->N_zc / 3 <= d_u && d_u <= (p->N_zc - p->N_cs) / 2) { + 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) + N_neg_shift = 0; + if (N_neg_shift > N_shift) + N_neg_shift = N_shift; + } else { + N_shift = 0; } - v_max = N_shift*N_group + N_neg_shift - 1; - if(v_max < 0){ + v_max = N_shift * N_group + N_neg_shift - 1; + if (v_max < 0) { v_max = 0; } - }else{ + } else { // Normal cell - if(0 == p->N_cs){ + if (0 == p->N_cs) { v_max = 0; - }else{ - v_max = (p->N_zc/p->N_cs)-1; + } else { + v_max = (p->N_zc / p->N_cs) - 1; } } - v=0; + v = 0; } // Shift root and add to set - if(p->hs){ - if(N_shift==0){ + if (p->hs) { + if (N_shift == 0) { C_v = 0; - }else{ - C_v = d_start*floor(v/N_shift) + (v % N_shift)*p->N_cs; + } else { + C_v = d_start * floor(v / N_shift) + (v % N_shift) * p->N_cs; } - }else{ - C_v = v*p->N_cs; + } else { + C_v = v * p->N_cs; + } + if (i == 46) { + printf("i=%d, C_v=%d\n", i, C_v); } - for(int j=0;jN_zc;j++){ - p->seqs[i][j] = root[(j+C_v) % p->N_zc]; + for (int j = 0; j < p->N_zc; j++) { + p->seqs[i][j] = root[(j + C_v) % p->N_zc]; } v++; @@ -329,69 +328,66 @@ int srslte_prach_gen_seqs(srslte_prach_t *p) return 0; } -int srslte_prach_init_cfg(srslte_prach_t *p, srslte_prach_cfg_t *cfg, uint32_t nof_prb) -{ +int srslte_prach_init_cfg(srslte_prach_t *p, srslte_prach_cfg_t *cfg, uint32_t nof_prb) { if (srslte_prach_init(p, srslte_symbol_sz(nof_prb))) { return -1; } return srslte_prach_set_cell(p, - srslte_symbol_sz(nof_prb), - cfg->config_idx, - cfg->root_seq_idx, - cfg->hs_flag, - cfg->zero_corr_zone); + srslte_symbol_sz(nof_prb), + cfg->config_idx, + cfg->root_seq_idx, + cfg->hs_flag, + cfg->zero_corr_zone); } -int srslte_prach_init(srslte_prach_t *p, uint32_t max_N_ifft_ul) -{ +int srslte_prach_init(srslte_prach_t *p, uint32_t max_N_ifft_ul) { int ret = SRSLTE_ERROR; - if(p != NULL && - max_N_ifft_ul < 2049) - { + if (p != NULL && + max_N_ifft_ul < 2049) { bzero(p, sizeof(srslte_prach_t)); p->max_N_ifft_ul = max_N_ifft_ul; // Set up containers - p->prach_bins = srslte_vec_malloc(sizeof(cf_t)*MAX_N_zc); - p->corr_spec = srslte_vec_malloc(sizeof(cf_t)*MAX_N_zc); - p->corr = srslte_vec_malloc(sizeof(float)*MAX_N_zc); + p->prach_bins = srslte_vec_malloc(sizeof(cf_t) * MAX_N_zc); + p->corr_spec = srslte_vec_malloc(sizeof(cf_t) * MAX_N_zc); + p->corr = srslte_vec_malloc(sizeof(float) * MAX_N_zc); // Set up ZC FFTS - if(srslte_dft_plan(&p->zc_fft, MAX_N_zc, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)){ + if (srslte_dft_plan(&p->zc_fft, MAX_N_zc, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) { return SRSLTE_ERROR; } srslte_dft_plan_set_mirror(&p->zc_fft, false); srslte_dft_plan_set_norm(&p->zc_fft, true); - if(srslte_dft_plan(&p->zc_ifft, MAX_N_zc, SRSLTE_DFT_BACKWARD, SRSLTE_DFT_COMPLEX)){ + if (srslte_dft_plan(&p->zc_ifft, MAX_N_zc, SRSLTE_DFT_BACKWARD, SRSLTE_DFT_COMPLEX)) { return SRSLTE_ERROR; } srslte_dft_plan_set_mirror(&p->zc_ifft, false); srslte_dft_plan_set_norm(&p->zc_ifft, false); - uint32_t fft_size_alloc = max_N_ifft_ul * DELTA_F/DELTA_F_RA; + uint32_t fft_size_alloc = max_N_ifft_ul * DELTA_F / DELTA_F_RA; - p->ifft_in = (cf_t*)srslte_vec_malloc(fft_size_alloc*sizeof(cf_t)); - p->ifft_out = (cf_t*)srslte_vec_malloc(fft_size_alloc*sizeof(cf_t)); - if(srslte_dft_plan(&p->ifft, fft_size_alloc, SRSLTE_DFT_BACKWARD, SRSLTE_DFT_COMPLEX)) { + p->ifft_in = (cf_t *) srslte_vec_malloc(fft_size_alloc * sizeof(cf_t)); + p->ifft_out = (cf_t *) srslte_vec_malloc(fft_size_alloc * sizeof(cf_t)); + if (srslte_dft_plan(&p->ifft, fft_size_alloc, SRSLTE_DFT_BACKWARD, SRSLTE_DFT_COMPLEX)) { fprintf(stderr, "Error creating DFT plan\n"); return -1; } srslte_dft_plan_set_mirror(&p->ifft, true); srslte_dft_plan_set_norm(&p->ifft, true); - if(srslte_dft_plan(&p->fft, fft_size_alloc, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)){ + if (srslte_dft_plan(&p->fft, fft_size_alloc, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) { fprintf(stderr, "Error creating DFT plan\n"); return -1; } - - p->signal_fft = srslte_vec_malloc(sizeof(cf_t)*fft_size_alloc); + + p->signal_fft = srslte_vec_malloc(sizeof(cf_t) * fft_size_alloc); if (!p->signal_fft) { fprintf(stderr, "Error allocating memory\n"); - return -1; + return -1; } - + srslte_dft_plan_set_mirror(&p->fft, true); srslte_dft_plan_set_norm(&p->fft, false); @@ -403,20 +399,17 @@ int srslte_prach_init(srslte_prach_t *p, uint32_t max_N_ifft_ul) return ret; } - int srslte_prach_set_cell(srslte_prach_t *p, - uint32_t N_ifft_ul, - uint32_t config_idx, - uint32_t root_seq_index, - bool high_speed_flag, - uint32_t zero_corr_zone_config) -{ + uint32_t N_ifft_ul, + uint32_t config_idx, + uint32_t root_seq_index, + bool high_speed_flag, + uint32_t zero_corr_zone_config) { int ret = SRSLTE_ERROR; - if(p != NULL && - N_ifft_ul < 2049 && - config_idx < 64 && - root_seq_index < MAX_ROOTS) - { + if (p != NULL && + N_ifft_ul < 2049 && + config_idx < 64 && + root_seq_index < MAX_ROOTS) { if (N_ifft_ul > p->max_N_ifft_ul) { fprintf(stderr, "PRACH: Error in set_cell(): N_ifft_ul must be lower or equal max_N_ifft_ul in init()\n"); return -1; @@ -432,7 +425,7 @@ int srslte_prach_set_cell(srslte_prach_t *p, // Determine N_zc and N_cs - if(4 == preamble_format){ + if (4 == preamble_format) { if (p->zczc < 7) { p->N_zc = 139; p->N_cs = prach_Ncs_format4[p->zczc]; @@ -440,16 +433,16 @@ int srslte_prach_set_cell(srslte_prach_t *p, fprintf(stderr, "Invalid zeroCorrelationZoneConfig=%d for format4\n", p->zczc); return SRSLTE_ERROR; } - }else{ + } else { p->N_zc = MAX_N_zc; - if(p->hs){ + if (p->hs) { if (p->zczc < 15) { p->N_cs = prach_Ncs_restricted[p->zczc]; } else { fprintf(stderr, "Invalid zeroCorrelationZoneConfig=%d for restricted set\n", p->zczc); return SRSLTE_ERROR; } - }else{ + } else { if (p->zczc < 16) { p->N_cs = prach_Ncs_unrestricted[p->zczc]; } else { @@ -461,10 +454,10 @@ int srslte_prach_set_cell(srslte_prach_t *p, // Set up ZC FFTS if (p->N_zc != MAX_N_zc) { - if(srslte_dft_replan(&p->zc_fft, p->N_zc)){ + if (srslte_dft_replan(&p->zc_fft, p->N_zc)) { return SRSLTE_ERROR; } - if(srslte_dft_replan(&p->zc_ifft, p->N_zc)){ + if (srslte_dft_replan(&p->zc_ifft, p->N_zc)) { return SRSLTE_ERROR; } } @@ -474,16 +467,16 @@ int srslte_prach_set_cell(srslte_prach_t *p, srslte_prach_gen_seqs(p); // Generate sequence FFTs - for(int i=0;izc_fft, p->seqs[i], p->dft_seqs[i]); } // Create our FFT objects and buffers p->N_ifft_ul = N_ifft_ul; - if(4 == preamble_format){ - p->N_ifft_prach = p->N_ifft_ul * DELTA_F/DELTA_F_RA_4; - }else{ - p->N_ifft_prach = p->N_ifft_ul * DELTA_F/DELTA_F_RA; + if (4 == preamble_format) { + p->N_ifft_prach = p->N_ifft_ul * DELTA_F / DELTA_F_RA_4; + } else { + p->N_ifft_prach = p->N_ifft_ul * DELTA_F / DELTA_F_RA; } /* The deadzone specifies the number of samples at the end of the correlation window @@ -496,19 +489,19 @@ int srslte_prach_set_cell(srslte_prach_t *p, p->deadzone = (uint32_t) ceil((float) samp_rate/((float) p->N_zc*subcarrier_spacing)); }*/ - if(srslte_dft_replan(&p->ifft, p->N_ifft_prach)) { + if (srslte_dft_replan(&p->ifft, p->N_ifft_prach)) { fprintf(stderr, "Error creating DFT plan\n"); return -1; } - if(srslte_dft_replan(&p->fft, p->N_ifft_prach)){ + if (srslte_dft_replan(&p->fft, p->N_ifft_prach)) { fprintf(stderr, "Error creating DFT plan\n"); return -1; } - p->N_seq = prach_Tseq[p->f]*p->N_ifft_ul/2048; - p->N_cp = prach_Tcp[p->f]*p->N_ifft_ul/2048; - p->T_seq = prach_Tseq[p->f]*SRSLTE_LTE_TS; - p->T_tot = (prach_Tseq[p->f]+prach_Tcp[p->f])*SRSLTE_LTE_TS; + p->N_seq = prach_Tseq[p->f] * p->N_ifft_ul / 2048; + p->N_cp = prach_Tcp[p->f] * p->N_ifft_ul / 2048; + p->T_seq = prach_Tseq[p->f] * SRSLTE_LTE_TS; + p->T_tot = (prach_Tseq[p->f] + prach_Tcp[p->f]) * SRSLTE_LTE_TS; ret = SRSLTE_SUCCESS; } else { @@ -519,44 +512,42 @@ int srslte_prach_set_cell(srslte_prach_t *p, } int srslte_prach_gen(srslte_prach_t *p, - uint32_t seq_index, - uint32_t freq_offset, - cf_t *signal) -{ + uint32_t seq_index, + uint32_t freq_offset, + cf_t *signal) { int ret = SRSLTE_ERROR; - if(p != NULL && - seq_index < N_SEQS && - signal != NULL) - { + if (p != NULL && + seq_index < N_SEQS && + signal != NULL) { // Calculate parameters uint32_t N_rb_ul = srslte_nof_prb(p->N_ifft_ul); - uint32_t k_0 = freq_offset*N_RB_SC - N_rb_ul*N_RB_SC/2 + p->N_ifft_ul/2; - uint32_t K = DELTA_F/DELTA_F_RA; - uint32_t begin = PHI + (K*k_0) + (K/2); + uint32_t k_0 = freq_offset * N_RB_SC - N_rb_ul * N_RB_SC / 2 + p->N_ifft_ul / 2; + uint32_t K = DELTA_F / DELTA_F_RA; + uint32_t begin = PHI + (K * k_0) + (K / 2); if (6 + freq_offset > N_rb_ul) { fprintf(stderr, "Error no space for PRACH: frequency offset=%d, N_rb_ul=%d\n", freq_offset, N_rb_ul); - return ret; + return ret; } - - DEBUG("N_zc: %d, N_cp: %d, N_seq: %d, N_ifft_prach=%d begin: %d\n", + + DEBUG("N_zc: %d, N_cp: %d, N_seq: %d, N_ifft_prach=%d begin: %d\n", p->N_zc, p->N_cp, p->N_seq, p->N_ifft_prach, begin); - + // Map dft-precoded sequence to ifft bins - memset(p->ifft_in, 0, begin*sizeof(cf_t)); + memset(p->ifft_in, 0, begin * sizeof(cf_t)); memcpy(&p->ifft_in[begin], p->dft_seqs[seq_index], p->N_zc * sizeof(cf_t)); - memset(&p->ifft_in[begin+p->N_zc], 0, (p->N_ifft_prach - begin - p->N_zc) * sizeof(cf_t)); + memset(&p->ifft_in[begin + p->N_zc], 0, (p->N_ifft_prach - begin - p->N_zc) * sizeof(cf_t)); srslte_dft_run(&p->ifft, p->ifft_in, p->ifft_out); // Copy CP into buffer - memcpy(signal, &p->ifft_out[p->N_ifft_prach-p->N_cp], p->N_cp*sizeof(cf_t)); + memcpy(signal, &p->ifft_out[p->N_ifft_prach - p->N_cp], p->N_cp * sizeof(cf_t)); // Copy preamble sequence into buffer - for(int i=0;iN_seq;i++){ - signal[p->N_cp+i] = p->ifft_out[i%p->N_ifft_prach]; + for (int i = 0; i < p->N_seq; i++) { + signal[p->N_cp + i] = p->ifft_out[i % p->N_ifft_prach]; } - + ret = SRSLTE_SUCCESS; } @@ -564,7 +555,7 @@ int srslte_prach_gen(srslte_prach_t *p, } void srslte_prach_set_detect_factor(srslte_prach_t *p, float ratio) { - p->detect_factor = ratio; + p->detect_factor = ratio; } int srslte_prach_detect(srslte_prach_t *p, @@ -572,8 +563,7 @@ int srslte_prach_detect(srslte_prach_t *p, cf_t *signal, uint32_t sig_len, uint32_t *indices, - uint32_t *n_indices) -{ + uint32_t *n_indices) { return srslte_prach_detect_offset(p, freq_offset, signal, sig_len, indices, NULL, NULL, n_indices); } @@ -583,21 +573,19 @@ int srslte_prach_detect_offset(srslte_prach_t *p, uint32_t sig_len, uint32_t *indices, float *t_offsets, - float *peak_to_avg, - uint32_t *n_indices) -{ + float *peak_to_avg, + uint32_t *n_indices) { int ret = SRSLTE_ERROR; - if(p != NULL && - signal != NULL && - sig_len > 0 && - indices != NULL) - { - - if(sig_len < p->N_ifft_prach){ + if (p != NULL && + signal != NULL && + sig_len > 0 && + indices != NULL) { + + if (sig_len < p->N_ifft_prach) { fprintf(stderr, "srslte_prach_detect: Signal length is %d and should be %d\n", sig_len, p->N_ifft_prach); return SRSLTE_ERROR_INVALID_INPUTS; } - + // FFT incoming signal srslte_dft_run(&p->fft, signal, p->signal_fft); @@ -605,66 +593,65 @@ int srslte_prach_detect_offset(srslte_prach_t *p, // Extract bins of interest uint32_t N_rb_ul = srslte_nof_prb(p->N_ifft_ul); - uint32_t k_0 = freq_offset*N_RB_SC - N_rb_ul*N_RB_SC/2 + p->N_ifft_ul/2; - uint32_t K = DELTA_F/DELTA_F_RA; - uint32_t begin = PHI + (K*k_0) + (K/2); + uint32_t k_0 = freq_offset * N_RB_SC - N_rb_ul * N_RB_SC / 2 + p->N_ifft_ul / 2; + uint32_t K = DELTA_F / DELTA_F_RA; + uint32_t begin = PHI + (K * k_0) + (K / 2); - memcpy(p->prach_bins, &p->signal_fft[begin], p->N_zc*sizeof(cf_t)); - - for(int i=0;iN_roots;i++){ + memcpy(p->prach_bins, &p->signal_fft[begin], p->N_zc * sizeof(cf_t)); + + for (int i = 0; i < p->N_roots; i++) { cf_t *root_spec = p->dft_seqs[p->root_seqs_idx[i]]; - + srslte_vec_prod_conj_ccc(p->prach_bins, root_spec, p->corr_spec, p->N_zc); srslte_dft_run(&p->zc_ifft, p->corr_spec, p->corr_spec); - + srslte_vec_abs_square_cf(p->corr_spec, p->corr, p->N_zc); - float corr_ave = srslte_vec_acc_ff(p->corr, p->N_zc)/p->N_zc; - + float corr_ave = srslte_vec_acc_ff(p->corr, p->N_zc) / p->N_zc; + uint32_t winsize = 0; - if(p->N_cs != 0){ + if (p->N_cs != 0) { winsize = p->N_cs; - }else{ + } else { winsize = p->N_zc; } - uint32_t n_wins = p->N_zc/winsize; - - float max_peak = 0; - for(int j=0;jN_zc-(j*p->N_cs))%p->N_zc; - uint32_t end = start+winsize; - if (end>p->deadzone) { - end-=p->deadzone; + uint32_t n_wins = p->N_zc / winsize; + + float max_peak = 0; + for (int j = 0; j < n_wins; j++) { + uint32_t start = (p->N_zc - (j * p->N_cs)) % p->N_zc; + uint32_t end = start + winsize; + if (end > p->deadzone) { + end -= p->deadzone; } start += p->deadzone; p->peak_values[j] = 0; - for(int k=start;kcorr[k] > p->peak_values[j]) { - p->peak_values[j] = p->corr[k]; - p->peak_offsets[j] = k-start; + for (int k = start; k < end; k++) { + if (p->corr[k] > p->peak_values[j]) { + p->peak_values[j] = p->corr[k]; + p->peak_offsets[j] = k - start; if (p->peak_values[j] > max_peak) { max_peak = p->peak_values[j]; } } } } - if (max_peak > p->detect_factor*corr_ave) { - for (int j=0;jpeak_values[j] > p->detect_factor*corr_ave) - { + if (max_peak > p->detect_factor * corr_ave) { + for (int j = 0; j < n_wins; j++) { + if (p->peak_values[j] > p->detect_factor * corr_ave) { //printf("saving prach correlation\n"); //memcpy(save_corr, p->corr, p->N_zc*sizeof(float)); if (indices) { - indices[*n_indices] = (i*n_wins)+j; + indices[*n_indices] = (i * n_wins) + j; } if (peak_to_avg) { - peak_to_avg[*n_indices] = p->peak_values[j]/corr_ave; + peak_to_avg[*n_indices] = p->peak_values[j] / corr_ave; } if (t_offsets) { - t_offsets[*n_indices] = (float) p->peak_offsets[j]*p->T_seq/p->N_zc; - } - (*n_indices)++; + t_offsets[*n_indices] = (float) p->peak_offsets[j] * p->T_seq / p->N_zc; + } + (*n_indices)++; } } } @@ -687,41 +674,37 @@ int srslte_prach_free(srslte_prach_t *p) { srslte_dft_plan_free(&p->zc_ifft); if (p->signal_fft) { - free(p->signal_fft); + free(p->signal_fft); } - + bzero(p, sizeof(srslte_prach_t)); return 0; } -int srslte_prach_print_seqs(srslte_prach_t *p) -{ - for(int i=0; iseqs[i] , sizeof(cf_t), p->N_zc, f); + fwrite(p->seqs[i], sizeof(cf_t), p->N_zc, f); fclose(f); } - for(int i=0; idft_seqs[i] , sizeof(cf_t), p->N_zc, f); + fwrite(p->dft_seqs[i], sizeof(cf_t), p->N_zc, f); fclose(f); } - for(int i=0;iN_roots;i++) - { + for (int i = 0; i < p->N_roots; i++) { FILE *f; char str[32]; sprintf(str, "prach_root_seq_%d.bin", i); f = fopen(str, "wb"); - fwrite(p->seqs[p->root_seqs_idx[i]] , sizeof(cf_t), p->N_zc, f); + fwrite(p->seqs[p->root_seqs_idx[i]], sizeof(cf_t), p->N_zc, f); fclose(f); } return 0; From 3982db00fe93af3bc35c01079197b81e18437cc1 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 18:07:39 +0100 Subject: [PATCH 26/74] 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 ea07f695adc2d7e4c3d8c46500ddf63a9e4dfb9f Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 18:07:39 +0100 Subject: [PATCH 27/74] 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 28/74] 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 29/74] 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 30/74] 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 31/74] 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 32/74] 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 { From e6274801ce70edbee65c51a67b0f92ef0899c6f2 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 22:33:28 +0100 Subject: [PATCH 33/74] Restored pathloss metric --- srsue/src/phy/phch_worker.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index a4e6eeb47..f7e1381f8 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->get_radio()->get_rx_gain(); + dl_metrics.pathloss = phy->pathloss; dl_metrics.sinr = phy->avg_snr_db; dl_metrics.turbo_iters = srslte_pdsch_last_noi(&ue_dl.pdsch); phy->set_dl_metrics(dl_metrics); From ca4a22aeaf244cca2cdf2003eb8b6a29bc6e1860 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 23:20:35 +0100 Subject: [PATCH 34/74] Transmit Msg3 only if available --- srsue/hdr/mac/ul_harq.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index b98a7497a..644167746 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -237,8 +237,8 @@ private: // New transmission reset(); - // Uplink grant in a RAR - if (grant->is_from_rar) { + // Uplink grant in a RAR and there is a PDU in the Msg3 buffer + if (grant->is_from_rar && !harq_entity->mux_unit->msg3_is_transmitted()) { Debug("Getting Msg3 buffer payload, grant size=%d bytes\n", grant->n_bytes[0]); pdu_ptr = harq_entity->mux_unit->msg3_get(payload_buffer, grant->n_bytes[0]); if (pdu_ptr) { From 13a16e200cd088b7a3ea554a99aa81ff995ccca6 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 23:31:52 +0100 Subject: [PATCH 35/74] Transmit Msg3 only if available (2) --- srsue/hdr/mac/mux.h | 4 ++++ srsue/hdr/mac/ul_harq.h | 3 ++- srsue/src/mac/mux.cc | 13 ++++++++++++- srsue/src/mac/proc_ra.cc | 3 ++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/srsue/hdr/mac/mux.h b/srsue/hdr/mac/mux.h index ebc61b5c6..889dd68f3 100644 --- a/srsue/hdr/mac/mux.h +++ b/srsue/hdr/mac/mux.h @@ -67,6 +67,9 @@ public: void msg3_flush(); bool msg3_is_transmitted(); + + void msg3_prepare(); + bool msg3_is_pending(); void append_crnti_ce_next_tx(uint16_t crnti); @@ -105,6 +108,7 @@ private: /* PDU Buffer */ srslte::sch_pdu pdu_msg; bool msg3_has_been_transmitted; + bool msg3_pending; }; } // namespace srsue diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index 644167746..21b84aa60 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -238,7 +238,7 @@ private: reset(); // Uplink grant in a RAR and there is a PDU in the Msg3 buffer - if (grant->is_from_rar && !harq_entity->mux_unit->msg3_is_transmitted()) { + if (grant->is_from_rar && harq_entity->mux_unit->msg3_is_pending()) { Debug("Getting Msg3 buffer payload, grant size=%d bytes\n", grant->n_bytes[0]); pdu_ptr = harq_entity->mux_unit->msg3_get(payload_buffer, grant->n_bytes[0]); if (pdu_ptr) { @@ -246,6 +246,7 @@ private: } else { Warning("UL RAR grant available but no Msg3 on buffer\n"); } + printf("Transmitted Msg3\n"); // Normal UL grant } else { diff --git a/srsue/src/mac/mux.cc b/srsue/src/mac/mux.cc index ba2b45209..2f8ade2af 100644 --- a/srsue/src/mac/mux.cc +++ b/srsue/src/mac/mux.cc @@ -65,6 +65,7 @@ void mux::reset() for (uint32_t i=0;imsg3_prepare(); rntis->temp_rnti = rar_pdu_msg.get()->get_temp_crnti(); phy_h->pdcch_dl_search(SRSLTE_RNTI_TEMP, rar_pdu_msg.get()->get_temp_crnti()); From 1db4644c7b5443592d06c5661d7a7defec21f9c3 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 23:46:12 +0100 Subject: [PATCH 36/74] Set PHY crnti before RA done no contention --- srsue/src/mac/proc_ra.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srsue/src/mac/proc_ra.cc b/srsue/src/mac/proc_ra.cc index 3860fd809..b7aa90b26 100644 --- a/srsue/src/mac/proc_ra.cc +++ b/srsue/src/mac/proc_ra.cc @@ -347,7 +347,8 @@ void ra_proc::tb_decoded_ok() { if (preambleIndex > 0) { // Preamble selected by Network - state = COMPLETION; + phy_h->set_crnti(rntis->crnti); + state = COMPLETION; } else { // Preamble selected by UE MAC mux_unit->msg3_prepare(); From d52c2402ff590ffd0d38f1b9fdd53228e04e5af9 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 13 Feb 2018 23:53:08 +0100 Subject: [PATCH 37/74] Revert "Set PHY crnti before RA done no contention" This reverts commit 1db4644c7b5443592d06c5661d7a7defec21f9c3. --- srsue/src/mac/proc_ra.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/srsue/src/mac/proc_ra.cc b/srsue/src/mac/proc_ra.cc index b7aa90b26..3860fd809 100644 --- a/srsue/src/mac/proc_ra.cc +++ b/srsue/src/mac/proc_ra.cc @@ -347,8 +347,7 @@ void ra_proc::tb_decoded_ok() { if (preambleIndex > 0) { // Preamble selected by Network - phy_h->set_crnti(rntis->crnti); - state = COMPLETION; + state = COMPLETION; } else { // Preamble selected by UE MAC mux_unit->msg3_prepare(); From 9acefc53f8477c99231193162ca98b5e53c5b0f2 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 14 Feb 2018 00:00:31 +0100 Subject: [PATCH 38/74] Set C-RNTI when grant from RAR but no Msg3 --- srsue/hdr/mac/ul_harq.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index 21b84aa60..4ea37cb07 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -250,6 +250,9 @@ private: // Normal UL grant } else { + if (grant->is_from_rar) { + grant->rnti = harq_entity->rntis->crnti; + } // Request a MAC PDU from the Multiplexing & Assemble Unit pdu_ptr = harq_entity->mux_unit->pdu_get(payload_buffer, grant->n_bytes[0], tti_tx, pid); if (pdu_ptr) { From 898c86d95490c9e938ace88dc2a92557d5c8af14 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Tue, 13 Feb 2018 23:28:09 +0100 Subject: [PATCH 39/74] Channel estimattor selects the strongest RSRP. --- lib/src/phy/ch_estimation/chest_dl.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/src/phy/ch_estimation/chest_dl.c b/lib/src/phy/ch_estimation/chest_dl.c index 3dae7f9e5..ba9ae40e6 100644 --- a/lib/src/phy/ch_estimation/chest_dl.c +++ b/lib/src/phy/ch_estimation/chest_dl.c @@ -691,14 +691,22 @@ float srslte_chest_dl_get_rsrp_ant_port(srslte_chest_dl_t *q, uint32_t ant_idx, } float srslte_chest_dl_get_rsrp_port(srslte_chest_dl_t *q, uint32_t port) { - float n = 0; + float max = -INFINITY; for (int i = 0; i < q->last_nof_antennas; i++) { - n += q->rsrp[i][port]; + if (q->rsrp[i][port] > max) { + max = q->rsrp[i][port]; + } } - return n / q->last_nof_antennas; + return max; } float srslte_chest_dl_get_rsrp(srslte_chest_dl_t *q) { - // Note: use only port 0 but average across antennas - return srslte_chest_dl_get_rsrp_port(q, 0); + float max = -INFINITY; + for (int i = 0; i < q->cell.nof_ports; ++i) { + float v = srslte_chest_dl_get_rsrp_port(q, i); + if (max < v) { + max = v; + } + } + return max; } From b54efc6d9fa64f4d9ab8700c9006d7b642163c3c Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 14 Feb 2018 17:15:30 +0100 Subject: [PATCH 40/74] Added testing log info --- srsue/src/upper/rrc.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index f93401fc5..b5c44b391 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -2602,6 +2602,7 @@ void rrc::rrc_meas::calculate_triggers(uint32_t tti) } } if (gen_report) { + log_h->info("Generate report MeasId=%d, from event\n", m->first); generate_report(m->first); } } @@ -2631,6 +2632,7 @@ void rrc::rrc_meas::ho_finish() { bool rrc::rrc_meas::timer_expired(uint32_t timer_id) { for (std::map::iterator iter = active.begin(); iter != active.end(); ++iter) { if (iter->second.periodic_timer == timer_id) { + log_h->info("Generate report MeasId=%d, from timerId=%d\n", iter->first, timer_id); generate_report(iter->first); return true; } @@ -2814,6 +2816,8 @@ void rrc::rrc_meas::parse_meas_config(LIBLTE_RRC_MEAS_CONFIG_STRUCT *cfg) remove_meas_id(cfg->meas_id_to_remove_list[i]); } + log_h->info("nof active measId=%d\n", active.size()); + // Measurement identity addition/modification 5.5.2.3 if (cfg->meas_id_to_add_mod_list_present) { for (uint32_t i=0;imeas_id_to_add_mod_list.N_meas_id;i++) { @@ -2828,8 +2832,9 @@ void rrc::rrc_meas::parse_meas_config(LIBLTE_RRC_MEAS_CONFIG_STRUCT *cfg) } active[measId->meas_id].object_id = measId->meas_obj_id; active[measId->meas_id].report_id = measId->rep_cnfg_id; - log_h->info("MEAS: %s measId=%d, measObjectId=%d, reportConfigId=%d\n", - is_new?"Added":"Updated", measId->meas_id, measId->meas_obj_id, measId->rep_cnfg_id); + log_h->info("MEAS: %s measId=%d, measObjectId=%d, reportConfigId=%d, nof_values=%d\n", + is_new?"Added":"Updated", measId->meas_id, measId->meas_obj_id, measId->rep_cnfg_id, + active[measId->meas_id].cell_values.size()); } } From 23e722f97ac96469e17ab7493a37ce523d686073 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 14 Feb 2018 19:38:53 +0100 Subject: [PATCH 41/74] Fixed issue rsrp=0 in neighbour cell measurements --- srsue/src/upper/rrc.cc | 65 ++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index b5c44b391..ba2c45190 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -2539,6 +2539,8 @@ void rrc::rrc_meas::calculate_triggers(uint32_t tti) } } + + for (std::map::iterator m = active.begin(); m != active.end(); ++m) { report_cfg_t *cfg = &reports_cfg[m->second.report_id]; float hyst = 0.5*cfg->event.hysteresis; @@ -2563,41 +2565,48 @@ void rrc::rrc_meas::calculate_triggers(uint32_t tti) enter_condition = Mp + hyst < range_to_value(cfg->trigger_quantity, cfg->event.event_a1.eutra.range); exit_condition = Mp - hyst > range_to_value(cfg->trigger_quantity, cfg->event.event_a1.eutra.range); } + + // check only if gen_report |= process_event(&cfg->event, tti, enter_condition, exit_condition, - &m->second, &m->second.cell_values[serving_cell_idx]); + &m->second, &pcell_measurement); + if (gen_report) { + log_h->info("Triggered by A1/A2 event\n"); + } // Rest are evaluated for every cell in frequency } else { meas_obj_t *obj = &objects[m->second.object_id]; for (std::map::iterator cell = obj->cells.begin(); cell != obj->cells.end(); ++cell) { - float Ofn = obj->q_offset; - float Ocn = cell->second.q_offset; - float Mn = m->second.cell_values[cell->second.pci].ms[cfg->trigger_quantity]; - float Off=0, th=0, th1=0, th2=0; - bool enter_condition = false; - bool exit_condition = false; - switch (event_id) { - case LIBLTE_RRC_EVENT_ID_EUTRA_A3: - Off = 0.5*cfg->event.event_a3.offset; - enter_condition = Mn + Ofn + Ocn - hyst > Mp + Ofp + Ocp + Off; - exit_condition = Mn + Ofn + Ocn + hyst < Mp + Ofp + Ocp + Off; - break; - case LIBLTE_RRC_EVENT_ID_EUTRA_A4: - th = range_to_value(cfg->trigger_quantity, cfg->event.event_a4.eutra.range); - enter_condition = Mn + Ofn + Ocn - hyst > th; - exit_condition = Mn + Ofn + Ocn + hyst < th; - break; - case LIBLTE_RRC_EVENT_ID_EUTRA_A5: - th1 = range_to_value(cfg->trigger_quantity, cfg->event.event_a5.eutra1.range); - th2 = range_to_value(cfg->trigger_quantity, cfg->event.event_a5.eutra2.range); - enter_condition = (Mp + hyst < th1) && (Mn + Ofn + Ocn - hyst > th2); - exit_condition = (Mp - hyst > th1) && (Mn + Ofn + Ocn + hyst < th2); - break; - default: - log_h->error("Error event %s not implemented\n", event_str); + if (m->second.cell_values.count(cell->second.pci)) { + float Ofn = obj->q_offset; + float Ocn = cell->second.q_offset; + float Mn = m->second.cell_values[cell->second.pci].ms[cfg->trigger_quantity]; + float Off=0, th=0, th1=0, th2=0; + bool enter_condition = false; + bool exit_condition = false; + switch (event_id) { + case LIBLTE_RRC_EVENT_ID_EUTRA_A3: + Off = 0.5*cfg->event.event_a3.offset; + enter_condition = Mn + Ofn + Ocn - hyst > Mp + Ofp + Ocp + Off; + exit_condition = Mn + Ofn + Ocn + hyst < Mp + Ofp + Ocp + Off; + break; + case LIBLTE_RRC_EVENT_ID_EUTRA_A4: + th = range_to_value(cfg->trigger_quantity, cfg->event.event_a4.eutra.range); + enter_condition = Mn + Ofn + Ocn - hyst > th; + exit_condition = Mn + Ofn + Ocn + hyst < th; + break; + case LIBLTE_RRC_EVENT_ID_EUTRA_A5: + th1 = range_to_value(cfg->trigger_quantity, cfg->event.event_a5.eutra1.range); + th2 = range_to_value(cfg->trigger_quantity, cfg->event.event_a5.eutra2.range); + enter_condition = (Mp + hyst < th1) && (Mn + Ofn + Ocn - hyst > th2); + exit_condition = (Mp - hyst > th1) && (Mn + Ofn + Ocn + hyst < th2); + break; + default: + log_h->error("Error event %s not implemented\n", event_str); + } + gen_report |= process_event(&cfg->event, tti, enter_condition, exit_condition, + &m->second, &m->second.cell_values[cell->second.pci]); } - gen_report |= process_event(&cfg->event, tti, enter_condition, exit_condition, - &m->second, &m->second.cell_values[cell->second.pci]); } } } From 90de622f6c2fdaeb3ff39a3887a4f9ca1ac9b403 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 14 Feb 2018 21:52:14 +0100 Subject: [PATCH 42/74] Fixed SIB searching --- srsue/src/upper/rrc.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index f93401fc5..9ef892edb 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -341,11 +341,14 @@ void rrc::run_si_acquisition_procedure() // Instruct MAC to look for SIB1 tti = mac->get_current_tti(); si_win_start = sib_start_tti(tti, 2, 0, 5); - if (tti > last_win_start + 10) { + if (last_win_start == 0 || + (srslte_tti_interval(last_win_start, tti) > 20 && srslte_tti_interval(last_win_start, tti) < 1000)) + { + last_win_start = si_win_start; mac->bcch_start_rx(si_win_start, 1); - rrc_log->debug("Instructed MAC to search for SIB1, win_start=%d, win_len=%d\n", - si_win_start, 1); + rrc_log->info("Instructed MAC to search for SIB1, win_start=%d, win_len=%d, interval=%d\n", + si_win_start, 1, srslte_tti_interval(last_win_start, tti)); nof_sib1_trials++; if (nof_sib1_trials >= SIB1_SEARCH_TIMEOUT) { if (state == RRC_STATE_CELL_SELECTING) { @@ -369,13 +372,15 @@ void rrc::run_si_acquisition_procedure() tti = mac->get_current_tti(); period = liblte_rrc_si_periodicity_num[serving_cell->sib1.sched_info[sysinfo_index].si_periodicity]; si_win_start = sib_start_tti(tti, period, offset, sf); + si_win_len = liblte_rrc_si_window_length_num[serving_cell->sib1.si_window_length]; - if (tti > last_win_start + 10) { + if (last_win_start == 0 || + (srslte_tti_interval(last_win_start, tti) > period*10 && srslte_tti_interval(last_win_start, tti) < 1000)) + { last_win_start = si_win_start; - si_win_len = liblte_rrc_si_window_length_num[serving_cell->sib1.si_window_length]; mac->bcch_start_rx(si_win_start, si_win_len); - rrc_log->debug("Instructed MAC to search for system info, win_start=%d, win_len=%d\n", + rrc_log->info("Instructed MAC to search for system info, win_start=%d, win_len=%d\n", si_win_start, si_win_len); } @@ -1313,6 +1318,9 @@ void rrc::write_pdu_bcch_dlsch(byte_buffer_t *pdu) { handle_sib13(); } } + + last_win_start = 0; + if(serving_cell->has_valid_sib2) { sysinfo_index++; } From a2129601dfb9fd7064e85056c9f01459930eeb1b Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Thu, 15 Feb 2018 03:16:07 +0100 Subject: [PATCH 43/74] Noise level in MIMO is not divided by number of antennas --- lib/examples/pdsch_enodeb.c | 17 ++++++++++++++-- lib/src/phy/ch_estimation/chest_dl.c | 30 +++++++++++++++++----------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/examples/pdsch_enodeb.c b/lib/examples/pdsch_enodeb.c index c780e02ea..158d672ea 100644 --- a/lib/examples/pdsch_enodeb.c +++ b/lib/examples/pdsch_enodeb.c @@ -84,6 +84,8 @@ int mbsfn_area_id = -1; char *rf_args = ""; float rf_amp = 0.8, rf_gain = 70.0, rf_freq = 2400000000; +float output_file_snr = +INFINITY; + bool null_file_sink=false; srslte_filesink_t fsink; srslte_ofdm_t ifft[SRSLTE_MAX_PORTS]; @@ -145,13 +147,14 @@ void usage(char *prog) { printf("\t-w Number of codewords/layers (multiplex mode only)* [Default %d]\n", multiplex_nof_layers); printf("\t-u listen TCP port for input data (-1 is random) [Default %d]\n", net_port); printf("\t-v [set srslte_verbose to debug, default none]\n"); + printf("\t-s output file SNR [Default %f]\n", output_file_snr); printf("\n"); printf("\t*: See 3GPP 36.212 Table 5.3.3.1.5-4 for more information\n"); } void parse_args(int argc, char **argv) { int opt; - while ((opt = getopt(argc, argv, "aglfmoncpvutxbwM")) != -1) { + while ((opt = getopt(argc, argv, "aglfmoncpvutxbwMs")) != -1) { switch (opt) { case 'a': @@ -200,6 +203,9 @@ void parse_args(int argc, char **argv) { case 'v': srslte_verbose++; break; + case 's': + output_file_snr = atof(argv[optind]); + break; default: usage(argv[0]); exit(-1); @@ -989,7 +995,14 @@ int main(int argc, char **argv) { /* send to file or usrp */ if (output_file_name) { if (!null_file_sink) { - srslte_filesink_write_multi(&fsink, (void**) output_buffer, sf_n_samples, cell.nof_ports); + /* Apply AWGN */ + if (output_file_snr != +INFINITY) { + float var = powf(10.0f, -(output_file_snr + 3.0f) / 20.0f); + for (int k = 0; k < cell.nof_ports; k++) { + srslte_ch_awgn_c(output_buffer[k], output_buffer[k], var, sf_n_samples); + } + } + srslte_filesink_write_multi(&fsink, (void**) output_buffer, sf_n_samples, cell.nof_ports); } usleep(1000); } else { diff --git a/lib/src/phy/ch_estimation/chest_dl.c b/lib/src/phy/ch_estimation/chest_dl.c index ba9ae40e6..5249696af 100644 --- a/lib/src/phy/ch_estimation/chest_dl.c +++ b/lib/src/phy/ch_estimation/chest_dl.c @@ -291,7 +291,7 @@ static float estimate_noise_pilots(srslte_chest_dl_t *q, uint32_t port_id, srslt norm /= norm3; } } - float power = norm*q->cell.nof_ports*srslte_vec_avg_power_cf(q->tmp_noise, nref); + float power = norm*srslte_vec_avg_power_cf(q->tmp_noise, nref); return power; } @@ -543,7 +543,7 @@ void chest_interpolate_noise_est(srslte_chest_dl_t *q, cf_t *input, cf_t *ce, ui /* Compute RSRP for the channel estimates in this port */ uint32_t npilots = SRSLTE_REFSIGNAL_NUM_SF(q->cell.nof_prb, port_id); - q->rsrp[rxant_id][port_id] = __real__ srslte_vec_dot_prod_conj_ccc(q->pilot_estimates, q->pilot_estimates, npilots) / npilots; + q->rsrp[rxant_id][port_id] = srslte_vec_avg_power_cf(q->pilot_estimates, npilots); q->rssi[rxant_id][port_id] = srslte_chest_dl_rssi(q, input, port_id); } @@ -639,7 +639,10 @@ float srslte_chest_dl_get_noise_estimate(srslte_chest_dl_t *q) { for (int i=0;ilast_nof_antennas;i++) { n += srslte_vec_acc_ff(q->noise_estimate[i], q->cell.nof_ports)/q->cell.nof_ports; } - return n/q->last_nof_antennas; + if (q->last_nof_antennas) { + n /= q->last_nof_antennas; + } + return n; } float srslte_chest_dl_get_snr(srslte_chest_dl_t *q) { @@ -691,20 +694,23 @@ float srslte_chest_dl_get_rsrp_ant_port(srslte_chest_dl_t *q, uint32_t ant_idx, } float srslte_chest_dl_get_rsrp_port(srslte_chest_dl_t *q, uint32_t port) { - float max = -INFINITY; - for (int i = 0; i < q->last_nof_antennas; i++) { - if (q->rsrp[i][port] > max) { - max = q->rsrp[i][port]; - } + float sum = 0.0f; + for (int j = 0; j < q->cell.nof_ports; ++j) { + sum +=q->rsrp[port][j]; } - return max; + + if (q->cell.nof_ports) { + sum /= q->cell.nof_ports; + } + + return sum; } float srslte_chest_dl_get_rsrp(srslte_chest_dl_t *q) { - float max = -INFINITY; - for (int i = 0; i < q->cell.nof_ports; ++i) { + float max = -0.0f; + for (int i = 0; i < q->last_nof_antennas; ++i) { float v = srslte_chest_dl_get_rsrp_port(q, i); - if (max < v) { + if (v > max) { max = v; } } From b69854724781655fed8c3eadd9ae65c3c2d8d2c2 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Thu, 15 Feb 2018 16:39:56 +0000 Subject: [PATCH 44/74] Fix for first RLC tx after handover --- lib/src/upper/rlc_am.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 413a02ac1..e12138268 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -112,8 +112,10 @@ void rlc_am::reset() pthread_mutex_lock(&mutex); reordering_timeout.reset(); - if(tx_sdu) - tx_sdu->reset(); + if(tx_sdu) { + pool->deallocate(tx_sdu); + tx_sdu = NULL; + } if(rx_sdu) rx_sdu->reset(); From 48278c4c066a060c39f8054e0e19c449f7d653f4 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 10:25:57 +0100 Subject: [PATCH 45/74] deallocate sdu in rlc_am_test --- lib/test/upper/rlc_am_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index 0b8c63668..b690210a9 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -64,6 +64,7 @@ public: { assert(lcid == 1); sdus[n_sdus++] = sdu; + byte_buffer_pool::get_instance()->deallocate(sdu); } void write_pdu_bcch_bch(byte_buffer_t *sdu) {} void write_pdu_bcch_dlsch(byte_buffer_t *sdu) {} From f86bebb0f3c746b61bea099c3cc182fd3020a16b Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 11:23:58 +0100 Subject: [PATCH 46/74] Revert "deallocate sdu in rlc_am_test" This reverts commit 48278c4c066a060c39f8054e0e19c449f7d653f4. --- lib/test/upper/rlc_am_test.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index b690210a9..0b8c63668 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -64,7 +64,6 @@ public: { assert(lcid == 1); sdus[n_sdus++] = sdu; - byte_buffer_pool::get_instance()->deallocate(sdu); } void write_pdu_bcch_bch(byte_buffer_t *sdu) {} void write_pdu_bcch_dlsch(byte_buffer_t *sdu) {} From 90fe4a218bb82e8275b5ea4a8ebcb2a980990de4 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 11:37:57 +0100 Subject: [PATCH 47/74] Fix RNTI in Msg3 after non-contention HO in PCAP --- srsue/hdr/mac/ul_harq.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index 4ea37cb07..60deff36f 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -272,7 +272,7 @@ private: generate_retx(tti_tx, action); } if (harq_entity->pcap && grant) { - if (grant->is_from_rar) { + if (grant->is_from_rar && harq_entity->rntis->temp_rnti) { grant->rnti = harq_entity->rntis->temp_rnti; } harq_entity->pcap->write_ul_crnti(pdu_ptr, grant->n_bytes[0], grant->rnti, get_nof_retx(), tti_tx); From 9a8257048d71a6186b1c9594faf4998e13007c32 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 12:04:10 +0100 Subject: [PATCH 48/74] Casted phy_log vector to srslte::log --- srsue/src/phy/phy.cc | 2 +- srsue/src/ue.cc | 4 ++-- srsue/test/mac/mac_test.cc | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index 820cf1351..07337b022 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -120,7 +120,7 @@ bool phy::check_args(phy_args_t *args) } bool phy::init(srslte::radio_multi* radio_handler, mac_interface_phy *mac, rrc_interface_phy *rrc, - std::vector log_vec, phy_args_t *phy_args) { + std::vector log_vec, phy_args_t *phy_args) { mlockall(MCL_CURRENT | MCL_FUTURE); diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index 611bac620..2f8fa5794 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -68,7 +68,7 @@ bool ue::init(all_args_t *args_) char tmp[16]; sprintf(tmp, "PHY%d",i); mylog->init(tmp, logger, true); - phy_log.push_back((void*) mylog); + phy_log.push_back(mylog); } mac_log.init("MAC ", logger, true); @@ -91,7 +91,7 @@ bool ue::init(all_args_t *args_) char tmp[16]; sprintf(tmp, "PHY_LIB"); lib_log->init(tmp, logger, true); - phy_log.push_back((void*) lib_log); + phy_log.push_back(lib_log); ((srslte::log_filter*) phy_log[args->expert.phy.nof_phy_threads])->set_level(level(args->log.phy_lib_level)); diff --git a/srsue/test/mac/mac_test.cc b/srsue/test/mac/mac_test.cc index 324189427..b76ab2f95 100644 --- a/srsue/test/mac/mac_test.cc +++ b/srsue/test/mac/mac_test.cc @@ -451,12 +451,12 @@ int main(int argc, char *argv[]) exit(1); } - std::vector phy_log; + std::vector phy_log; srslte::log_filter *mylog = new srslte::log_filter("PHY"); char tmp[16]; sprintf(tmp, "PHY%d",0); - phy_log.push_back((void*) mylog); + phy_log.push_back((srslte::log*) mylog); switch (prog_args.verbose) { case 1: From 097005684aab2b42c95f5b92d1bdcc605df123d2 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 12:05:45 +0100 Subject: [PATCH 49/74] Logs to test snr drop issue --- srsue/hdr/phy/phch_worker.h | 3 +++ srsue/src/phy/phch_recv.cc | 5 +++-- srsue/src/phy/phch_worker.cc | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/srsue/hdr/phy/phch_worker.h b/srsue/hdr/phy/phch_worker.h index c154ff514..78389ccf7 100644 --- a/srsue/hdr/phy/phch_worker.h +++ b/srsue/hdr/phy/phch_worker.h @@ -70,6 +70,9 @@ public: void start_plot(); float get_ref_cfo(); + float get_snr(); + float get_rsrp(); + float get_noise(); float get_cfo(); float get_ul_cfo(); diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index bf09f5f34..80c972266 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -675,10 +675,11 @@ void phch_recv::run_thread() case 1: if (last_worker) { - Debug("SF: cfo_tot=%7.1f Hz, ref=%f Hz, pss=%f Hz\n", + Info("SF: cfo_tot=%7.1f Hz, ref=%f Hz, pss=%f Hz, snr_sf=%.2f dB, rsrp=%.2f dB, noise=%.2f dB\n", srslte_ue_sync_get_cfo(&ue_sync), 15000*last_worker->get_ref_cfo(), - 15000*ue_sync.strack.cfo_pss_mean); + 15000*ue_sync.strack.cfo_pss_mean, + last_worker->get_snr(), last_worker->get_rsrp(), last_worker->get_noise()); } last_worker = worker; diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index f7e1381f8..e6fb7f35a 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -203,6 +203,22 @@ float phch_worker::get_ref_cfo() return srslte_chest_dl_get_cfo(&ue_dl.chest); } +float phch_worker::get_snr() +{ + return 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest)); +} + +float phch_worker::get_rsrp() +{ + return 10*log10(srslte_chest_dl_get_rsrp(&ue_dl.chest)); +} + +float phch_worker::get_noise() +{ + return 10*log10(srslte_chest_dl_get_noise_estimate(&ue_dl.chest)); +} + + float phch_worker::get_cfo() { return cfo; From 75f42ac82955fa55d4925f3805495d676f6d34e5 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 12:40:07 +0100 Subject: [PATCH 50/74] add RLC AM destructor --- lib/include/srslte/upper/rlc_am.h | 1 + lib/src/upper/rlc_am.cc | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index 2311b23cb..7601baefa 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -71,6 +71,7 @@ class rlc_am { public: rlc_am(); + ~rlc_am(); void init(log *rlc_entity_log_, uint32_t lcid_, srsue::pdcp_interface_rlc *pdcp_, diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 413a02ac1..652970011 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -68,6 +68,20 @@ rlc_am::rlc_am() : tx_sdu_queue(16) do_status = false; } +rlc_am::~rlc_am() +{ + // reset RLC and dealloc SDUs + stop(); + + if(rx_sdu) { + pool->deallocate(rx_sdu); + } + + if(tx_sdu) { + pool->deallocate(tx_sdu); + } +} + void rlc_am::init(srslte::log *log_, uint32_t lcid_, srsue::pdcp_interface_rlc *pdcp_, From b5b1c0bf4b53aae7ebbb64c5ef0f6efe3ca16e4d Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 12:41:13 +0100 Subject: [PATCH 51/74] fix memory leaks RLC AM test --- lib/test/upper/rlc_am_test.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index 0b8c63668..184de3a00 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -59,6 +59,14 @@ public: n_sdus = 0; } + ~rlc_am_tester(){ + for (uint32_t i = 0; i < 10; i++) { + if (sdus[i] != NULL) { + byte_buffer_pool::get_instance()->deallocate(sdus[i]); + } + } + } + // PDCP interface void write_pdu(uint32_t lcid, byte_buffer_t *sdu) { @@ -1051,21 +1059,31 @@ void resegment_test_6() int main(int argc, char **argv) { basic_test(); byte_buffer_pool::get_instance()->cleanup(); + concat_test(); byte_buffer_pool::get_instance()->cleanup(); + segment_test(); byte_buffer_pool::get_instance()->cleanup(); + retx_test(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_1(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_2(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_3(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_4(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_5(); byte_buffer_pool::get_instance()->cleanup(); + resegment_test_6(); + byte_buffer_pool::get_instance()->cleanup(); } From 315c5de06ca43d9ba58b8e799ccfc1e8905c45a2 Mon Sep 17 00:00:00 2001 From: yagoda Date: Fri, 16 Feb 2018 13:51:32 +0000 Subject: [PATCH 52/74] fixing type mismatch error in phy.h --- srsue/hdr/phy/phy.h | 4 ++-- srsue/hdr/ue.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 53d4f6e13..a29480ad4 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -53,7 +53,7 @@ public: bool init(srslte::radio_multi *radio_handler, mac_interface_phy *mac, rrc_interface_phy *rrc, - std::vector log_vec, + std::vector log_vec, phy_args_t *args = NULL); void stop(); @@ -159,7 +159,7 @@ private: const static int WORKERS_THREAD_PRIO = 0; srslte::radio_multi *radio_handler; - std::vector log_vec; + std::vector log_vec; srslte::log *log_h; srslte::log *log_phy_lib_h; srsue::mac_interface_phy *mac; diff --git a/srsue/hdr/ue.h b/srsue/hdr/ue.h index 763531261..e36277461 100644 --- a/srsue/hdr/ue.h +++ b/srsue/hdr/ue.h @@ -101,7 +101,7 @@ private: srslte::logger *logger; // rf_log is on ue_base - std::vector phy_log; + std::vector phy_log; srslte::log_filter mac_log; srslte::log_filter rlc_log; srslte::log_filter pdcp_log; From 79e59f1bf85af1bb01fca1b50afa03e00267450d Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 15:25:53 +0100 Subject: [PATCH 53/74] Missed headers in previous commit --- srsue/hdr/phy/phy.h | 4 ++-- srsue/hdr/ue.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 53d4f6e13..a29480ad4 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -53,7 +53,7 @@ public: bool init(srslte::radio_multi *radio_handler, mac_interface_phy *mac, rrc_interface_phy *rrc, - std::vector log_vec, + std::vector log_vec, phy_args_t *args = NULL); void stop(); @@ -159,7 +159,7 @@ private: const static int WORKERS_THREAD_PRIO = 0; srslte::radio_multi *radio_handler; - std::vector log_vec; + std::vector log_vec; srslte::log *log_h; srslte::log *log_phy_lib_h; srsue::mac_interface_phy *mac; diff --git a/srsue/hdr/ue.h b/srsue/hdr/ue.h index 763531261..e36277461 100644 --- a/srsue/hdr/ue.h +++ b/srsue/hdr/ue.h @@ -101,7 +101,7 @@ private: srslte::logger *logger; // rf_log is on ue_base - std::vector phy_log; + std::vector phy_log; srslte::log_filter mac_log; srslte::log_filter rlc_log; srslte::log_filter pdcp_log; From 056e3793477a6ed14520380ec179967565adcfc5 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 16:09:07 +0100 Subject: [PATCH 54/74] Set TA to time_adv instead of nsamples --- srsue/src/phy/phch_recv.cc | 9 ++------- srsue/src/phy/phy.cc | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 80c972266..bda9fbd69 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -186,14 +186,9 @@ void phch_recv::set_agc_enable(bool enable) } } -void phch_recv::set_time_adv_sec(float _time_adv_sec) +void phch_recv::set_time_adv_sec(float time_adv_sec) { - if (TX_MODE_CONTINUOUS && !radio_h->is_first_of_burst()) { - int nsamples = ceil(current_srate*_time_adv_sec); - next_offset = -nsamples; - } else { - time_adv_sec = _time_adv_sec; - } + this->time_adv_sec = time_adv_sec; } void phch_recv::set_ue_sync_opts(srslte_ue_sync_t *q, float cfo) diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index 07337b022..84cd0fd08 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -226,7 +226,7 @@ void phy::set_timeadv_rar(uint32_t ta_cmd) { void phy::set_timeadv(uint32_t ta_cmd) { uint32_t new_nta = srslte_N_ta_new(n_ta, ta_cmd); - sf_recv.set_time_adv_sec(((float) (new_nta - n_ta))*SRSLTE_LTE_TS); + sf_recv.set_time_adv_sec(((float) new_nta)*SRSLTE_LTE_TS); Info("PHY: Set TA: ta_cmd: %d, n_ta: %d, old_n_ta: %d, ta_usec: %.1f\n", ta_cmd, new_nta, n_ta, ((float) new_nta)*SRSLTE_LTE_TS*1e6); n_ta = new_nta; } From e6dcb81d99138982893a2c2e62cdaf93d34aaf64 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 16:37:36 +0100 Subject: [PATCH 55/74] Ignore TA cmd --- srsue/src/phy/phy.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index 84cd0fd08..4417beb86 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -226,7 +226,7 @@ void phy::set_timeadv_rar(uint32_t ta_cmd) { void phy::set_timeadv(uint32_t ta_cmd) { uint32_t new_nta = srslte_N_ta_new(n_ta, ta_cmd); - sf_recv.set_time_adv_sec(((float) new_nta)*SRSLTE_LTE_TS); + //sf_recv.set_time_adv_sec(((float) new_nta)*SRSLTE_LTE_TS); Info("PHY: Set TA: ta_cmd: %d, n_ta: %d, old_n_ta: %d, ta_usec: %.1f\n", ta_cmd, new_nta, n_ta, ((float) new_nta)*SRSLTE_LTE_TS*1e6); n_ta = new_nta; } From 62116bf1aee150df3777ac0338ed52d9851eb3bf Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 17:16:03 +0100 Subject: [PATCH 56/74] Revert "Logs to test snr drop issue" This reverts commit 097005684aab2b42c95f5b92d1bdcc605df123d2. --- srsue/hdr/phy/phch_worker.h | 3 --- srsue/src/phy/phch_recv.cc | 5 ++--- srsue/src/phy/phch_worker.cc | 16 ---------------- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/srsue/hdr/phy/phch_worker.h b/srsue/hdr/phy/phch_worker.h index 78389ccf7..c154ff514 100644 --- a/srsue/hdr/phy/phch_worker.h +++ b/srsue/hdr/phy/phch_worker.h @@ -70,9 +70,6 @@ public: void start_plot(); float get_ref_cfo(); - float get_snr(); - float get_rsrp(); - float get_noise(); float get_cfo(); float get_ul_cfo(); diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index bda9fbd69..72afb5e1e 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -670,11 +670,10 @@ void phch_recv::run_thread() case 1: if (last_worker) { - Info("SF: cfo_tot=%7.1f Hz, ref=%f Hz, pss=%f Hz, snr_sf=%.2f dB, rsrp=%.2f dB, noise=%.2f dB\n", + Debug("SF: cfo_tot=%7.1f Hz, ref=%f Hz, pss=%f Hz\n", srslte_ue_sync_get_cfo(&ue_sync), 15000*last_worker->get_ref_cfo(), - 15000*ue_sync.strack.cfo_pss_mean, - last_worker->get_snr(), last_worker->get_rsrp(), last_worker->get_noise()); + 15000*ue_sync.strack.cfo_pss_mean); } last_worker = worker; diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index e6fb7f35a..f7e1381f8 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -203,22 +203,6 @@ float phch_worker::get_ref_cfo() return srslte_chest_dl_get_cfo(&ue_dl.chest); } -float phch_worker::get_snr() -{ - return 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest)); -} - -float phch_worker::get_rsrp() -{ - return 10*log10(srslte_chest_dl_get_rsrp(&ue_dl.chest)); -} - -float phch_worker::get_noise() -{ - return 10*log10(srslte_chest_dl_get_noise_estimate(&ue_dl.chest)); -} - - float phch_worker::get_cfo() { return cfo; From 42c4b97f7e35bce0687671c696275fc2031e51c5 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 17:59:48 +0100 Subject: [PATCH 57/74] Stop PDCCH RX before HO --- srsue/src/upper/rrc.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 4e8897dc1..4d93c9452 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -1089,6 +1089,7 @@ bool rrc::ho_prepare() { ho_src_rnti = uernti.crnti; // Reset/Reestablish stack + mac->bcch_stop_rx(); // FIXME: change function name phy->meas_reset(); mac->wait_uplink(); pdcp->reestablish(); From bf691e8c65dee2a54c2f1fae19a4a431aed9132f Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 18:14:00 +0100 Subject: [PATCH 58/74] Do not stop RX during HO --- srsue/src/phy/phch_recv.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 72afb5e1e..6016f3e91 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -384,11 +384,13 @@ bool phch_recv::cell_handover(srslte_cell_t cell) this->cell = cell; Info("Cell HO: Stopping sync with current cell\n"); worker_com->reset_ul(); - stop_sync(); + //stop_sync(); Info("Cell HO: Reconfiguring cell\n"); if (set_cell()) { Info("Cell HO: Synchronizing with new cell\n"); - resync_sfn(true, true); + //resync_sfn(true, true); + sfn_p.reset(); + phy_state = CELL_RESELECT; ret = true; } else { log_h->error("Cell HO: Configuring cell PCI=%d\n", cell.id); From e59822f9a982295095d26519b44eca79e4df8e0c Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 18:41:38 +0100 Subject: [PATCH 59/74] Fixed bug in previous commit --- srsue/hdr/phy/phch_recv.h | 5 ++-- srsue/src/phy/phch_recv.cc | 52 ++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index 66c3342fb..bc7255ac9 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -309,10 +309,11 @@ private: CELL_SELECT, CELL_RESELECT, CELL_MEASURE, - CELL_CAMP + CELL_CAMP, + IDLE_RX } phy_state; - bool is_in_idle; + bool is_in_idle, is_in_idle_rx; // Sampling rate mode (find is 1.96 MHz, camp is the full cell BW) enum { diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 6016f3e91..8b913c1d3 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -380,20 +380,30 @@ bool phch_recv::cell_handover(srslte_cell_t cell) log_h->info("Cell HO: Waiting pending PHICH\n"); } - bool ret; + bool ret = false; this->cell = cell; Info("Cell HO: Stopping sync with current cell\n"); worker_com->reset_ul(); - //stop_sync(); - Info("Cell HO: Reconfiguring cell\n"); - if (set_cell()) { - Info("Cell HO: Synchronizing with new cell\n"); - //resync_sfn(true, true); - sfn_p.reset(); - phy_state = CELL_RESELECT; - ret = true; + phy_state = IDLE_RX; + cnt = 0; + while(!is_in_idle_rx && cnt<20) { + usleep(1000); + cnt++; + } + if (is_in_idle_rx) { + Info("Cell HO: Reconfiguring cell\n"); + if (set_cell()) { + //resync_sfn(true, true); + sfn_p.reset(); + phy_state = CELL_RESELECT; + Info("Cell HO: Synchronizing with new cell\n"); + ret = true; + } else { + log_h->error("Cell HO: Configuring cell PCI=%d\n", cell.id); + ret = false; + } } else { - log_h->error("Cell HO: Configuring cell PCI=%d\n", cell.id); + log_h->error("Cell HO: Could not stop sync\n"); ret = false; } return ret; @@ -574,6 +584,7 @@ void phch_recv::run_thread() uint32_t sf_idx = 0; phy_state = IDLE; is_in_idle = true; + is_in_idle_rx = false; while (running) { @@ -582,6 +593,10 @@ void phch_recv::run_thread() Debug("SYNC: state=%d\n", phy_state); } + if (phy_state != IDLE_RX) { + is_in_idle_rx = false; + } + log_h->step(tti); log_phy_lib_h->step(tti); @@ -746,6 +761,23 @@ void phch_recv::run_thread() is_in_idle = true; usleep(1000); break; + case IDLE_RX: + if (!worker) { + worker = (phch_worker *) workers_pool->wait_worker(tti); + } + is_in_idle_rx = true; + if (worker) { + for (uint32_t i = 0; i < SRSLTE_MAX_PORTS; i++) { + buffer[i] = worker->get_buffer(i); + } + if (!radio_h->rx_now(buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb), NULL)) { + Error("SYNC: Receiving from radio while in IDLE_RX\n"); + } + } else { + // wait_worker() only returns NULL if it's being closed. Quit now to avoid unnecessary loops here + running = false; + } + break; } // Increase TTI counter and trigger MAC clock (lower priority) From c5ffdfe8c74bf3d06f393783c6e1847888bc791e Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 21:31:11 +0100 Subject: [PATCH 60/74] set byte_buffer ptr to null after deallocating from pool --- lib/include/srslte/common/buffer_pool.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index a4186a78b..e48144b6f 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -164,6 +164,7 @@ public: } b->reset(); pool->deallocate(b); + b = NULL; } private: buffer_pool *pool; From 1be93d4682baa5e2a166ebc940f894e68354ac16 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 21:32:21 +0100 Subject: [PATCH 61/74] add RLC UM destructor --- lib/include/srslte/upper/rlc_um.h | 1 + lib/src/upper/rlc_um.cc | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/include/srslte/upper/rlc_um.h b/lib/include/srslte/upper/rlc_um.h index 0a2469a7c..6d8eb6d08 100644 --- a/lib/include/srslte/upper/rlc_um.h +++ b/lib/include/srslte/upper/rlc_um.h @@ -50,6 +50,7 @@ class rlc_um { public: rlc_um(); + ~rlc_um(); void init(log *rlc_entity_log_, uint32_t lcid_, diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 213e8c840..a365a4501 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -59,6 +59,11 @@ rlc_um::rlc_um() : tx_sdu_queue(16) pdu_lost = false; } +rlc_um::~rlc_um() +{ + stop(); +} + void rlc_um::init(srslte::log *log_, uint32_t lcid_, srsue::pdcp_interface_rlc *pdcp_, @@ -114,12 +119,13 @@ void rlc_um::empty_queue() { void rlc_um::stop() { reset(); - mac_timers->timer_release_id(reordering_timer_id); + if (mac_timers) { + mac_timers->timer_release_id(reordering_timer_id); + } } void rlc_um::reset() { - // Empty tx_sdu_queue before locking the mutex empty_queue(); @@ -129,12 +135,17 @@ void rlc_um::reset() vr_ux = 0; vr_uh = 0; pdu_lost = false; - if(rx_sdu) - rx_sdu->reset(); - if(tx_sdu) - tx_sdu->reset(); - if(mac_timers) + if(rx_sdu) { + pool->deallocate(rx_sdu); + } + + if(tx_sdu) { + pool->deallocate(tx_sdu); + } + + if(mac_timers) { reordering_timer->stop(); + } // Drop all messages in RX window std::map::iterator it; From a6ccb05bb107bb91a2eeeb95b00c384d1d627968 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 16 Feb 2018 21:32:53 +0100 Subject: [PATCH 62/74] fix mem leak in RLC UM test and RLC AM stress tester --- lib/test/upper/rlc_am_stress_test.cc | 1 + lib/test/upper/rlc_um_test.cc | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/test/upper/rlc_am_stress_test.cc b/lib/test/upper/rlc_am_stress_test.cc index 086a41bd8..137236b4a 100644 --- a/lib/test/upper/rlc_am_stress_test.cc +++ b/lib/test/upper/rlc_am_stress_test.cc @@ -85,6 +85,7 @@ private: usleep(100); } running = false; + byte_buffer_pool::get_instance()->deallocate(pdu); } rlc_interface_mac *rlc1; diff --git a/lib/test/upper/rlc_um_test.cc b/lib/test/upper/rlc_um_test.cc index 6ce39ef7f..3755c1174 100644 --- a/lib/test/upper/rlc_um_test.cc +++ b/lib/test/upper/rlc_um_test.cc @@ -62,6 +62,14 @@ public: n_sdus = 0; } + ~rlc_um_tester(){ + for (uint32_t i = 0; i < NBUFS; i++) { + if (sdus[i] != NULL) { + byte_buffer_pool::get_instance()->deallocate(sdus[i]); + } + } + } + // PDCP interface void write_pdu(uint32_t lcid, byte_buffer_t *sdu) { From f8303acba7b6131b1d057efa164ce5876af3033f Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Sat, 17 Feb 2018 21:37:48 +0100 Subject: [PATCH 63/74] Fixed memory leak in logger_stdout --- lib/include/srslte/common/logger_stdout.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/include/srslte/common/logger_stdout.h b/lib/include/srslte/common/logger_stdout.h index 00e4ffa7a..b76faadaf 100644 --- a/lib/include/srslte/common/logger_stdout.h +++ b/lib/include/srslte/common/logger_stdout.h @@ -42,7 +42,10 @@ namespace srslte { { public: void log(std::string *msg) { - fprintf(stdout, "%s", msg->c_str()); + if (msg) { + fprintf(stdout, "%s", msg->c_str()); + delete msg; + } } }; From d959608e10373c83fa4a6284448425cfccf71459 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 20 Feb 2018 11:44:46 +0100 Subject: [PATCH 64/74] fix mem dealloc in viterbi for 16bit AVX --- lib/src/phy/fec/viterbi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/src/phy/fec/viterbi.c b/lib/src/phy/fec/viterbi.c index 25d77ef36..4e5801b94 100644 --- a/lib/src/phy/fec/viterbi.c +++ b/lib/src/phy/fec/viterbi.c @@ -166,9 +166,15 @@ void free37_avx2_16bit(void *o) { if (q->symbols_uc) { free(q->symbols_uc); } + if (q->symbols_us) { + free(q->symbols_us); + } if (q->tmp) { free(q->tmp); } + if (q->tmp_s) { + free(q->tmp_s); + } delete_viterbi37_avx2_16bit(q->ptr); } From 94fe9d4a4710dc09a41bcb0e4844f59923d4fb35 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 20 Feb 2018 12:27:02 +0100 Subject: [PATCH 65/74] rlc: add basic RLC AM reset test --- lib/test/upper/rlc_am_test.cc | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index 184de3a00..67305c093 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -1056,6 +1056,60 @@ void resegment_test_6() } } +void reset_test() +{ + srslte::log_filter log1("RLC_AM_1"); + srslte::log_filter log2("RLC_AM_2"); + log1.set_level(srslte::LOG_LEVEL_DEBUG); + log2.set_level(srslte::LOG_LEVEL_DEBUG); + log1.set_hex_limit(-1); + log2.set_hex_limit(-1); + rlc_am_tester tester; + mac_dummy_timers timers; + + rlc_am rlc1; + int len; + + log1.set_level(srslte::LOG_LEVEL_DEBUG); + + rlc1.init(&log1, 1, &tester, &tester, &timers); + + LIBLTE_RRC_RLC_CONFIG_STRUCT cnfg; + cnfg.rlc_mode = LIBLTE_RRC_RLC_MODE_AM; + cnfg.dl_am_rlc.t_reordering = LIBLTE_RRC_T_REORDERING_MS5; + cnfg.dl_am_rlc.t_status_prohibit = LIBLTE_RRC_T_STATUS_PROHIBIT_MS5; + cnfg.ul_am_rlc.max_retx_thresh = LIBLTE_RRC_MAX_RETX_THRESHOLD_T4; + cnfg.ul_am_rlc.poll_byte = LIBLTE_RRC_POLL_BYTE_KB25; + cnfg.ul_am_rlc.poll_pdu = LIBLTE_RRC_POLL_PDU_P4; + cnfg.ul_am_rlc.t_poll_retx = LIBLTE_RRC_T_POLL_RETRANSMIT_MS5; + + rlc1.configure(&cnfg); + + // Push 1 SDU of size 10 into RLC1 + byte_buffer_t sdu_buf; + *sdu_buf.msg = 1; // Write the index into the buffer + sdu_buf.N_bytes = 100; + rlc1.write_sdu(&sdu_buf); + + // read 1 PDU from RLC1 and force segmentation + byte_buffer_t pdu_bufs; + len = rlc1.read_pdu(pdu_bufs.msg, 4); + pdu_bufs.N_bytes = len; + + // reset RLC1 + rlc1.reset(); + + // read another PDU segment from RLC1 + len = rlc1.read_pdu(pdu_bufs.msg, 4); + pdu_bufs.N_bytes = len; + + // now empty RLC buffer + len = rlc1.read_pdu(pdu_bufs.msg, 100); + pdu_bufs.N_bytes = len; + + assert(0 == rlc1.get_buffer_state()); +} + int main(int argc, char **argv) { basic_test(); byte_buffer_pool::get_instance()->cleanup(); @@ -1086,4 +1140,7 @@ int main(int argc, char **argv) { resegment_test_6(); byte_buffer_pool::get_instance()->cleanup(); + + reset_test(); + byte_buffer_pool::get_instance()->cleanup(); } From 8d852ddfe5e4f6eedb80e247d62b8628f9643c2f Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 20 Feb 2018 17:54:09 +0100 Subject: [PATCH 66/74] only reset SDU buffer in RLC AM/UM --- lib/src/upper/rlc_am.cc | 8 -------- lib/src/upper/rlc_um.cc | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 652970011..b34b0cb0b 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -72,14 +72,6 @@ rlc_am::~rlc_am() { // reset RLC and dealloc SDUs stop(); - - if(rx_sdu) { - pool->deallocate(rx_sdu); - } - - if(tx_sdu) { - pool->deallocate(tx_sdu); - } } void rlc_am::init(srslte::log *log_, diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index a365a4501..3fbcbaadf 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -136,11 +136,11 @@ void rlc_um::reset() vr_uh = 0; pdu_lost = false; if(rx_sdu) { - pool->deallocate(rx_sdu); + rx_sdu->reset(); } if(tx_sdu) { - pool->deallocate(tx_sdu); + tx_sdu->reset(); } if(mac_timers) { From f6a17d118265f0ce3e40a390e521d6207a76dfe3 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 16 Feb 2018 12:05:45 +0100 Subject: [PATCH 67/74] Logs to test snr drop issue --- srsue/hdr/phy/phch_worker.h | 3 +++ srsue/src/phy/phch_recv.cc | 5 +++-- srsue/src/phy/phch_worker.cc | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/srsue/hdr/phy/phch_worker.h b/srsue/hdr/phy/phch_worker.h index c154ff514..78389ccf7 100644 --- a/srsue/hdr/phy/phch_worker.h +++ b/srsue/hdr/phy/phch_worker.h @@ -70,6 +70,9 @@ public: void start_plot(); float get_ref_cfo(); + float get_snr(); + float get_rsrp(); + float get_noise(); float get_cfo(); float get_ul_cfo(); diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index bf09f5f34..80c972266 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -675,10 +675,11 @@ void phch_recv::run_thread() case 1: if (last_worker) { - Debug("SF: cfo_tot=%7.1f Hz, ref=%f Hz, pss=%f Hz\n", + Info("SF: cfo_tot=%7.1f Hz, ref=%f Hz, pss=%f Hz, snr_sf=%.2f dB, rsrp=%.2f dB, noise=%.2f dB\n", srslte_ue_sync_get_cfo(&ue_sync), 15000*last_worker->get_ref_cfo(), - 15000*ue_sync.strack.cfo_pss_mean); + 15000*ue_sync.strack.cfo_pss_mean, + last_worker->get_snr(), last_worker->get_rsrp(), last_worker->get_noise()); } last_worker = worker; diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index f7e1381f8..e6fb7f35a 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -203,6 +203,22 @@ float phch_worker::get_ref_cfo() return srslte_chest_dl_get_cfo(&ue_dl.chest); } +float phch_worker::get_snr() +{ + return 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest)); +} + +float phch_worker::get_rsrp() +{ + return 10*log10(srslte_chest_dl_get_rsrp(&ue_dl.chest)); +} + +float phch_worker::get_noise() +{ + return 10*log10(srslte_chest_dl_get_noise_estimate(&ue_dl.chest)); +} + + float phch_worker::get_cfo() { return cfo; From d250dd51ad88f3e026c8e1d661841c869f229236 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 21 Feb 2018 11:51:08 +0100 Subject: [PATCH 68/74] Reduce LO leakage by not transmit signal on idle --- srsue/src/phy/phch_common.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srsue/src/phy/phch_common.cc b/srsue/src/phy/phch_common.cc index b76b0d9ce..24c190361 100644 --- a/srsue/src/phy/phch_common.cc +++ b/srsue/src/phy/phch_common.cc @@ -62,9 +62,10 @@ phch_common::phch_common(uint32_t max_mutex_) : tx_mutex(max_mutex_) bzero(zeros, 50000*sizeof(cf_t)); // FIXME: This is an ugly fix to avoid the TX filters to empty + /* for (int i=0;i<50000;i++) { zeros[i] = 0.01*cexpf(((float) i/50000)*0.1*_Complex_I); - } + }*/ reset(); From 3a005af9f5356ada066a2f6c9dc4863afda6199e Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 21 Feb 2018 11:51:26 +0100 Subject: [PATCH 69/74] Normalize PUCCH power --- lib/src/phy/ue/ue_ul.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/phy/ue/ue_ul.c b/lib/src/phy/ue/ue_ul.c index 5cf913bfa..b3842d0b7 100644 --- a/lib/src/phy/ue/ue_ul.c +++ b/lib/src/phy/ue/ue_ul.c @@ -355,7 +355,7 @@ int srslte_ue_ul_pucch_encode(srslte_ue_ul_t *q, srslte_uci_data_t uci_data, } if (q->normalize_en) { - float norm_factor = (float) 0.8*q->cell.nof_prb/5; + float norm_factor = (float) q->cell.nof_prb/15/10; srslte_vec_sc_prod_cfc(output_signal, norm_factor, output_signal, SRSLTE_SF_LEN_PRB(q->cell.nof_prb)); } ret = SRSLTE_SUCCESS; From 56df710d1f3b9d84d18252cd169f0af98cd5398a Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 21 Feb 2018 11:51:55 +0100 Subject: [PATCH 70/74] Add rx_gain_offset interface for RSRP calibration --- lib/include/srslte/interfaces/ue_interfaces.h | 1 + srsue/src/main.cc | 6 +++++- srsue/src/phy/phch_recv.cc | 2 +- srsue/src/phy/phch_worker.cc | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index 454a18039..00b61fa1c 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -492,6 +492,7 @@ typedef struct { float estimator_fil_w; bool rssi_sensor_enabled; bool sic_pss_enabled; + float rx_gain_offset; } phy_args_t; diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 4119b9f78..e76891796 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -162,7 +162,11 @@ void parse_args(all_args_t *args, int argc, char *argv[]) { bpo::value(&args->expert.phy.rssi_sensor_enabled)->default_value(true), "Enable or disable RF frontend RSSI sensor. In some USRP devices can cause segmentation fault") - ("expert.prach_gain", + ("expert.rx_gain_offset", + bpo::value(&args->expert.phy.rx_gain_offset)->default_value(10), + "RX Gain offset to add to rx_gain to correct RSRP value") + + ("expert.prach_gain", bpo::value(&args->expert.phy.prach_gain)->default_value(-1.0), "Disable PRACH power control") diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 80c972266..7e6498157 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -675,7 +675,7 @@ void phch_recv::run_thread() case 1: if (last_worker) { - Info("SF: cfo_tot=%7.1f Hz, ref=%f Hz, pss=%f Hz, snr_sf=%.2f dB, rsrp=%.2f dB, noise=%.2f dB\n", + Debug("SF: cfo_tot=%7.1f Hz, ref=%f Hz, pss=%f Hz, snr_sf=%.2f dB, rsrp=%.2f dB, noise=%.2f dB\n", srslte_ue_sync_get_cfo(&ue_sync), 15000*last_worker->get_ref_cfo(), 15000*ue_sync.strack.cfo_pss_mean, diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index e6fb7f35a..b6878e6d8 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -1386,7 +1386,7 @@ void phch_worker::update_measurements() phy->last_radio_rssi = phy->get_radio()->get_rssi(); phy->rx_gain_offset = phy->avg_rssi_dbm - phy->last_radio_rssi + 30; } else { - phy->rx_gain_offset = phy->get_radio()->get_rx_gain(); + phy->rx_gain_offset = phy->get_radio()->get_rx_gain() + phy->args->rx_gain_offset; } } rssi_read_cnt++; From ff5ac85c7d09d0050fd61c4e0a41bca8a68a2e25 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 21 Feb 2018 14:50:41 +0100 Subject: [PATCH 71/74] Added int16 to float SIMD vector function --- lib/include/srslte/phy/utils/vector_simd.h | 2 ++ lib/src/phy/utils/test/vector_test.c | 25 +++++++++++++++++ lib/src/phy/utils/vector.c | 5 +--- lib/src/phy/utils/vector_simd.c | 32 +++++++++++++++++++++- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/lib/include/srslte/phy/utils/vector_simd.h b/lib/include/srslte/phy/utils/vector_simd.h index 49268ca43..8139d0e78 100644 --- a/lib/include/srslte/phy/utils/vector_simd.h +++ b/lib/include/srslte/phy/utils/vector_simd.h @@ -120,6 +120,8 @@ SRSLTE_API void srslte_vec_abs_square_cf_simd(const cf_t *x, float *z, const int /* Other Functions */ SRSLTE_API void srslte_vec_lut_sss_simd(const short *x, const unsigned short *lut, short *y, const int len); +SRSLTE_API void srslte_vec_convert_if_simd(const int16_t *x, float *z, const float scale, const int len); + SRSLTE_API void srslte_vec_convert_fi_simd(const float *x, int16_t *z, const float scale, const int len); SRSLTE_API void srslte_vec_cp_simd(const cf_t *src, cf_t *dst, int len); diff --git a/lib/src/phy/utils/test/vector_test.c b/lib/src/phy/utils/test/vector_test.c index ebda516ea..f0b954bad 100644 --- a/lib/src/phy/utils/test/vector_test.c +++ b/lib/src/phy/utils/test/vector_test.c @@ -452,6 +452,28 @@ TEST(srslte_vec_convert_fi, free(z); ) +TEST(srslte_vec_convert_if, + MALLOC(int16_t, x); + MALLOC(float, z); + float scale = 1000.0f; + + float gold; + float k = 1.0f/scale; + for (int i = 0; i < block_size; i++) { + x[i] = (int16_t) RANDOM_S(); + } + + TEST_CALL(srslte_vec_convert_if(x, scale, z, block_size)) + + for (int i = 0; i < block_size; i++) { + gold = ((float)x[i]) * k; + mse += fabsf(gold - z[i]); + } + + free(x); + free(z); +) + TEST(srslte_vec_prod_fff, MALLOC(float, x); MALLOC(float, y); @@ -753,6 +775,9 @@ int main(int argc, char **argv) { passed[func_count][size_count] = test_srslte_vec_convert_fi(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; + passed[func_count][size_count] = test_srslte_vec_convert_if(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; + passed[func_count][size_count] = test_srslte_vec_prod_fff(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; diff --git a/lib/src/phy/utils/vector.c b/lib/src/phy/utils/vector.c index 195ac98cb..b97583bb8 100644 --- a/lib/src/phy/utils/vector.c +++ b/lib/src/phy/utils/vector.c @@ -93,10 +93,7 @@ void srslte_vec_sc_prod_ccc(const cf_t *x, const cf_t h, cf_t *z, const uint32_t // Used in turbo decoder void srslte_vec_convert_if(const int16_t *x, const float scale, float *z, const uint32_t len) { - int i; - for (i=0;i Date: Mon, 19 Feb 2018 19:15:38 +0100 Subject: [PATCH 72/74] UE stores last PMI and last RI in common phy --- lib/src/phy/ue/ue_dl.c | 12 ++++++------ srsue/hdr/phy/phch_common.h | 3 +++ srsue/src/phy/phch_common.cc | 2 ++ srsue/src/phy/phch_worker.cc | 35 +++++++++++++++++------------------ 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/src/phy/ue/ue_dl.c b/lib/src/phy/ue/ue_dl.c index 491e676bf..3815041a7 100644 --- a/lib/src/phy/ue/ue_dl.c +++ b/lib/src/phy/ue/ue_dl.c @@ -460,15 +460,15 @@ int srslte_ue_dl_cfg_grant(srslte_ue_dl_t *q, srslte_ra_dl_grant_t *grant, uint3 pmi = grant->pinfo - 1; } else { ERROR("Not Implemented (nof_tb=%d, pinfo=%d)", nof_tb, grant->pinfo); - return SRSLTE_ERROR; + pmi = grant->pinfo % 4; } } else { - if (grant->pinfo < 2) { - pmi = grant->pinfo; - } else { - ERROR("Not Implemented (nof_tb=%d, pinfo=%d)", nof_tb, grant->pinfo); - return SRSLTE_ERROR; + if (grant->pinfo == 2) { + ERROR("Not implemented codebook index (nof_tb=%d, pinfo=%d)", nof_tb, grant->pinfo); + } else if (grant->pinfo > 2) { + ERROR("Reserved codebook index (nof_tb=%d, pinfo=%d)", nof_tb, grant->pinfo); } + pmi = grant->pinfo % 2; } } if(SRSLTE_SF_MBSFN == grant->sf_type) { diff --git a/srsue/hdr/phy/phch_common.h b/srsue/hdr/phy/phch_common.h index 31bf06122..f21738b6b 100644 --- a/srsue/hdr/phy/phch_common.h +++ b/srsue/hdr/phy/phch_common.h @@ -87,6 +87,9 @@ public: uint32_t last_ul_tti[2*HARQ_DELAY_MS]; srslte_mod_t last_ul_mod[2*HARQ_DELAY_MS]; + uint8_t last_ri; + uint8_t last_pmi; + phch_common(uint32_t max_mutex = 3); void init(phy_interface_rrc::phy_cfg_t *config, phy_args_t *args, diff --git a/srsue/src/phy/phch_common.cc b/srsue/src/phy/phch_common.cc index 24c190361..65681c8c6 100644 --- a/srsue/src/phy/phch_common.cc +++ b/srsue/src/phy/phch_common.cc @@ -48,6 +48,8 @@ phch_common::phch_common(uint32_t max_mutex_) : tx_mutex(max_mutex_) max_mutex = max_mutex_; nof_mutex = 0; rx_gain_offset = 0; + last_ri = 0; + last_pmi = 0; bzero(&dl_metrics, sizeof(dl_metrics_t)); dl_metrics_read = true; diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index b6878e6d8..6a533759b 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -890,19 +890,20 @@ void phch_worker::set_uci_periodic_cqi() int cqi_fixed = phy->args->cqi_fixed; int cqi_max = phy->args->cqi_max; - uint8_t ri = (uint8_t) ue_dl.ri; - uint8_t pmi = (uint8_t) ue_dl.pmi[ri]; - float sinr = ue_dl.sinr[ri][pmi]; + float sinr = ue_dl.sinr[phy->last_ri & SRSLTE_MAX_LAYERS][phy->last_pmi % SRSLTE_MAX_CODEBOOKS]; if (period_cqi.configured && rnti_is_set) { if (period_cqi.ri_idx_present && srslte_ri_send(period_cqi.pmi_idx, period_cqi.ri_idx, TTI_TX(tti))) { /* Compute RI, PMI and SINR */ - compute_ri(&ri, &pmi, &sinr); - uci_data.uci_ri = ri; + compute_ri(&phy->last_ri, &phy->last_pmi, &sinr); + uci_data.uci_ri = phy->last_ri; uci_data.uci_ri_len = 1; uci_data.ri_periodic_report = true; - Debug("PUCCH: Periodic ri=%d\n", ri); + Debug("PUCCH: Periodic ri=%d, SINR=%.1f\n", phy->last_ri, sinr); } else if (srslte_cqi_send(period_cqi.pmi_idx, TTI_TX(tti))) { + compute_ri(NULL, NULL, NULL); + phy->last_pmi = (uint8_t) ue_dl.pmi[phy->last_ri % SRSLTE_MAX_LAYERS]; + srslte_cqi_value_t cqi_report = {0}; if (period_cqi.format_is_subband) { // TODO: Implement subband periodic reports @@ -923,8 +924,8 @@ void phch_worker::set_uci_periodic_cqi() } if (phy->config->dedicated.antenna_info_explicit_value.tx_mode == LIBLTE_RRC_TRANSMISSION_MODE_4) { cqi_report.wideband.pmi_present = true; - cqi_report.wideband.pmi = pmi; - cqi_report.wideband.rank_is_not_one = (ri != 0); + cqi_report.wideband.pmi = phy->last_pmi; + cqi_report.wideband.rank_is_not_one = (phy->last_ri != 0); } Debug("PUCCH: Periodic CQI=%d, SNR=%.1f dB\n", cqi_report.wideband.wideband_cqi, phy->avg_snr_db); } @@ -936,13 +937,11 @@ void phch_worker::set_uci_periodic_cqi() void phch_worker::set_uci_aperiodic_cqi() { - uint8_t ri = (uint8_t) ue_dl.ri; - uint8_t pmi = (uint8_t) ue_dl.pmi[ri]; - float sinr_db = ue_dl.sinr[ri][pmi]; + float sinr_db = ue_dl.sinr[phy->last_ri % SRSLTE_MAX_LAYERS][phy->last_pmi%SRSLTE_MAX_CODEBOOKS]; if (phy->config->dedicated.cqi_report_cnfg.report_mode_aperiodic_present) { /* Compute RI, PMI and SINR */ - compute_ri(&ri, &pmi, &sinr_db); + compute_ri(&phy->last_ri, &phy->last_pmi, &sinr_db); switch(phy->config->dedicated.cqi_report_cnfg.report_mode_aperiodic) { case LIBLTE_RRC_CQI_REPORT_MODE_APERIODIC_RM30: @@ -977,7 +976,7 @@ void phch_worker::set_uci_aperiodic_cqi() /* Set RI = 1 */ if (phy->config->dedicated.antenna_info_explicit_value.tx_mode == LIBLTE_RRC_TRANSMISSION_MODE_3 || phy->config->dedicated.antenna_info_explicit_value.tx_mode == LIBLTE_RRC_TRANSMISSION_MODE_4) { - uci_data.uci_ri = ri; + uci_data.uci_ri = phy->last_ri; uci_data.uci_ri_len = 1; } else { uci_data.uci_ri_len = 0; @@ -1007,13 +1006,13 @@ void phch_worker::set_uci_aperiodic_cqi() cqi_report.subband_hl.wideband_cqi_cw0 = srslte_cqi_from_snr(sinr_db); cqi_report.subband_hl.subband_diff_cqi_cw0 = 0; // Always report zero offset on all subbands - if (ri > 0) { + if (phy->last_ri > 0) { cqi_report.subband_hl.rank_is_not_one = true; cqi_report.subband_hl.wideband_cqi_cw1 = srslte_cqi_from_snr(sinr_db); cqi_report.subband_hl.subband_diff_cqi_cw1 = 0; // Always report zero offset on all subbands } - cqi_report.subband_hl.pmi = pmi; + cqi_report.subband_hl.pmi = phy->last_pmi; cqi_report.subband_hl.pmi_present = true; cqi_report.subband_hl.four_antenna_ports = (cell.nof_ports == 4); @@ -1027,7 +1026,7 @@ void phch_worker::set_uci_aperiodic_cqi() } uci_data.uci_cqi_len = (uint32_t) cqi_len; uci_data.uci_ri_len = 1; - uci_data.uci_ri = ri; + uci_data.uci_ri = phy->last_ri; char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = {0}; srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); @@ -1035,11 +1034,11 @@ void phch_worker::set_uci_aperiodic_cqi() if (cqi_report.subband_hl.rank_is_not_one) { Info("PUSCH: Aperiodic RM31 ri~1, CQI=%02d/%02d, SINR=%2.1f/%2.1fdB, pmi=%d for %d subbands\n", cqi_report.subband_hl.wideband_cqi_cw0, cqi_report.subband_hl.wideband_cqi_cw1, - sinr_db, sinr_db, pmi, cqi_report.subband_hl.N); + sinr_db, sinr_db, phy->last_pmi, cqi_report.subband_hl.N); } else { Info("PUSCH: Aperiodic RM31 ri=1, CQI=%02d, SINR=%2.1f, pmi=%d for %d subbands\n", cqi_report.subband_hl.wideband_cqi_cw0, - sinr_db, pmi, cqi_report.subband_hl.N); + sinr_db, phy->last_pmi, cqi_report.subband_hl.N); } } break; From 2c8467780dbf447e0139655db63e8a409fd07898 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 21 Feb 2018 16:15:51 +0100 Subject: [PATCH 73/74] UE stores last PMI and last RI in common phy --- lib/include/srslte/phy/utils/vector_simd.h | 2 ++ lib/src/phy/utils/test/vector_test.c | 37 ++++++++++++++++++---- lib/src/phy/utils/vector.c | 5 +-- lib/src/phy/utils/vector_simd.c | 32 ++++++++++++++++++- 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/lib/include/srslte/phy/utils/vector_simd.h b/lib/include/srslte/phy/utils/vector_simd.h index 49268ca43..8139d0e78 100644 --- a/lib/include/srslte/phy/utils/vector_simd.h +++ b/lib/include/srslte/phy/utils/vector_simd.h @@ -120,6 +120,8 @@ SRSLTE_API void srslte_vec_abs_square_cf_simd(const cf_t *x, float *z, const int /* Other Functions */ SRSLTE_API void srslte_vec_lut_sss_simd(const short *x, const unsigned short *lut, short *y, const int len); +SRSLTE_API void srslte_vec_convert_if_simd(const int16_t *x, float *z, const float scale, const int len); + SRSLTE_API void srslte_vec_convert_fi_simd(const float *x, int16_t *z, const float scale, const int len); SRSLTE_API void srslte_vec_cp_simd(const cf_t *src, cf_t *dst, int len); diff --git a/lib/src/phy/utils/test/vector_test.c b/lib/src/phy/utils/test/vector_test.c index ebda516ea..55ff2944e 100644 --- a/lib/src/phy/utils/test/vector_test.c +++ b/lib/src/phy/utils/test/vector_test.c @@ -452,6 +452,28 @@ TEST(srslte_vec_convert_fi, free(z); ) +TEST(srslte_vec_convert_if, + MALLOC(int16_t, x); + MALLOC(float, z); + float scale = 1000.0f; + + float gold; + float k = 1.0f/scale; + for (int i = 0; i < block_size; i++) { + x[i] = (int16_t) RANDOM_S(); + } + + TEST_CALL(srslte_vec_convert_if(x, scale, z, block_size)) + + for (int i = 0; i < block_size; i++) { + gold = ((float)x[i]) * k; + mse += fabsf(gold - z[i]); + } + + free(x); + free(z); +) + TEST(srslte_vec_prod_fff, MALLOC(float, x); MALLOC(float, y); @@ -596,7 +618,7 @@ TEST(srslte_vec_div_ccc, for (int i = 0; i < block_size; i++) { gold = x[i] / y[i]; - mse += cabsf(gold - z[i]); + mse += cabsf(gold - z[i]) / cabsf(gold); } mse /= block_size; @@ -614,14 +636,14 @@ TEST(srslte_vec_div_cfc, cf_t gold; for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); - y[i] = RANDOM_F(); + y[i] = RANDOM_F() + 0.0001f; } TEST_CALL(srslte_vec_div_cfc(x, y, z, block_size)) for (int i = 0; i < block_size; i++) { gold = x[i] / y[i]; - mse += cabsf(gold - z[i])/cabsf(gold); + mse += cabsf(gold - z[i]) / cabsf(gold); } mse /= block_size; @@ -638,15 +660,15 @@ TEST(srslte_vec_div_fff, cf_t gold; for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_F() + 0.0001; - y[i] = RANDOM_F()+ 0.0001; + x[i] = RANDOM_F(); + y[i] = RANDOM_F() + 0.0001f; } TEST_CALL(srslte_vec_div_fff(x, y, z, block_size)) for (int i = 0; i < block_size; i++) { gold = x[i] / y[i]; - mse += cabsf(gold - z[i]); + mse += cabsf(gold - z[i]) / cabsf(gold); } mse /= block_size; @@ -753,6 +775,9 @@ int main(int argc, char **argv) { passed[func_count][size_count] = test_srslte_vec_convert_fi(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; + passed[func_count][size_count] = test_srslte_vec_convert_if(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; + passed[func_count][size_count] = test_srslte_vec_prod_fff(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; diff --git a/lib/src/phy/utils/vector.c b/lib/src/phy/utils/vector.c index 195ac98cb..b97583bb8 100644 --- a/lib/src/phy/utils/vector.c +++ b/lib/src/phy/utils/vector.c @@ -93,10 +93,7 @@ void srslte_vec_sc_prod_ccc(const cf_t *x, const cf_t h, cf_t *z, const uint32_t // Used in turbo decoder void srslte_vec_convert_if(const int16_t *x, const float scale, float *z, const uint32_t len) { - int i; - for (i=0;i Date: Thu, 22 Feb 2018 12:13:53 +0100 Subject: [PATCH 74/74] Stop RX stream when cell not found during initial cell search --- lib/src/phy/rf/rf_utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/phy/rf/rf_utils.c b/lib/src/phy/rf/rf_utils.c index 4587ebdcb..f12054e9d 100644 --- a/lib/src/phy/rf/rf_utils.c +++ b/lib/src/phy/rf/rf_utils.c @@ -186,9 +186,11 @@ int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas, ret = srslte_ue_cellsearch_scan(&cs, found_cells, &max_peak_cell); } if (ret < 0) { + srslte_rf_stop_rx_stream(rf); fprintf(stderr, "Error searching cell\n"); return SRSLTE_ERROR; } else if (ret == 0) { + srslte_rf_stop_rx_stream(rf); fprintf(stderr, "Could not find any cell in this frequency\n"); return SRSLTE_SUCCESS; }