diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/mac_params.h b/srsapps/ue/mac/include/srsapps/ue/mac/mac_params.h index b8e550fab..7edceb904 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/mac_params.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/mac_params.h @@ -81,8 +81,6 @@ namespace ue { RA_CONTENTIONTIMER, SR_PUCCH_CONFIGURED, - SR_PUCCH_RESINDEX, - SR_CONFIG_INDEX, SR_TRANS_MAX, HARQ_MAXTX, diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/proc_bsr.h b/srsapps/ue/mac/include/srsapps/ue/mac/proc_bsr.h index 309a173cc..e01f1d5a8 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/proc_bsr.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/proc_bsr.h @@ -30,6 +30,7 @@ #include #include "srsapps/ue/mac/proc.h" +#include "srsapps/ue/mac/mux.h" #ifndef PROCBSR_H #define PROCBSR_H @@ -42,14 +43,17 @@ namespace ue { class bsr_proc : public proc { public: - void step(uint32_t tti) { - if (is_running()) { - fprintf(stderr, "BSR procedure not implemented\n"); - } - } - void reset() { - - } + bsr_proc(); + void init(log *log_h, mac_params *params_db, mux *mux_unit_); + void step(uint32_t tti); + void reset(); + void start(); +private: + bool is_pending_sr; + mac_params *params_db; + mux *mux_unit; + log *log_h; + bool initiated; }; } diff --git a/srsapps/ue/mac/src/proc_bsr.c b/srsapps/ue/mac/src/proc_bsr.c new file mode 100644 index 000000000..e5adca60d --- /dev/null +++ b/srsapps/ue/mac/src/proc_bsr.c @@ -0,0 +1,65 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2015 The srsLTE Developers. See the + * COPYRIGHT file at the top-level directory of this distribution. + * + * \section LICENSE + * + * This file is part of the srsLTE library. + * + * srsLTE 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. + * + * srsLTE 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 "srsapps/ue/mac/proc_bsr.h" +#include "srsapps/ue/mac/mac_params.h" + +namespace srslte { + namespace ue { + +bsr_proc::bsr_proc() +{ + initiated = false; +} + + +void bsr_proc::init(log* log_h_, mac_params* params_db_, mux *mux_unit_) +{ + log_h = log_h; + params_db = params_db_; + mux_unit = mux_unit_; + initiated = true; +} + +void bsr_proc::reset() +{ + +} + +void bsr_proc::start() +{ + +} +void bsr_proc::step(uint32_t tti) +{ + if (!initiated) { + return; + } +} + + } +} diff --git a/srsapps/ue/mac/src/proc_sr.cc b/srsapps/ue/mac/src/proc_sr.cc index e31451ddc..c0723beb0 100644 --- a/srsapps/ue/mac/src/proc_sr.cc +++ b/srsapps/ue/mac/src/proc_sr.cc @@ -47,6 +47,7 @@ void sr_proc::init(log* log_h_, mac_params* params_db_, phy* phy_h_) void sr_proc::reset() { is_pending_sr = false; + phy_h->send_sr(false); } void sr_proc::step(uint32_t tti) @@ -55,7 +56,7 @@ void sr_proc::step(uint32_t tti) if (is_pending_sr) { if (sr_counter < dsr_transmax) { sr_counter++; - phy_h->get_ul_buffer(tti+4)->generate_sr(); + phy_h->send_sr(true); } else { reset(); } diff --git a/srsapps/ue/mac/test/mac_test.cc b/srsapps/ue/mac/test/mac_test.cc index b4238d45f..9e7edc475 100644 --- a/srsapps/ue/mac/test/mac_test.cc +++ b/srsapps/ue/mac/test/mac_test.cc @@ -200,14 +200,16 @@ void setup_mac_phy_sib2(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT *sib2, srslte::u void process_connsetup(LIBLTE_RRC_CONNECTION_SETUP_STRUCT *msg, srslte::ue::mac *mac, srslte::ue::phy *phy) { mac->set_param(srslte::ue::mac_params::HARQ_MAXTX, liblte_rrc_max_harq_tx_num[msg->rr_cnfg.mac_main_cnfg.explicit_value.ulsch_cnfg.max_harq_tx]); - - mac->set_param(srslte::ue::mac_params::SR_PUCCH_RESINDEX, + + phy->set_param(srslte::ue::phy_params::SR_PUCCH_RESINDEX, msg->rr_cnfg.phy_cnfg_ded.sched_request_cnfg.sr_pucch_resource_idx); - mac->set_param(srslte::ue::mac_params::SR_CONFIG_INDEX, + phy->set_param(srslte::ue::phy_params::SR_CONFIG_INDEX, msg->rr_cnfg.phy_cnfg_ded.sched_request_cnfg.sr_cnfg_idx); + mac->set_param(srslte::ue::mac_params::SR_TRANS_MAX, liblte_rrc_dsr_trans_max_num[msg->rr_cnfg.phy_cnfg_ded.sched_request_cnfg.dsr_trans_max]); - + mac->set_param(srslte::ue::mac_params::SR_PUCCH_CONFIGURED, 1); + phy->set_param(srslte::ue::phy_params::UCI_I_OFFSET_ACK, msg->rr_cnfg.phy_cnfg_ded.pusch_cnfg_ded.beta_offset_ack_idx); phy->set_param(srslte::ue::phy_params::UCI_I_OFFSET_CQI, msg->rr_cnfg.phy_cnfg_ded.pusch_cnfg_ded.beta_offset_cqi_idx); phy->set_param(srslte::ue::phy_params::UCI_I_OFFSET_RI, msg->rr_cnfg.phy_cnfg_ded.pusch_cnfg_ded.beta_offset_ri_idx); diff --git a/srsapps/ue/phy/include/srsapps/ue/phy/phy.h b/srsapps/ue/phy/include/srsapps/ue/phy/phy.h index 8f9ca741e..53174b1ba 100644 --- a/srsapps/ue/phy/include/srsapps/ue/phy/phy.h +++ b/srsapps/ue/phy/include/srsapps/ue/phy/phy.h @@ -90,6 +90,9 @@ public: bool send_prach(uint32_t preamble_idx); bool send_prach(uint32_t preamble_idx, int allowed_subframe); bool send_prach(uint32_t preamble_idx, int allowed_subframe, int target_power_dbm); + + // Indicate the PHY to send SR as soon as possible or not + void send_sr(bool enable); // Returns TTI when PRACH was transmitted. -1 if not yet transmitted int get_prach_transmitted_tti(); @@ -149,12 +152,18 @@ private: float cellsearch_cfo; bool do_agc; double last_gain; + + uint32_t sr_N_offset; + uint32_t sr_periodicity; + bool sr_enabled; + uint32_t sr_n_pucch; + bool sr_is_ready_to_send(uint32_t tti); + bool init_(radio *radio_handler, tti_sync *ttisync, log *log_h, bool do_agc); static void *phy_thread_fnc(void *arg); bool decode_mib_N_id_2(int force_N_id_2, srslte_cell_t *cell, uint8_t payload[SRSLTE_BCH_PAYLOAD_LEN]); int sync_sfn(); void run_rx_tx_state(); - bool init_radio_handler(char *args); ul_buffer* get_ul_buffer_adv(uint32_t tti); }; diff --git a/srsapps/ue/phy/include/srsapps/ue/phy/phy_params.h b/srsapps/ue/phy/include/srsapps/ue/phy/phy_params.h index 05cdcbfb4..44fa2402f 100644 --- a/srsapps/ue/phy/include/srsapps/ue/phy/phy_params.h +++ b/srsapps/ue/phy/include/srsapps/ue/phy/phy_params.h @@ -77,6 +77,9 @@ namespace ue { PUCCH_N_PUCCH_2, PUCCH_N_PUCCH_SR, + SR_PUCCH_RESINDEX, + SR_CONFIG_INDEX, + UCI_I_OFFSET_ACK, UCI_I_OFFSET_RI, UCI_I_OFFSET_CQI, diff --git a/srsapps/ue/phy/src/phy.cc b/srsapps/ue/phy/src/phy.cc index 3b5646cc5..6632684a2 100644 --- a/srsapps/ue/phy/src/phy.cc +++ b/srsapps/ue/phy/src/phy.cc @@ -140,6 +140,52 @@ bool phy::send_prach(uint32_t preamble_idx, int allowed_subframe, int target_pow return false; } +/* Send SR as soon as possible as defined in Section 10.2 of 36.213 */ +void phy::send_sr(bool enable) +{ + + if (enable) { + // Get sr_periodicity and sr_N_offset from table 10.1-5 + uint32_t I_sr = params_db.get_param(phy_params::SR_CONFIG_INDEX); + if (I_sr < 5) { + sr_periodicity = 5; + sr_N_offset = I_sr; + } else if (I_sr < 15) { + sr_periodicity = 10; + sr_N_offset = I_sr-5; + } else if (I_sr < 35) { + sr_periodicity = 20; + sr_N_offset = I_sr-15; + } else if (I_sr < 75) { + sr_periodicity = 40; + sr_N_offset = I_sr-35; + } else if (I_sr < 155) { + sr_periodicity = 80; + sr_N_offset = I_sr-75; + } else if (I_sr < 157) { + sr_periodicity = 2; + sr_N_offset = I_sr-155; + } else if (I_sr == 157) { + sr_periodicity = 1; + sr_N_offset = I_sr-157; + } else { + Error("Invalid I_sr=%d\n", I_sr); + return; + } + sr_n_pucch = params_db.get_param(phy_params::SR_PUCCH_RESINDEX); + } + sr_enabled = enable; +} + +bool phy::sr_is_ready_to_send(uint32_t tti_) { + if (sr_enabled) { + if ((10*tti_to_SFN(tti_)+tti_to_subf(tti_)-sr_N_offset)%sr_periodicity==0) { + return true; + } + } + return false; +} + int phy::get_prach_transmitted_tti() { return prach_buffer.get_transmitted_tti(); @@ -444,6 +490,9 @@ void phy::run_rx_tx_state() if (prach_buffer.is_ready_to_send(current_tti)) { prach_buffer.send(radio_handler, cfo, last_rx_time); } + if (sr_is_ready_to_send(current_tti+ul_buffer::tx_advance_sf)) { + get_ul_buffer_adv(current_tti)->generate_sr(); + } // send ul buffer if we have to if (get_ul_buffer_adv(current_tti)->is_released() || get_ul_buffer_adv(current_tti)->uci_ready()) { // Generate PUCCH if no UL grant diff --git a/srslte/examples/pdsch_ue.c b/srslte/examples/pdsch_ue.c index 366c22aee..5ab186236 100644 --- a/srslte/examples/pdsch_ue.c +++ b/srslte/examples/pdsch_ue.c @@ -561,7 +561,7 @@ int main(int argc, char **argv) { #ifndef DISABLE_GRAPHICS if (!prog_args.disable_plots) { - if ((sfn%10) == 0 && decode_pdsch) { + if ((sfn%4) == 0 && decode_pdsch) { plot_sf_idx = srslte_ue_sync_get_sfidx(&ue_sync); sem_post(&plot_sem); } @@ -694,10 +694,10 @@ void *plot_thread_run(void *arg) { plot_real_setNewData(&pce_arg, tmp_plot2, SRSLTE_REFSIGNAL_NUM_SF(ue_dl.cell.nof_prb,0)); #endif - plot_scatter_setNewData(&pscatequal_pdcch, ue_dl.pdcch.d, 36*ue_dl.pdcch.nof_cce/2); + plot_scatter_setNewData(&pscatequal_pdcch, ue_dl.pdcch.d, 36*ue_dl.pdcch.nof_cce); } - plot_scatter_setNewData(&pscatequal, ue_dl.pdsch.d, nof_symbols/2); + plot_scatter_setNewData(&pscatequal, ue_dl.pdsch.d, nof_symbols); if (plot_sf_idx == 1) { if (prog_args.net_port_signal > 0) { diff --git a/srslte/lib/ue/src/ue_sync.c b/srslte/lib/ue/src/ue_sync.c index c99cc086d..aac311c41 100644 --- a/srslte/lib/ue/src/ue_sync.c +++ b/srslte/lib/ue/src/ue_sync.c @@ -118,15 +118,13 @@ int srslte_ue_sync_init(srslte_ue_sync_t *q, q->sf_len = SRSLTE_SF_LEN(q->fft_size); q->file_mode = false; q->correct_cfo = true; + q->decode_sss_on_track = true; if (cell.id == 1000) { - /* If the cell is unkown, decode SSS on track state */ - q->decode_sss_on_track = true; /* If the cell is unkown, we search PSS/SSS in 5 ms */ q->nof_recv_sf = 5; } else { - q->decode_sss_on_track = false; /* If the cell is known, we work on a 1ms basis */ q->nof_recv_sf = 1;