diff --git a/lib/include/srslte/interfaces/ue_nr_interfaces.h b/lib/include/srslte/interfaces/ue_nr_interfaces.h index f225cdcde..c5dbc6426 100644 --- a/lib/include/srslte/interfaces/ue_nr_interfaces.h +++ b/lib/include/srslte/interfaces/ue_nr_interfaces.h @@ -49,8 +49,12 @@ public: virtual int sf_indication(const uint32_t tti) = 0; ///< FIXME: rename to slot indication // Query the MAC for the current RNTI to look for - virtual uint16_t get_dl_sched_rnti(const uint32_t tti) = 0; - virtual uint16_t get_ul_sched_rnti(const uint32_t tti) = 0; + struct sched_rnti_t { + uint16_t id; + srslte_rnti_type_t type; + }; + virtual sched_rnti_t get_dl_sched_rnti_nr(const uint32_t tti) = 0; + virtual sched_rnti_t get_ul_sched_rnti_nr(const uint32_t tti) = 0; /// Indicate succussfully received TB to MAC. The TB buffer is allocated in the PHY and handed as unique_ptr to MAC virtual void tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant) = 0; @@ -126,7 +130,10 @@ public: virtual int tx_request(const tx_request_t& request) = 0; /// Instruct PHY to send PRACH in the next occasion. - virtual void send_prach(const uint32_t prach_occasion, const int preamble_index, const float preamble_received_target_power, const float ta_base_sec = 0.0f) = 0; + virtual void send_prach(const uint32_t prach_occasion, + const int preamble_index, + const float preamble_received_target_power, + const float ta_base_sec = 0.0f) = 0; }; class phy_interface_rrc_nr diff --git a/srsue/hdr/stack/mac_nr/mac_nr.h b/srsue/hdr/stack/mac_nr/mac_nr.h index 2ebc6ed26..40a9b7462 100644 --- a/srsue/hdr/stack/mac_nr/mac_nr.h +++ b/srsue/hdr/stack/mac_nr/mac_nr.h @@ -47,8 +47,8 @@ public: void bch_decoded_ok(uint32_t tti, srslte::unique_byte_buffer_t payload); /// Interface for PHY - uint16_t get_dl_sched_rnti(const uint32_t tti); - uint16_t get_ul_sched_rnti(const uint32_t tti); + sched_rnti_t get_dl_sched_rnti_nr(const uint32_t tti); + sched_rnti_t get_ul_sched_rnti_nr(const uint32_t tti); int sf_indication(const uint32_t tti); void tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant); diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 43eda0bb8..c3292f2fe 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -88,6 +88,9 @@ public: uint16_t get_dl_sched_rnti(uint32_t tti) final { return mac.get_dl_sched_rnti(tti); } uint16_t get_ul_sched_rnti(uint32_t tti) final { return mac.get_ul_sched_rnti(tti); } + sched_rnti_t get_dl_sched_rnti_nr(uint32_t tti) final { return mac_nr.get_dl_sched_rnti_nr(tti); } + sched_rnti_t get_ul_sched_rnti_nr(uint32_t tti) final { return mac_nr.get_ul_sched_rnti_nr(tti); } + void new_grant_ul(uint32_t cc_idx, mac_grant_ul_t grant, tb_action_ul_t* action) final { mac.new_grant_ul(cc_idx, grant, action); diff --git a/srsue/hdr/stack/ue_stack_nr.h b/srsue/hdr/stack/ue_stack_nr.h index ab842b44b..634256fb3 100644 --- a/srsue/hdr/stack/ue_stack_nr.h +++ b/srsue/hdr/stack/ue_stack_nr.h @@ -74,9 +74,9 @@ public: void run_tti(uint32_t tti) final; // MAC interface for PHY - uint16_t get_dl_sched_rnti(const uint32_t tti) { return mac->get_dl_sched_rnti(tti); } - uint16_t get_ul_sched_rnti(const uint32_t tti) { return mac->get_ul_sched_rnti(tti); } - int sf_indication(const uint32_t tti) + sched_rnti_t get_dl_sched_rnti_nr(const uint32_t tti) final { return mac->get_dl_sched_rnti_nr(tti); } + sched_rnti_t get_ul_sched_rnti_nr(const uint32_t tti) final { return mac->get_ul_sched_rnti_nr(tti); } + int sf_indication(const uint32_t tti) { run_tti(tti); return SRSLTE_SUCCESS; diff --git a/srsue/src/phy/nr/cc_worker.cc b/srsue/src/phy/nr/cc_worker.cc index 3499e74d8..b4ee3cfaa 100644 --- a/srsue/src/phy/nr/cc_worker.cc +++ b/srsue/src/phy/nr/cc_worker.cc @@ -129,11 +129,16 @@ uint32_t cc_worker::get_buffer_len() void cc_worker::decode_pdcch_dl() { std::array dci_rx = {}; - uint16_t rnti = phy->stack->get_dl_sched_rnti(dl_slot_cfg.idx); + srsue::mac_interface_phy_nr::sched_rnti_t rnti = phy->stack->get_dl_sched_rnti_nr(dl_slot_cfg.idx); + + // Skip search if no valid RNTI is given + if (rnti.id == SRSLTE_INVALID_RNTI) { + return; + } // Search for grants - int n_dl = srslte_ue_dl_nr_find_dl_dci( - &ue_dl, &dl_slot_cfg, rnti, srslte_rnti_type_c, dci_rx.data(), (uint32_t)dci_rx.size()); + int n_dl = + srslte_ue_dl_nr_find_dl_dci(&ue_dl, &dl_slot_cfg, rnti.id, rnti.type, dci_rx.data(), (uint32_t)dci_rx.size()); if (n_dl < SRSLTE_SUCCESS) { logger.error("Error decoding DL NR-PDCCH"); return; @@ -156,11 +161,16 @@ void cc_worker::decode_pdcch_dl() void cc_worker::decode_pdcch_ul() { std::array dci_rx = {}; - uint16_t rnti = phy->stack->get_ul_sched_rnti(ul_slot_cfg.idx); + srsue::mac_interface_phy_nr::sched_rnti_t rnti = phy->stack->get_ul_sched_rnti_nr(ul_slot_cfg.idx); + + // Skip search if no valid RNTI is given + if (rnti.id == SRSLTE_INVALID_RNTI) { + return; + } // Search for grants - int n_dl = srslte_ue_dl_nr_find_ul_dci( - &ue_dl, &dl_slot_cfg, rnti, srslte_rnti_type_c, dci_rx.data(), (uint32_t)dci_rx.size()); + int n_dl = + srslte_ue_dl_nr_find_ul_dci(&ue_dl, &dl_slot_cfg, rnti.id, rnti.type, dci_rx.data(), (uint32_t)dci_rx.size()); if (n_dl < SRSLTE_SUCCESS) { logger.error("Error decoding UL NR-PDCCH"); return; @@ -206,7 +216,7 @@ bool cc_worker::work_dl() // Initialise PDSCH Result std::array pdsch_res = {}; - pdsch_res[0].payload = data->buffer; + pdsch_res[0].payload = data->msg; pdsch_cfg.grant.tb[0].softbuffer.rx = &softbuffer_rx; // Decode actual PDSCH transmission @@ -236,6 +246,10 @@ bool cc_worker::work_dl() mac_nr_grant.rnti = pdsch_cfg.grant.rnti; mac_nr_grant.tti = dl_slot_cfg.idx; + if (pdsch_cfg.grant.rnti_type == srslte_rnti_type_ra) { + phy->rar_grant_tti = dl_slot_cfg.idx; + } + // Send data to MAC phy->stack->tb_decoded(cc_idx, mac_nr_grant); } @@ -273,14 +287,17 @@ bool cc_worker::work_ul() mac_ul_grant.rnti = pusch_cfg.grant.rnti; mac_ul_grant.tti = ul_slot_cfg.idx; mac_ul_grant.tbs = pusch_cfg.grant.tb[0].tbs; - phy->stack->new_grant_ul(0, mac_ul_grant); - + srslte::unique_byte_buffer_t tx_pdu = srslte::make_byte_buffer(); + phy->stack->new_grant_ul(0, mac_ul_grant, tx_pdu.get()); // Provisional reset and assign Tx softbuffer srslte_softbuffer_tx_reset(&softbuffer_tx); pusch_cfg.grant.tb[0].softbuffer.tx = &softbuffer_tx; + // TODO: Use here PDU, after that, remove tx_data attribute + uint8_t* tx_data_ptr = tx_pdu.get()->msg; + // Encode PUSCH transmission - if (srslte_ue_ul_nr_encode_pusch(&ue_ul, &ul_slot_cfg, &pusch_cfg, tx_data.data()) < SRSLTE_SUCCESS) { + if (srslte_ue_ul_nr_encode_pusch(&ue_ul, &ul_slot_cfg, &pusch_cfg, tx_data_ptr) < SRSLTE_SUCCESS) { ERROR("Encoding PUSCH"); return false; } @@ -289,9 +306,9 @@ bool cc_worker::work_ul() if (logger.info.enabled()) { std::array str; srslte_ue_ul_nr_pusch_info(&ue_ul, &pusch_cfg, str.data(), str.size()); - logger.info(tx_data.data(), + logger.info(tx_data_ptr, pusch_cfg.grant.tb[0].tbs / 8, - "PUSCH: cc=%d, %s, tti_tx=%d", + "PUSCH (NR): cc=%d, %s, tti_tx=%d", cc_idx, str.data(), ul_slot_cfg.idx); diff --git a/srsue/src/stack/mac_nr/mac_nr.cc b/srsue/src/stack/mac_nr/mac_nr.cc index 44c07e979..a1304e407 100644 --- a/srsue/src/stack/mac_nr/mac_nr.cc +++ b/srsue/src/stack/mac_nr/mac_nr.cc @@ -73,9 +73,9 @@ void mac_nr::run_tti(const uint32_t tti) logger.debug("Running MAC tti=%d", tti); } -uint16_t mac_nr::get_ul_sched_rnti(const uint32_t tti) +mac_interface_phy_nr::sched_rnti_t mac_nr::get_ul_sched_rnti_nr(const uint32_t tti) { - return c_rnti; + return {c_rnti, srslte_rnti_type_c}; } bool mac_nr::is_si_opportunity() @@ -89,34 +89,33 @@ bool mac_nr::is_paging_opportunity() return false; } -uint16_t mac_nr::get_dl_sched_rnti(const uint32_t tti) +mac_interface_phy_nr::sched_rnti_t mac_nr::get_dl_sched_rnti_nr(const uint32_t tti) { // Priority: SI-RNTI, P-RNTI, RA-RNTI, Temp-RNTI, CRNTI if (is_si_opportunity()) { - return SRSLTE_SIRNTI; + return {SRSLTE_SIRNTI, srslte_rnti_type_si}; } if (is_paging_opportunity()) { - return SRSLTE_PRNTI; + return {SRSLTE_PRNTI, srslte_rnti_type_si}; } - // TODO: add new RA proc shortly -#if 0 - if (proc_ra->is_rar_opportunity()) { - return proc_ra->get_rar_rnti(); + if (proc_ra.is_rar_opportunity(tti)) { + return {proc_ra.get_rar_rnti(), srslte_rnti_type_ra}; } - if (proc_ra->has_temp_rnti() && has_crnti() == false) { +#if 0 + if (proc_ra.has_temp_rnti() && has_crnti() == false) { return proc_ra->get_temp_rnti(); } #endif if (has_crnti()) { - return get_crnti(); + return {get_crnti(), srslte_rnti_type_c}; } // turn off DCI search for this TTI - return SRSLTE_INVALID_RNTI; + return {SRSLTE_INVALID_RNTI, srslte_rnti_type_c}; } bool mac_nr::has_crnti() @@ -151,7 +150,7 @@ void mac_nr::prach_sent(const uint32_t tti, const uint32_t f_id, const uint32_t ul_carrier_id) { - // TODO: indicate to RA proc + proc_ra.prach_sent(tti, s_id, t_id, f_id, ul_carrier_id); } // This function handles all PCAP writing for a decoded DL TB