srsLTE/srsenb/hdr/phy/prach_worker.h

152 lines
4.1 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
*
*/
2018-03-31 10:04:04 -07:00
#ifndef SRSENB_PRACH_WORKER_H
#define SRSENB_PRACH_WORKER_H
2017-06-01 03:25:57 -07:00
2021-03-19 03:45:56 -07:00
#include "srsran/common/block_queue.h"
#include "srsran/common/buffer_pool.h"
#include "srsran/common/threads.h"
#include "srsran/interfaces/enb_phy_interfaces.h"
#include "srsran/srslog/srslog.h"
#include <atomic>
2017-06-01 03:25:57 -07:00
2020-06-19 00:45:42 -07:00
// Setting ENABLE_PRACH_GUI to non zero enables a GUI showing signal received in the PRACH window.
#define ENABLE_PRACH_GUI 0
#if defined(ENABLE_GUI) and ENABLE_PRACH_GUI
#include <srsgui/srsgui.h>
#endif // defined(ENABLE_GUI) and ENABLE_PRACH_GUI
2017-06-01 03:25:57 -07:00
namespace srsenb {
2018-09-19 08:37:23 -07:00
class stack_interface_phy_lte;
2021-03-19 03:45:56 -07:00
class prach_worker : srsran::thread
2017-06-01 03:25:57 -07:00
{
public:
prach_worker(uint32_t cc_idx_, srslog::basic_logger& logger) :
buffer_pool(8), thread("PRACH_WORKER"), logger(logger), running(false)
2021-01-28 03:17:18 -08:00
{
cc_idx = cc_idx_;
}
2021-03-19 03:45:56 -07:00
int init(const srsran_cell_t& cell_,
const srsran_prach_cfg_t& prach_cfg_,
stack_interface_phy_lte* mac,
int priority,
uint32_t nof_workers);
int new_tti(uint32_t tti, cf_t* buffer);
2017-06-01 03:25:57 -07:00
void set_max_prach_offset_us(float delay_us);
void stop();
2017-06-01 03:25:57 -07:00
private:
2021-01-28 03:17:18 -08:00
uint32_t cc_idx = 0;
2019-10-23 07:32:28 -07:00
uint32_t prach_indices[165] = {};
float prach_offsets[165] = {};
float prach_p2avg[165] = {};
2021-03-19 03:45:56 -07:00
srsran_cell_t cell = {};
srsran_prach_cfg_t prach_cfg = {};
srsran_prach_t prach = {};
2017-06-01 03:25:57 -07:00
2020-06-19 00:45:42 -07:00
#if defined(ENABLE_GUI) and ENABLE_PRACH_GUI
plot_real_t plot_real;
2021-03-19 03:45:56 -07:00
std::array<float, 3 * SRSRAN_SF_LEN_MAX> plot_buffer;
2020-06-19 00:45:42 -07:00
#endif // defined(ENABLE_GUI) and ENABLE_PRACH_GUI
const static int sf_buffer_sz = 128 * 1024;
class sf_buffer
{
2018-09-19 08:37:23 -07:00
public:
2019-10-17 07:44:45 -07:00
sf_buffer() = default;
2019-04-23 01:53:11 -07:00
void reset()
{
nof_samples = 0;
tti = 0;
}
2019-10-17 07:44:45 -07:00
cf_t samples[sf_buffer_sz] = {};
uint32_t nof_samples = 0;
uint32_t tti = 0;
2021-03-19 03:45:56 -07:00
#ifdef SRSRAN_BUFFER_POOL_LOG_ENABLED
char debug_name[SRSRAN_BUFFER_POOL_LOG_NAME_LEN];
#endif /* SRSRAN_BUFFER_POOL_LOG_ENABLED */
2018-09-19 08:37:23 -07:00
};
2021-03-19 03:45:56 -07:00
srsran::buffer_pool<sf_buffer> buffer_pool;
srsran::block_queue<sf_buffer*> pending_buffers;
2017-06-01 03:25:57 -07:00
2021-01-28 03:17:18 -08:00
srslog::basic_logger& logger;
2019-10-17 07:44:45 -07:00
sf_buffer* current_buffer = nullptr;
stack_interface_phy_lte* stack = nullptr;
float max_prach_offset_us = 0.0f;
2019-10-23 07:32:28 -07:00
bool initiated = false;
std::atomic<bool> running;
uint32_t nof_sf = 0;
uint32_t sf_cnt = 0;
uint32_t nof_workers = 0;
2018-09-19 08:37:23 -07:00
2019-10-17 07:44:45 -07:00
void run_thread() final;
int run_tti(sf_buffer* b);
2017-06-01 03:25:57 -07:00
};
2019-10-23 07:32:28 -07:00
2019-11-08 02:24:58 -08:00
class prach_worker_pool
2019-10-23 07:32:28 -07:00
{
private:
std::vector<std::unique_ptr<prach_worker> > prach_vec;
public:
prach_worker_pool() = default;
~prach_worker_pool() = default;
void init(uint32_t cc_idx,
2021-03-19 03:45:56 -07:00
const srsran_cell_t& cell_,
const srsran_prach_cfg_t& prach_cfg_,
2019-10-23 07:32:28 -07:00
stack_interface_phy_lte* mac,
2021-01-28 03:17:18 -08:00
srslog::basic_logger& logger,
int priority,
uint32_t nof_workers_x_cc)
2019-10-23 07:32:28 -07:00
{
// Create PRACH worker if required
while (cc_idx >= prach_vec.size()) {
2021-01-28 03:17:18 -08:00
prach_vec.push_back(std::unique_ptr<prach_worker>(new prach_worker(prach_vec.size(), logger)));
2019-10-23 07:32:28 -07:00
}
2021-01-28 03:17:18 -08:00
prach_vec[cc_idx]->init(cell_, prach_cfg_, mac, priority, nof_workers_x_cc);
2019-10-23 07:32:28 -07:00
}
void set_max_prach_offset_us(float delay_us)
{
for (auto& prach : prach_vec) {
prach->set_max_prach_offset_us(delay_us);
}
}
void stop()
{
for (auto& prach : prach_vec) {
prach->stop();
}
}
int new_tti(uint32_t cc_idx, uint32_t tti, cf_t* buffer)
{
2021-03-19 03:45:56 -07:00
int ret = SRSRAN_ERROR;
2019-10-23 07:32:28 -07:00
if (cc_idx < prach_vec.size()) {
ret = prach_vec[cc_idx]->new_tti(tti, buffer);
}
return ret;
}
};
} // namespace srsenb
2018-03-31 10:04:04 -07:00
#endif // SRSENB_PRACH_WORKER_H