srsLTE/srsenb/hdr/phy/phy_common.h

249 lines
7.0 KiB
C
Raw Normal View History

/**
2017-06-02 03:46:06 -07:00
*
* \section COPYRIGHT
2017-06-02 03:46:06 -07:00
*
2021-03-19 03:45:56 -07:00
* Copyright 2013-2021 Software Radio Systems Limited
2017-06-02 03:46:06 -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-06-02 03:46:06 -07:00
*
*/
2017-06-01 03:25:57 -07:00
2018-03-31 10:04:04 -07:00
#ifndef SRSENB_PHCH_COMMON_H
#define SRSENB_PHCH_COMMON_H
2017-06-01 03:25:57 -07:00
#include "phy_interfaces.h"
#include "srsenb/hdr/phy/phy_ue_db.h"
2021-03-19 03:45:56 -07:00
#include "srsran/common/gen_mch_tables.h"
#include "srsran/common/interfaces_common.h"
#include "srsran/common/standard_streams.h"
#include "srsran/common/thread_pool.h"
#include "srsran/common/threads.h"
#include "srsran/interfaces/enb_metrics_interface.h"
#include "srsran/interfaces/phy_common_interface.h"
2021-03-19 03:45:56 -07:00
#include "srsran/interfaces/radio_interfaces.h"
#include "srsran/phy/channel/channel.h"
#include "srsran/radio/radio.h"
#include <map>
2021-03-19 03:45:56 -07:00
#include <srsran/common/tti_sempahore.h>
#include <string.h>
2017-06-01 03:25:57 -07:00
namespace srsenb {
class phy_common : public srsran::phy_common_interface
2017-06-01 03:25:57 -07:00
{
public:
2020-03-03 08:27:04 -08:00
phy_common() = default;
bool init(const phy_cell_cfg_list_t& cell_list_,
const phy_cell_cfg_list_nr_t& cell_list_nr_,
2021-03-19 03:45:56 -07:00
srsran::radio_interface_phy* radio_handler,
stack_interface_phy_lte* mac);
void reset();
2017-06-01 03:25:57 -07:00
void stop();
/**
* TTI transmission semaphore, used for ensuring that PHY workers transmit following start order
*/
2021-03-19 03:45:56 -07:00
srsran::tti_semaphore<void*> semaphore;
/**
* Performs common end worker transmission tasks such as transmission and stack TTI execution
*
* @param tx_sem_id Semaphore identifier, the worker thread pointer is used
* @param buffer baseband IQ sample buffer
* @param tx_time timestamp to transmit samples
2020-11-23 00:43:12 -08:00
* @param is_nr flag is true if it is called from NR
*/
void worker_end(const worker_context_t& w_ctx, const bool& tx_enable, srsran::rf_buffer_t& buffer) override;
2017-06-01 03:25:57 -07:00
// Common objects
2020-01-23 06:12:26 -08:00
phy_args_t params = {};
uint32_t get_nof_carriers_lte() { return static_cast<uint32_t>(cell_list_lte.size()); };
uint32_t get_nof_carriers_nr() { return static_cast<uint32_t>(cell_list_nr.size()); };
uint32_t get_nof_carriers() { return static_cast<uint32_t>(cell_list_lte.size() + cell_list_nr.size()); };
2020-01-23 06:12:26 -08:00
uint32_t get_nof_prb(uint32_t cc_idx)
{
uint32_t ret = 0;
if (cc_idx < cell_list_lte.size()) {
ret = cell_list_lte[cc_idx].cell.nof_prb;
} else if (cc_idx == 1 && !cell_list_nr.empty()) {
// for basic NSA config return width of first NR carrier
ret = cell_list_nr[0].carrier.nof_prb;
2020-01-23 06:12:26 -08:00
}
return ret;
};
uint32_t get_nof_ports(uint32_t cc_idx)
{
uint32_t ret = 0;
if (cc_idx < cell_list_lte.size()) {
ret = cell_list_lte[cc_idx].cell.nof_ports;
} else if (cc_idx == 1 && !cell_list_nr.empty()) {
// one RF port for basic NSA config
ret = 1;
2020-01-23 06:12:26 -08:00
}
return ret;
};
uint32_t get_nof_rf_channels()
{
uint32_t count = 0;
for (auto& cell : cell_list_lte) {
count += cell.cell.nof_ports;
}
for (auto& cell : cell_list_nr) {
2020-11-23 00:43:12 -08:00
count += cell.carrier.max_mimo_layers;
}
return count;
}
double get_ul_freq_hz(uint32_t cc_idx)
2020-01-23 06:12:26 -08:00
{
double ret = 0.0;
2020-01-23 06:12:26 -08:00
if (cc_idx < cell_list_lte.size()) {
ret = cell_list_lte[cc_idx].ul_freq_hz;
}
cc_idx -= cell_list_lte.size();
if (cc_idx < cell_list_nr.size()) {
ret = cell_list_nr[cc_idx].ul_freq_hz;
2020-01-23 06:12:26 -08:00
}
return ret;
};
double get_dl_freq_hz(uint32_t cc_idx)
2020-01-23 06:12:26 -08:00
{
double ret = 0.0;
2020-01-23 06:12:26 -08:00
if (cc_idx < cell_list_lte.size()) {
ret = cell_list_lte[cc_idx].dl_freq_hz;
}
cc_idx -= cell_list_lte.size();
if (cc_idx < cell_list_nr.size()) {
ret = cell_list_nr[cc_idx].dl_freq_hz;
2020-01-23 06:12:26 -08:00
}
return ret;
};
uint32_t get_rf_port(uint32_t cc_idx)
{
uint32_t ret = 0;
if (cc_idx < cell_list_lte.size()) {
ret = cell_list_lte[cc_idx].rf_port;
}
cc_idx -= cell_list_lte.size();
if (cc_idx < cell_list_nr.size()) {
ret = cell_list_nr[cc_idx].rf_port;
2020-01-23 06:12:26 -08:00
}
return ret;
};
2021-03-19 03:45:56 -07:00
srsran_cell_t get_cell(uint32_t cc_idx)
2020-01-23 06:12:26 -08:00
{
2021-03-19 03:45:56 -07:00
srsran_cell_t c = {};
if (cc_idx < cell_list_lte.size()) {
c = cell_list_lte[cc_idx].cell;
}
return c;
};
2019-04-23 01:53:11 -07:00
void set_cell_gain(uint32_t cell_id, float gain_db)
{
// Find LTE cell
auto it_lte = std::find_if(
cell_list_lte.begin(), cell_list_lte.end(), [cell_id](phy_cell_cfg_t& x) { return x.cell_id == cell_id; });
// Check if the lte cell was found;
if (it_lte != cell_list_lte.end()) {
it_lte->gain_db = gain_db;
return;
}
// Find NR cell
auto it_nr = std::find_if(
cell_list_nr.begin(), cell_list_nr.end(), [cell_id](phy_cell_cfg_nr_t& x) { return x.cell_id == cell_id; });
// Check if the nr cell was found;
if (it_nr != cell_list_nr.end()) {
it_nr->gain_db = gain_db;
return;
}
2021-03-19 03:45:56 -07:00
srsran::console("cell ID %d not found\n", cell_id);
}
float get_cell_gain(uint32_t cc_idx)
{
if (cc_idx < cell_list_lte.size()) {
return cell_list_lte.at(cc_idx).gain_db;
}
cc_idx -= cell_list_lte.size();
if (cc_idx < cell_list_nr.size()) {
return cell_list_nr.at(cc_idx).gain_db;
}
return 0.0f;
}
// Common Physical Uplink DMRS configuration
2021-03-19 03:45:56 -07:00
srsran_refsignal_dmrs_pusch_cfg_t dmrs_pusch_cfg = {};
2017-06-01 03:25:57 -07:00
2021-03-19 03:45:56 -07:00
srsran::radio_interface_phy* radio = nullptr;
stack_interface_phy_lte* stack = nullptr;
2021-03-19 03:45:56 -07:00
srsran::channel_ptr dl_channel = nullptr;
2020-02-10 03:59:23 -08:00
/**
* UE Database object, direct public access, all PHY threads should be able to access this attribute directly
2020-02-10 03:59:23 -08:00
*/
phy_ue_db ue_db;
2019-04-23 01:53:11 -07:00
2021-03-19 03:45:56 -07:00
void configure_mbsfn(srsran::phy_cfg_mbsfn_t* cfg);
void build_mch_table();
void build_mcch_table();
2021-03-19 03:45:56 -07:00
bool is_mbsfn_sf(srsran_mbsfn_cfg_t* cfg, uint32_t phy_tti);
2019-04-23 01:53:11 -07:00
void set_mch_period_stop(uint32_t stop);
// Getters and setters for ul grants which need to be shared between workers
const stack_interface_phy_lte::ul_sched_list_t& get_ul_grants(uint32_t tti);
void set_ul_grants(uint32_t tti, const stack_interface_phy_lte::ul_sched_list_t& ul_grants);
void clear_grants(uint16_t rnti);
2017-06-01 03:25:57 -07:00
private:
// Common objects for scheduling grants
2021-03-19 03:45:56 -07:00
srsran::circular_array<stack_interface_phy_lte::ul_sched_list_t, TTIMOD_SZ> ul_grants = {};
std::mutex grant_mutex = {};
phy_cell_cfg_list_t cell_list_lte;
phy_cell_cfg_list_nr_t cell_list_nr;
2017-06-01 03:25:57 -07:00
bool have_mtch_stop = false;
pthread_mutex_t mtch_mutex = {};
pthread_cond_t mtch_cvar = {};
2021-03-19 03:45:56 -07:00
srsran::phy_cfg_mbsfn_t mbsfn = {};
bool sib13_configured = false;
bool mcch_configured = false;
uint8_t mch_table[40] = {};
uint8_t mcch_table[10] = {};
uint32_t mch_period_stop = 0;
srsran::rf_buffer_t tx_buffer = {};
2021-03-19 03:45:56 -07:00
bool is_mch_subframe(srsran_mbsfn_cfg_t* cfg, uint32_t phy_tti);
bool is_mcch_subframe(srsran_mbsfn_cfg_t* cfg, uint32_t phy_tti);
2017-06-01 03:25:57 -07:00
};
} // namespace srsenb
2018-03-31 10:04:04 -07:00
#endif // SRSENB_PHCH_COMMON_H