srsLTE/srsue/hdr/phy/phy.h

227 lines
7.1 KiB
C
Raw Normal View History

/**
2017-05-30 06:38:04 -07:00
*
* \section COPYRIGHT
2017-05-30 06:38:04 -07:00
*
2021-03-19 03:45:56 -07:00
* Copyright 2013-2021 Software Radio Systems Limited
2017-05-30 06:38:04 -07:00
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
2017-05-30 06:38:04 -07:00
*
*/
2018-03-31 10:04:04 -07:00
#ifndef SRSUE_PHY_H
#define SRSUE_PHY_H
2017-05-30 06:38:04 -07:00
2019-04-23 01:53:11 -07:00
#include "phy_common.h"
#include "phy_metrics.h"
2021-03-19 03:45:56 -07:00
#include "srsran/common/block_queue.h"
#include "srsran/common/threads.h"
#include "srsran/common/trace.h"
#include "srsran/interfaces/phy_interface_types.h"
#include "srsran/interfaces/radio_interfaces.h"
#include "srsran/radio/radio.h"
#include "srsran/srslog/srslog.h"
#include "srsran/srsran.h"
#include "srsue/hdr/phy/lte/worker_pool.h"
2020-11-20 03:12:29 -08:00
#include "srsue/hdr/phy/nr/worker_pool.h"
#include "srsue/hdr/phy/ue_lte_phy_base.h"
#include "srsue/hdr/phy/ue_nr_phy_base.h"
2019-04-23 01:53:11 -07:00
#include "sync.h"
2017-05-30 06:38:04 -07:00
namespace srsue {
typedef _Complex float cf_t;
2017-05-30 06:38:04 -07:00
2021-03-19 03:45:56 -07:00
class phy_cmd_proc : public srsran::thread
{
public:
phy_cmd_proc() : thread("PHY_CMD") { start(); }
~phy_cmd_proc() { stop(); }
void add_cmd(std::function<void(void)> cmd) { cmd_queue.push(cmd); }
void stop()
{
if (running) {
add_cmd([this]() { running = false; });
wait_thread_finish();
}
}
private:
void run_thread()
{
std::function<void(void)> cmd;
while (running) {
cmd = cmd_queue.wait_pop();
cmd();
}
}
bool running = true;
// Queue for commands
2021-03-19 03:45:56 -07:00
srsran::block_queue<std::function<void(void)> > cmd_queue;
};
2021-03-19 03:45:56 -07:00
class phy final : public ue_lte_phy_base, public ue_nr_phy_base, public srsran::thread
2017-05-30 06:38:04 -07:00
{
public:
explicit phy() :
logger_phy(srslog::fetch_basic_logger("PHY")),
logger_phy_lib(srslog::fetch_basic_logger("PHY_LIB")),
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
lte_workers(MAX_WORKERS),
nr_workers(MAX_WORKERS),
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
common(logger_phy),
sfsync(logger_phy, logger_phy_lib),
prach_buffer(logger_phy),
thread("PHY")
{}
~phy() final { stop(); }
// Init defined in base class
int init(const phy_args_t& args_) final;
// Init for LTE PHYs
2021-03-19 03:45:56 -07:00
int init(const phy_args_t& args_, stack_interface_phy_lte* stack_, srsran::radio_interface_phy* radio_) final;
2019-04-23 01:53:11 -07:00
void stop() final;
2017-05-30 06:38:04 -07:00
void wait_initialize() final;
bool is_initiated();
2021-04-13 03:21:26 -07:00
void get_metrics(const srsran::srsran_rat_t& rat, phy_metrics_t* m) final;
2021-03-19 03:45:56 -07:00
void srsran_phy_logger(phy_logger_level_t log_level, char* str);
2017-05-30 06:38:04 -07:00
void radio_overflow() final;
void radio_failure() final;
2017-05-30 06:38:04 -07:00
/********** RRC INTERFACE ********************/
2017-06-21 09:29:17 -07:00
bool cell_search() final;
bool cell_select(phy_cell_t cell) final;
// Sets the new PHY configuration for the given CC. The configuration is applied in the background. The notify()
// function will be called when the reconfiguration is completed. Unless the PRACH configuration has changed, the
// reconfiguration will not take more than 3 ms
bool set_config(const srsran::phy_cfg_t& config, uint32_t cc_idx) final;
// Adds or modifies the cell configuration for a given CC. If the EARFCN has changed w.r.t. the previous value, or if
// the cell is new, this function might take a few hundred ms to complete, depending on the radio
2021-03-19 03:45:56 -07:00
bool set_scell(srsran_cell_t cell_info, uint32_t cc_idx, uint32_t earfcn) final;
// Applies a TDD configuration in the background. This function will take less than 3 ms to execute.
2021-03-19 03:45:56 -07:00
void set_config_tdd(srsran_tdd_config_t& tdd_config) final;
// Todo
2021-03-19 03:45:56 -07:00
void set_config_mbsfn_sib2(srsran::mbsfn_sf_cfg_t* cfg_list, uint32_t nof_cfgs) final;
void set_config_mbsfn_sib13(const srsran::sib13_t& sib13) final;
void set_config_mbsfn_mcch(const srsran::mcch_msg_t& mcch) final;
// This function applies the new configuration immediately
void set_cells_to_meas(uint32_t earfcn, const std::set<uint32_t>& pci) final;
// This function applies the new configuration immediately
void meas_stop() final;
// also MAC interface
bool cell_is_camping() final;
2017-05-30 06:38:04 -07:00
/********** MAC INTERFACE ********************/
2017-05-30 06:38:04 -07:00
/* Transmits PRACH in the next opportunity */
2020-03-11 02:27:53 -07:00
void prach_send(uint32_t preamble_idx, int allowed_subframe, float target_power_dbm, float ta_base_sec) final;
prach_info_t prach_get_info() final;
2019-04-23 01:53:11 -07:00
2017-05-30 06:38:04 -07:00
/* Indicates the transmission of a SR signal in the next opportunity */
void sr_send() final;
int sr_last_tx_tti() final;
2017-05-30 06:38:04 -07:00
// Time advance commands
2021-03-09 04:08:36 -08:00
void set_timeadv_rar(uint32_t tti, uint32_t ta_cmd) final;
void set_timeadv(uint32_t tti, uint32_t ta_cmd) final;
2019-04-23 01:53:11 -07:00
/* Activate / Disactivate SCell*/
void deactivate_scells() final;
void set_activation_deactivation_scell(uint32_t cmd, uint32_t tti) final;
2019-04-23 01:53:11 -07:00
/* Sets RAR dci payload */
2021-03-19 03:45:56 -07:00
void set_rar_grant(uint8_t grant_payload[SRSRAN_RAR_GRANT_LEN], uint16_t rnti) final;
2019-04-23 01:53:11 -07:00
2018-05-15 08:16:28 -07:00
/*Set MAC->PHY MCH period stopping point*/
void set_mch_period_stop(uint32_t stop) final;
float get_phr() final;
float get_pathloss_db() final;
uint32_t get_current_tti() final;
2017-05-30 06:38:04 -07:00
void start_plot() final;
2019-04-23 01:53:11 -07:00
const static int MAX_WORKERS = 4;
const static int DEFAULT_WORKERS = 4;
std::string get_type() final { return "lte_soft"; }
2021-03-19 03:45:56 -07:00
int init(const phy_args_nr_t& args_, stack_interface_phy_nr* stack_, srsran::radio_interface_phy* radio_) final;
bool set_config(const srsran::phy_cfg_nr_t& cfg) final;
int set_ul_grant(uint32_t rx_tti,
std::array<uint8_t, SRSRAN_RAR_UL_GRANT_NBITS> packed_ul_grant,
uint16_t rnti,
2021-03-19 03:45:56 -07:00
srsran_rnti_type_t rnti_type) final;
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) final;
int tx_request(const tx_request_t& request) final;
void set_earfcn(std::vector<uint32_t> earfcns) final;
bool has_valid_sr_resource(uint32_t sr_id) final;
void clear_pending_grants() final;
2019-04-23 01:53:11 -07:00
private:
void run_thread() final;
void configure_prach_params();
void reset();
std::mutex config_mutex;
std::condition_variable config_cond;
std::atomic<bool> is_configured = {false};
2018-06-06 07:59:00 -07:00
const static int SF_RECV_THREAD_PRIO = 0;
2019-04-23 01:53:11 -07:00
const static int WORKERS_THREAD_PRIO = 2;
2021-03-19 03:45:56 -07:00
srsran::radio_interface_phy* radio = nullptr;
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
srslog::basic_logger& logger_phy;
srslog::basic_logger& logger_phy_lib;
srsue::stack_interface_phy_lte* stack = nullptr;
srsue::stack_interface_phy_nr* stack_nr = nullptr;
2017-05-30 06:38:04 -07:00
lte::worker_pool lte_workers;
2020-11-20 03:12:29 -08:00
nr::worker_pool nr_workers;
phy_common common;
sync sfsync;
prach prach_buffer;
2019-04-23 01:53:11 -07:00
2021-03-19 03:45:56 -07:00
srsran_prach_cfg_t prach_cfg = {};
srsran_tdd_config_t tdd_config = {};
2019-04-23 01:53:11 -07:00
srsran::phy_cfg_t config = {};
srsran::phy_cfg_nr_t config_nr = {};
phy_args_t args = {};
2019-04-23 01:53:11 -07:00
// Since cell_search/cell_select operations take a lot of time, we use another queue to process the other commands
// in parallel and avoid accumulating in the queue
phy_cmd_proc cmd_worker_cell, cmd_worker;
// Tracks the current selected cell (last call to cell_select)
2021-03-19 03:45:56 -07:00
srsran_cell_t selected_cell = {};
static void set_default_args(phy_args_t& args);
bool check_args(const phy_args_t& args);
2017-05-30 06:38:04 -07:00
};
} // namespace srsue
2018-03-31 10:04:04 -07:00
#endif // SRSUE_PHY_H