mirror of https://github.com/pvnis/srsRAN_4G.git
Merge branch 'next' into agpl_next
commit
bfa1215b89
@ -0,0 +1,38 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 Software Radio Systems Limited
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSRAN_PHY_COMMON_INTERFACE_H
|
||||
#define SRSRAN_PHY_COMMON_INTERFACE_H
|
||||
|
||||
#include "../radio/rf_buffer.h"
|
||||
#include "../radio/rf_timestamp.h"
|
||||
|
||||
namespace srsran {
|
||||
|
||||
class phy_common_interface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Common PHY interface for workers to indicate they ended
|
||||
* @param h Worker pointer used as unique identifier for synchronising Tx
|
||||
* @param tx_enable Indicates whether the buffer has baseband samples to transmit
|
||||
* @param buffer Baseband buffer
|
||||
* @param tx_time Transmit timestamp
|
||||
* @param is_nr Indicates whether the worker is NR or not
|
||||
*/
|
||||
virtual void
|
||||
worker_end(void* h, bool tx_enable, srsran::rf_buffer_t& buffer, srsran::rf_timestamp_t& tx_time, bool is_nr) = 0;
|
||||
};
|
||||
|
||||
} // namespace srsran
|
||||
|
||||
#endif // SRSRAN_PHY_COMMON_INTERFACE_H
|
@ -0,0 +1,144 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 Software Radio Systems Limited
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSRAN_UE_SYNC_NR_H
|
||||
#define SRSRAN_UE_SYNC_NR_H
|
||||
|
||||
#include "srsran/phy/common/timestamp.h"
|
||||
#include "srsran/phy/sync/ssb.h"
|
||||
|
||||
#define SRSRAN_RECV_CALLBACK_TEMPLATE(NAME) int (*NAME)(void*, cf_t**, uint32_t, srsran_timestamp_t*)
|
||||
|
||||
/**
|
||||
* @brief Describes NR UE synchronization object internal states
|
||||
*/
|
||||
typedef enum SRSRAN_API {
|
||||
SRSRAN_UE_SYNC_NR_STATE_IDLE = 0, ///< Initial state, the object has no configuration
|
||||
SRSRAN_UE_SYNC_NR_STATE_FIND, ///< State just after configuring, baseband is not aligned
|
||||
SRSRAN_UE_SYNC_NR_STATE_TRACK ///< Baseband is aligned with subframes
|
||||
} srsran_ue_sync_nr_state_t;
|
||||
|
||||
/**
|
||||
* @brief Describes a UE sync NR object arguments
|
||||
*/
|
||||
typedef struct SRSRAN_API {
|
||||
// Memory allocation constraints
|
||||
double max_srate_hz; ///< Maximum sampling rate in Hz, set to zero to use default
|
||||
srsran_subcarrier_spacing_t min_scs; ///< Minimum subcarrier spacing
|
||||
uint32_t nof_rx_channels; ///< Number of receive channels, set to 0 for 1
|
||||
|
||||
// Enable/Disable features
|
||||
bool disable_cfo; ///< Set to true for disabling the CFO compensation close loop
|
||||
|
||||
// Signal detection thresholds and averaging coefficients
|
||||
float pbch_dmrs_thr; ///< NR-PBCH DMRS threshold for blind decoding, set to 0 for default
|
||||
float cfo_alpha; ///< Exponential Moving Average (EMA) alpha coefficient for CFO
|
||||
|
||||
// Receive callback
|
||||
void* recv_obj; ///< Receive object
|
||||
SRSRAN_RECV_CALLBACK_TEMPLATE(recv_callback); ///< Receive callback
|
||||
} srsran_ue_sync_nr_args_t;
|
||||
|
||||
/**
|
||||
* @brief Describes a UE sync NR object configuration
|
||||
*/
|
||||
typedef struct SRSRAN_API {
|
||||
srsran_ssb_cfg_t ssb; ///< SSB configuration
|
||||
uint32_t N_id; ///< Physicall cell identifier
|
||||
} srsran_ue_sync_nr_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief Describes a UE sync NR object
|
||||
*/
|
||||
typedef struct SRSRAN_API {
|
||||
// State
|
||||
srsran_ue_sync_nr_state_t state; ///< Internal state
|
||||
int32_t next_rf_sample_offset; ///< Next RF sample offset
|
||||
uint32_t ssb_idx; ///< Tracking SSB candidate index
|
||||
uint32_t sf_idx; ///< Current subframe index (0-9)
|
||||
uint32_t sfn; ///< Current system frame number (0-1023)
|
||||
srsran_csi_trs_measurements_t feedback; ///< Feedback measurements
|
||||
|
||||
// Components
|
||||
srsran_ssb_t ssb; ///< SSB internal object
|
||||
cf_t** tmp_buffer; ///< Temporal buffer pointers
|
||||
|
||||
// Initialised arguments
|
||||
uint32_t nof_rx_channels; ///< Number of receive channels
|
||||
bool disable_cfo; ///< Set to true for disabling the CFO compensation close loop
|
||||
float cfo_alpha; ///< Exponential Moving Average (EMA) alpha coefficient for CFO
|
||||
void* recv_obj; ///< Receive object
|
||||
SRSRAN_RECV_CALLBACK_TEMPLATE(recv_callback); ///< Receive callback
|
||||
|
||||
// Current configuration
|
||||
uint32_t N_id; ///< Current physical cell identifier
|
||||
double srate_hz; ///< Current sampling rate in Hz
|
||||
uint32_t sf_sz; ///< Current subframe size
|
||||
|
||||
// Metrics
|
||||
float cfo_hz; ///< Current CFO in Hz
|
||||
float avg_delay_us; ///< Current average delay
|
||||
} srsran_ue_sync_nr_t;
|
||||
|
||||
/**
|
||||
* @brief Describes a UE sync NR zerocopy outcome
|
||||
*/
|
||||
typedef struct SRSRAN_API {
|
||||
bool in_sync; ///< Indicates whether the received baseband is synchronized
|
||||
uint32_t sf_idx; ///< Subframe index
|
||||
uint32_t sfn; ///< System Frame Number
|
||||
srsran_timestamp_t timestamp; ///< Last received timestamp
|
||||
float cfo_hz; ///< Current CFO in Hz
|
||||
float delay_us; ///< Current average delay in microseconds
|
||||
} srsran_ue_sync_nr_outcome_t;
|
||||
|
||||
/**
|
||||
* @brief Initialises a UE sync NR object
|
||||
* @param q NR UE synchronization object
|
||||
* @param[in] args NR UE synchronization initialization arguments
|
||||
* @return SRSRAN_SUCCESS if no error occurs, SRSRAN_ERROR code otherwise
|
||||
*/
|
||||
SRSRAN_API int srsran_ue_sync_nr_init(srsran_ue_sync_nr_t* q, const srsran_ue_sync_nr_args_t* args);
|
||||
|
||||
/**
|
||||
* @brief Deallocate an NR UE synchronization object
|
||||
* @param q NR UE synchronization object
|
||||
*/
|
||||
SRSRAN_API void srsran_ue_sync_nr_free(srsran_ue_sync_nr_t* q);
|
||||
|
||||
/**
|
||||
* @brief Configures a UE sync NR object
|
||||
* @param q NR UE synchronization object
|
||||
* @param[in] cfg NR UE synchronization configuration
|
||||
* @return SRSRAN_SUCCESS if no error occurs, SRSRAN_ERROR code otherwise
|
||||
*/
|
||||
SRSRAN_API int srsran_ue_sync_nr_set_cfg(srsran_ue_sync_nr_t* q, const srsran_ue_sync_nr_cfg_t* cfg);
|
||||
|
||||
/**
|
||||
* @brief Runs the NR UE synchronization object, tries to find and track the configured SSB leaving in buffer the
|
||||
* received baseband subframe
|
||||
* @param q NR UE synchronization object
|
||||
* @param buffer 2D complex buffer
|
||||
* @param outcome zerocopy outcome
|
||||
* @return SRSRAN_SUCCESS if no error occurs, SRSRAN_ERROR code otherwise
|
||||
*/
|
||||
SRSRAN_API int srsran_ue_sync_nr_zerocopy(srsran_ue_sync_nr_t* q, cf_t** buffer, srsran_ue_sync_nr_outcome_t* outcome);
|
||||
|
||||
/**
|
||||
* @brief Feedback Channel State Information from Tracking Reference Signals into a UE synchronization object
|
||||
* @param q NR UE synchronization object
|
||||
* @param measurements CSI-TRS feedback measurement
|
||||
* @return SRSRAN_SUCCESS if no error occurs, SRSRAN_ERROR code otherwise
|
||||
*/
|
||||
SRSRAN_API int srsran_ue_sync_nr_feedback(srsran_ue_sync_nr_t* q, const srsran_csi_trs_measurements_t* measurements);
|
||||
|
||||
#endif // SRSRAN_UE_SYNC_NR_H
|
@ -0,0 +1,304 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 Software Radio Systems Limited
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srsran/common/test_common.h"
|
||||
#include "srsran/phy/channel/ch_awgn.h"
|
||||
#include "srsran/phy/channel/delay.h"
|
||||
#include "srsran/phy/ue/ue_sync_nr.h"
|
||||
#include "srsran/phy/utils/debug.h"
|
||||
#include "srsran/phy/utils/ringbuffer.h"
|
||||
#include "srsran/phy/utils/vector.h"
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// NR parameters
|
||||
static uint32_t pci = 1; // Physical Cell Identifier
|
||||
static uint32_t carrier_nof_prb = 52; // Carrier bandwidth
|
||||
static srsran_subcarrier_spacing_t carrier_scs = srsran_subcarrier_spacing_15kHz;
|
||||
static srsran_subcarrier_spacing_t ssb_scs = srsran_subcarrier_spacing_30kHz;
|
||||
|
||||
// Test and channel parameters
|
||||
static uint32_t nof_sf = 1000; // Number of subframes to test
|
||||
static float cfo_hz = 100.0f; // CFO in Hz
|
||||
static float n0_dB = -10.0f; // Noise floor in dB relative to full-scale
|
||||
static float delay_min_us = 10.0f; // Minimum dynamic delay in microseconds
|
||||
static float delay_max_us = 1000.0f; // Maximum dynamic delay in microseconds
|
||||
static float delay_period_s = 60.0f; // Delay period in seconds
|
||||
|
||||
// Test context
|
||||
static double srate_hz = 0.0f; // Base-band sampling rate
|
||||
static uint32_t sf_len = 0; // Subframe length
|
||||
static cf_t* buffer = NULL; // Base-band buffer
|
||||
static cf_t* buffer2 = NULL; // Base-band buffer
|
||||
|
||||
static void usage(char* prog)
|
||||
{
|
||||
printf("Usage: %s [v]\n", prog);
|
||||
printf("\t-v [set srsran_verbose to debug, default none]\n");
|
||||
}
|
||||
|
||||
static void parse_args(int argc, char** argv)
|
||||
{
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "v")) != -1) {
|
||||
switch (opt) {
|
||||
case 'v':
|
||||
srsran_verbose++;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint32_t sf_idx;
|
||||
uint32_t sfn;
|
||||
srsran_ringbuffer_t ringbuffer;
|
||||
srsran_ssb_t ssb;
|
||||
srsran_timestamp_t timestamp;
|
||||
srsran_channel_awgn_t awgn;
|
||||
srsran_channel_delay_t delay;
|
||||
} test_context_t;
|
||||
|
||||
static void run_channel(test_context_t* ctx)
|
||||
{
|
||||
// Delay
|
||||
srsran_channel_delay_execute(&ctx->delay, buffer, buffer2, sf_len, &ctx->timestamp);
|
||||
|
||||
// CFO
|
||||
srsran_vec_apply_cfo(buffer2, -cfo_hz / srate_hz, buffer, sf_len);
|
||||
|
||||
// AWGN
|
||||
srsran_channel_awgn_run_c(&ctx->awgn, buffer, buffer, sf_len);
|
||||
}
|
||||
|
||||
static int test_context_init(test_context_t* ctx)
|
||||
{
|
||||
SRSRAN_MEM_ZERO(ctx, test_context_t, 1);
|
||||
|
||||
if (ctx == NULL) {
|
||||
return SRSRAN_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
|
||||
ctx->sfn = 1;
|
||||
|
||||
if (srsran_ringbuffer_init(&ctx->ringbuffer, (int)(10 * sf_len * sizeof(cf_t))) < SRSRAN_SUCCESS) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
srsran_ssb_args_t ssb_args = {};
|
||||
ssb_args.max_srate_hz = srate_hz;
|
||||
ssb_args.min_scs = carrier_scs;
|
||||
ssb_args.enable_encode = true;
|
||||
if (srsran_ssb_init(&ctx->ssb, &ssb_args) < SRSRAN_SUCCESS) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
srsran_ssb_cfg_t ssb_cfg = {};
|
||||
ssb_cfg.srate_hz = srate_hz;
|
||||
ssb_cfg.srate_hz = srate_hz;
|
||||
ssb_cfg.center_freq_hz = 3.5e9;
|
||||
ssb_cfg.ssb_freq_hz = 3.5e9 - 960e3;
|
||||
ssb_cfg.scs = ssb_scs;
|
||||
ssb_cfg.pattern = SRSRAN_SSB_PATTERN_C;
|
||||
if (srsran_ssb_set_cfg(&ctx->ssb, &ssb_cfg) < SRSRAN_SUCCESS) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
if (srsran_channel_delay_init(&ctx->delay, delay_min_us, delay_max_us, delay_period_s, 0, (uint32_t)srate_hz) <
|
||||
SRSRAN_SUCCESS) {
|
||||
ERROR("Init");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
if (srsran_channel_awgn_init(&ctx->awgn, 0x0) < SRSRAN_SUCCESS) {
|
||||
ERROR("Init");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
if (srsran_channel_awgn_set_n0(&ctx->awgn, n0_dB) < SRSRAN_SUCCESS) {
|
||||
ERROR("Init");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
static void test_context_free(test_context_t* ctx)
|
||||
{
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
srsran_ringbuffer_free(&ctx->ringbuffer);
|
||||
srsran_ssb_free(&ctx->ssb);
|
||||
srsran_channel_delay_free(&ctx->delay);
|
||||
srsran_channel_awgn_free(&ctx->awgn);
|
||||
}
|
||||
|
||||
static int recv_callback(void* ptr, cf_t** rx_buffer, uint32_t nof_samples, srsran_timestamp_t* timestamp)
|
||||
{
|
||||
test_context_t* ctx = (test_context_t*)ptr;
|
||||
|
||||
// Check inputs
|
||||
if (ctx == NULL || rx_buffer == NULL || rx_buffer[0] == NULL) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// Calculate the number of required bytes
|
||||
int required_nbytes = (int)sizeof(cf_t) * nof_samples;
|
||||
|
||||
// Execute subframe until the ringbuffer has data
|
||||
while (srsran_ringbuffer_status(&ctx->ringbuffer) < required_nbytes) {
|
||||
// Reset buffer
|
||||
srsran_vec_cf_zero(buffer, sf_len);
|
||||
|
||||
if (ctx->sf_idx % (SRSRAN_NOF_SF_X_FRAME / 2) == 0) {
|
||||
// Prepare PBCH message
|
||||
srsran_pbch_msg_nr_t pbch_msg = {};
|
||||
pbch_msg.ssb_idx = 0;
|
||||
pbch_msg.hrf = ctx->sf_idx >= (SRSRAN_NOF_SF_X_FRAME / 2);
|
||||
pbch_msg.sfn_4lsb = ctx->sfn & 0b1111U;
|
||||
|
||||
// Encode SSB
|
||||
if (srsran_ssb_add(&ctx->ssb, pci, &pbch_msg, buffer, buffer) < SRSRAN_SUCCESS) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// Run channel
|
||||
run_channel(ctx);
|
||||
|
||||
// Write in the ring buffer
|
||||
if (srsran_ringbuffer_write(&ctx->ringbuffer, buffer, (int)sf_len * sizeof(cf_t)) < SRSRAN_SUCCESS) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// Increment subframe index
|
||||
ctx->sf_idx++;
|
||||
|
||||
// Increment SFN if required
|
||||
if (ctx->sf_idx >= SRSRAN_NOF_SF_X_FRAME) {
|
||||
ctx->sfn = (ctx->sfn + 1) % 1024U;
|
||||
ctx->sf_idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
srsran_vec_cf_zero(buffer, sf_len);
|
||||
|
||||
// Read ringbuffer
|
||||
if (srsran_ringbuffer_read(&ctx->ringbuffer, rx_buffer[0], required_nbytes) < SRSRAN_SUCCESS) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// Setup timestamp
|
||||
*timestamp = ctx->timestamp;
|
||||
|
||||
// Advance timestamp
|
||||
srsran_timestamp_add(&ctx->timestamp, 0, (float)(nof_samples / srate_hz));
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
static int test_case_1(srsran_ue_sync_nr_t* ue_sync)
|
||||
{
|
||||
for (uint32_t sf_idx = 0; sf_idx < nof_sf; sf_idx++) {
|
||||
srsran_ue_sync_nr_outcome_t outcome = {};
|
||||
TESTASSERT(srsran_ue_sync_nr_zerocopy(ue_sync, &buffer, &outcome) == SRSRAN_SUCCESS);
|
||||
|
||||
// Print outcome
|
||||
INFO("measure - zerocpy in-sync=%s sf_idx=%d sfn=%d timestamp=%f cfo_hz=%+.1f delay_us=%+.3f",
|
||||
outcome.in_sync ? "y" : "n",
|
||||
outcome.sf_idx,
|
||||
outcome.sfn,
|
||||
srsran_timestamp_real(&outcome.timestamp),
|
||||
outcome.cfo_hz,
|
||||
outcome.delay_us);
|
||||
}
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ret = SRSRAN_ERROR;
|
||||
parse_args(argc, argv);
|
||||
|
||||
srate_hz = (double)SRSRAN_SUBC_SPACING_NR(carrier_scs) * srsran_min_symbol_sz_rb(carrier_nof_prb);
|
||||
sf_len = (uint32_t)ceil(srate_hz / 1000.0);
|
||||
buffer = srsran_vec_cf_malloc(sf_len);
|
||||
buffer2 = srsran_vec_cf_malloc(sf_len);
|
||||
|
||||
test_context_t ctx = {};
|
||||
srsran_ue_sync_nr_t ue_sync = {};
|
||||
|
||||
if (buffer == NULL) {
|
||||
ERROR("Malloc");
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
if (buffer2 == NULL) {
|
||||
ERROR("Malloc");
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
srsran_ue_sync_nr_args_t ue_sync_args = {};
|
||||
ue_sync_args.max_srate_hz = srate_hz;
|
||||
ue_sync_args.min_scs = carrier_scs;
|
||||
ue_sync_args.recv_obj = &ctx;
|
||||
ue_sync_args.recv_callback = &recv_callback;
|
||||
ue_sync_args.disable_cfo = false;
|
||||
if (srsran_ue_sync_nr_init(&ue_sync, &ue_sync_args) < SRSRAN_SUCCESS) {
|
||||
ERROR("Init");
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
srsran_ue_sync_nr_cfg_t ue_sync_cfg = {};
|
||||
ue_sync_cfg.ssb.srate_hz = srate_hz;
|
||||
ue_sync_cfg.ssb.center_freq_hz = 3.5e9;
|
||||
ue_sync_cfg.ssb.ssb_freq_hz = 3.5e9 - 960e3;
|
||||
ue_sync_cfg.ssb.scs = ssb_scs;
|
||||
ue_sync_cfg.ssb.pattern = SRSRAN_SSB_PATTERN_C;
|
||||
ue_sync_cfg.N_id = pci;
|
||||
if (srsran_ue_sync_nr_set_cfg(&ue_sync, &ue_sync_cfg) < SRSRAN_SUCCESS) {
|
||||
ERROR("Init");
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
if (test_context_init(&ctx) < SRSRAN_SUCCESS) {
|
||||
ERROR("Init");
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
if (test_case_1(&ue_sync) != SRSRAN_SUCCESS) {
|
||||
ERROR("test case failed");
|
||||
}
|
||||
|
||||
ret = SRSRAN_SUCCESS;
|
||||
|
||||
clean_exit:
|
||||
srsran_ue_sync_nr_free(&ue_sync);
|
||||
|
||||
if (buffer) {
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
if (buffer2) {
|
||||
free(buffer2);
|
||||
}
|
||||
|
||||
test_context_free(&ctx);
|
||||
|
||||
return ret;
|
||||
}
|
@ -0,0 +1,314 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 Software Radio Systems Limited
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srsran/phy/ue/ue_sync_nr.h"
|
||||
#include "srsran/phy/utils/vector.h"
|
||||
|
||||
#define UE_SYNC_NR_DEFAULT_CFO_ALPHA 0.1
|
||||
|
||||
int srsran_ue_sync_nr_init(srsran_ue_sync_nr_t* q, const srsran_ue_sync_nr_args_t* args)
|
||||
{
|
||||
// Check inputs
|
||||
if (q == NULL || args == NULL) {
|
||||
return SRSRAN_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
|
||||
// Copy arguments
|
||||
q->recv_obj = args->recv_obj;
|
||||
q->recv_callback = args->recv_callback;
|
||||
q->nof_rx_channels = args->nof_rx_channels == 0 ? 1 : args->nof_rx_channels;
|
||||
q->disable_cfo = args->disable_cfo;
|
||||
q->cfo_alpha = isnormal(args->cfo_alpha) ? args->cfo_alpha : UE_SYNC_NR_DEFAULT_CFO_ALPHA;
|
||||
|
||||
// Initialise SSB
|
||||
srsran_ssb_args_t ssb_args = {};
|
||||
ssb_args.max_srate_hz = args->max_srate_hz;
|
||||
ssb_args.min_scs = args->min_scs;
|
||||
ssb_args.enable_search = true;
|
||||
ssb_args.enable_decode = true;
|
||||
ssb_args.pbch_dmrs_thr = args->pbch_dmrs_thr;
|
||||
if (srsran_ssb_init(&q->ssb, &ssb_args) < SRSRAN_SUCCESS) {
|
||||
ERROR("Error SSB init");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// Allocate temporal buffer pointers
|
||||
q->tmp_buffer = SRSRAN_MEM_ALLOC(cf_t*, q->nof_rx_channels);
|
||||
if (q->tmp_buffer == NULL) {
|
||||
ERROR("Error alloc");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
void srsran_ue_sync_nr_free(srsran_ue_sync_nr_t* q)
|
||||
{
|
||||
// Check inputs
|
||||
if (q == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
srsran_ssb_free(&q->ssb);
|
||||
|
||||
if (q->tmp_buffer) {
|
||||
free(q->tmp_buffer);
|
||||
}
|
||||
|
||||
SRSRAN_MEM_ZERO(q, srsran_ue_sync_nr_t, 1);
|
||||
}
|
||||
|
||||
int srsran_ue_sync_nr_set_cfg(srsran_ue_sync_nr_t* q, const srsran_ue_sync_nr_cfg_t* cfg)
|
||||
{
|
||||
// Check inputs
|
||||
if (q == NULL || cfg == NULL) {
|
||||
return SRSRAN_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
|
||||
// Copy parameters
|
||||
q->N_id = cfg->N_id;
|
||||
q->srate_hz = cfg->ssb.srate_hz;
|
||||
|
||||
// Calculate new subframe size
|
||||
q->sf_sz = (uint32_t)round(1e-3 * q->srate_hz);
|
||||
|
||||
// Configure SSB
|
||||
if (srsran_ssb_set_cfg(&q->ssb, &cfg->ssb) < SRSRAN_SUCCESS) {
|
||||
ERROR("Error configuring SSB");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// Transition to find
|
||||
q->state = SRSRAN_UE_SYNC_NR_STATE_FIND;
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
static void ue_sync_nr_reset_feedback(srsran_ue_sync_nr_t* q)
|
||||
{
|
||||
SRSRAN_MEM_ZERO(&q->feedback, srsran_csi_trs_measurements_t, 1);
|
||||
}
|
||||
|
||||
static void ue_sync_nr_apply_feedback(srsran_ue_sync_nr_t* q)
|
||||
{
|
||||
// Skip any update if there is no feedback available
|
||||
if (q->feedback.nof_re == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update number of samples
|
||||
q->avg_delay_us = q->feedback.delay_us;
|
||||
q->next_rf_sample_offset = (uint32_t)round((double)q->avg_delay_us * (q->srate_hz * 1e-6));
|
||||
|
||||
// Integrate CFO
|
||||
if (q->disable_cfo) {
|
||||
q->cfo_hz = SRSRAN_VEC_SAFE_EMA(q->feedback.cfo_hz, q->cfo_hz, q->cfo_alpha);
|
||||
} else {
|
||||
q->cfo_hz += q->feedback.cfo_hz * q->cfo_alpha;
|
||||
}
|
||||
|
||||
// Reset feedback
|
||||
ue_sync_nr_reset_feedback(q);
|
||||
}
|
||||
|
||||
static int ue_sync_nr_run_find(srsran_ue_sync_nr_t* q, cf_t* buffer)
|
||||
{
|
||||
srsran_csi_trs_measurements_t measurements = {};
|
||||
srsran_pbch_msg_nr_t pbch_msg = {};
|
||||
|
||||
// Find SSB, measure PSS/SSS and decode PBCH
|
||||
if (srsran_ssb_find(&q->ssb, buffer, q->N_id, &measurements, &pbch_msg) < SRSRAN_SUCCESS) {
|
||||
ERROR("Error finding SSB");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// If the PBCH message was NOT decoded, early return
|
||||
if (!pbch_msg.crc) {
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
// Reset feedback to prevent any previous erroneous measurement
|
||||
ue_sync_nr_reset_feedback(q);
|
||||
|
||||
// Set feedback measurement
|
||||
srsran_combine_csi_trs_measurements(&q->feedback, &measurements, &q->feedback);
|
||||
|
||||
// Apply feedback
|
||||
ue_sync_nr_apply_feedback(q);
|
||||
|
||||
// Setup context
|
||||
q->ssb_idx = pbch_msg.ssb_idx;
|
||||
q->sf_idx = srsran_ssb_candidate_sf_idx(&q->ssb, pbch_msg.ssb_idx, pbch_msg.hrf);
|
||||
q->sfn = pbch_msg.sfn_4lsb;
|
||||
|
||||
// Transition to track only if the measured delay is below 2.4 microseconds
|
||||
if (measurements.delay_us < 2.4f) {
|
||||
q->state = SRSRAN_UE_SYNC_NR_STATE_TRACK;
|
||||
}
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
static int ue_sync_nr_run_track(srsran_ue_sync_nr_t* q, cf_t* buffer)
|
||||
{
|
||||
srsran_csi_trs_measurements_t measurements = {};
|
||||
srsran_pbch_msg_nr_t pbch_msg = {};
|
||||
uint32_t half_frame = q->sf_idx / (SRSRAN_NOF_SF_X_FRAME / 2);
|
||||
|
||||
// Check if the SSB selected candidate index shall be received in this subframe
|
||||
bool is_ssb_opportunity = (q->sf_idx == srsran_ssb_candidate_sf_idx(&q->ssb, q->ssb_idx, half_frame > 0));
|
||||
|
||||
// If
|
||||
if (is_ssb_opportunity) {
|
||||
// Measure PSS/SSS and decode PBCH
|
||||
if (srsran_ssb_track(&q->ssb, buffer, q->N_id, q->ssb_idx, half_frame, &measurements, &pbch_msg) < SRSRAN_SUCCESS) {
|
||||
ERROR("Error finding SSB");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// If the PBCH message was NOT decoded, transition to track
|
||||
if (!pbch_msg.crc) {
|
||||
q->state = SRSRAN_UE_SYNC_NR_STATE_FIND;
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
// Otherwise feedback measurements and apply
|
||||
srsran_combine_csi_trs_measurements(&q->feedback, &measurements, &q->feedback);
|
||||
}
|
||||
|
||||
// Apply accumulated feedback
|
||||
ue_sync_nr_apply_feedback(q);
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
static int ue_sync_nr_recv(srsran_ue_sync_nr_t* q, cf_t** buffer, srsran_timestamp_t* timestamp)
|
||||
{
|
||||
// Verify callback and srate are valid
|
||||
if (q->recv_callback == NULL && !isnormal(q->srate_hz)) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
uint32_t buffer_offset = 0;
|
||||
uint32_t nof_samples = q->sf_sz;
|
||||
|
||||
if (q->next_rf_sample_offset > 0) {
|
||||
// Discard a number of samples from RF
|
||||
if (q->recv_callback(q->recv_obj, buffer, (uint32_t)q->next_rf_sample_offset, timestamp) < SRSRAN_SUCCESS) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
} else {
|
||||
// Adjust receive buffer
|
||||
buffer_offset = (uint32_t)(-q->next_rf_sample_offset);
|
||||
nof_samples = (uint32_t)(q->sf_sz + q->next_rf_sample_offset);
|
||||
}
|
||||
q->next_rf_sample_offset = 0;
|
||||
|
||||
// Select buffer offsets
|
||||
for (uint32_t chan = 0; chan < q->nof_rx_channels; chan++) {
|
||||
// Set buffer to NULL if not present
|
||||
if (buffer[chan] == NULL) {
|
||||
q->tmp_buffer[chan] = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Initialise first offset samples to zero
|
||||
if (buffer_offset > 0) {
|
||||
srsran_vec_cf_zero(buffer[chan], buffer_offset);
|
||||
}
|
||||
|
||||
// Set to sample index
|
||||
q->tmp_buffer[chan] = &buffer[chan][buffer_offset];
|
||||
}
|
||||
|
||||
// Receive
|
||||
if (q->recv_callback(q->recv_obj, q->tmp_buffer, nof_samples, timestamp) < SRSRAN_SUCCESS) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// Compensate CFO
|
||||
for (uint32_t chan = 0; chan < q->nof_rx_channels; chan++) {
|
||||
if (buffer[chan] != 0 && !q->disable_cfo) {
|
||||
srsran_vec_apply_cfo(buffer[chan], q->cfo_hz / q->srate_hz, buffer[chan], (int)q->sf_sz);
|
||||
}
|
||||
}
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
int srsran_ue_sync_nr_zerocopy(srsran_ue_sync_nr_t* q, cf_t** buffer, srsran_ue_sync_nr_outcome_t* outcome)
|
||||
{
|
||||
// Check inputs
|
||||
if (q == NULL || buffer == NULL || outcome == NULL) {
|
||||
return SRSRAN_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
|
||||
// Verify callback is valid
|
||||
if (q->recv_callback == NULL) {
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// Receive
|
||||
if (ue_sync_nr_recv(q, buffer, &outcome->timestamp) < SRSRAN_SUCCESS) {
|
||||
ERROR("Error receiving baseband");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
|
||||
// Run FSM
|
||||
switch (q->state) {
|
||||
case SRSRAN_UE_SYNC_NR_STATE_IDLE:
|
||||
// Do nothing
|
||||
break;
|
||||
case SRSRAN_UE_SYNC_NR_STATE_FIND:
|
||||
if (ue_sync_nr_run_find(q, buffer[0]) < SRSRAN_SUCCESS) {
|
||||
ERROR("Error running find");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
break;
|
||||
case SRSRAN_UE_SYNC_NR_STATE_TRACK:
|
||||
if (ue_sync_nr_run_track(q, buffer[0]) < SRSRAN_SUCCESS) {
|
||||
ERROR("Error running track");
|
||||
return SRSRAN_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Increment subframe counter
|
||||
q->sf_idx++;
|
||||
|
||||
// Increment SFN
|
||||
if (q->sf_idx >= SRSRAN_NOF_SF_X_FRAME) {
|
||||
q->sfn = (q->sfn + 1) % 1024;
|
||||
q->sf_idx = 0;
|
||||
}
|
||||
|
||||
// Fill outcome
|
||||
outcome->in_sync = (q->state == SRSRAN_UE_SYNC_NR_STATE_TRACK);
|
||||
outcome->sf_idx = q->sf_idx;
|
||||
outcome->sfn = q->sfn;
|
||||
outcome->cfo_hz = q->cfo_hz;
|
||||
outcome->delay_us = q->avg_delay_us;
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
||||
|
||||
int srsran_ue_sync_nr_feedback(srsran_ue_sync_nr_t* q, const srsran_csi_trs_measurements_t* measurements)
|
||||
{
|
||||
if (q == NULL || measurements == NULL) {
|
||||
return SRSRAN_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
|
||||
// Accumulate feedback proportional to the number of elements provided by the measurement
|
||||
srsran_combine_csi_trs_measurements(&q->feedback, measurements, &q->feedback);
|
||||
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#
|
||||
# Copyright 2013-2021 Software Radio Systems Limited
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
if (RF_FOUND AND ENABLE_SRSUE AND ENABLE_SRSENB)
|
||||
add_executable(nr_phy_test nr_phy_test.cc)
|
||||
target_link_libraries(nr_phy_test
|
||||
srsue_phy_nr
|
||||
srsue_phy
|
||||
srsran_common
|
||||
srsran_phy
|
||||
srsran_radio
|
||||
srsenb_phy
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${Boost_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${Boost_LIBRARIES}
|
||||
${ATOMIC_LIBS})
|
||||
|
||||
add_nr_test(nr_phy_test nr_phy_test)
|
||||
endif ()
|
@ -0,0 +1,113 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 Software Radio Systems Limited
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srsenb/hdr/phy/nr/worker_pool.h"
|
||||
#include "srsran/common/test_common.h"
|
||||
#include "srsue/hdr/phy/nr/worker_pool.h"
|
||||
|
||||
class phy_common : public srsran::phy_common_interface
|
||||
{
|
||||
public:
|
||||
void
|
||||
worker_end(void* h, bool tx_enable, srsran::rf_buffer_t& buffer, srsran::rf_timestamp_t& tx_time, bool is_nr) override
|
||||
{}
|
||||
};
|
||||
|
||||
class ue_dummy_stack : public srsue::stack_interface_phy_nr
|
||||
{
|
||||
public:
|
||||
void in_sync() override {}
|
||||
void out_of_sync() override {}
|
||||
void run_tti(const uint32_t tti) override {}
|
||||
int sf_indication(const uint32_t tti) override { return 0; }
|
||||
sched_rnti_t get_dl_sched_rnti_nr(const uint32_t tti) override { return sched_rnti_t(); }
|
||||
sched_rnti_t get_ul_sched_rnti_nr(const uint32_t tti) override { return sched_rnti_t(); }
|
||||
void new_grant_dl(const uint32_t cc_idx, const mac_nr_grant_dl_t& grant, tb_action_dl_t* action) override {}
|
||||
void tb_decoded(const uint32_t cc_idx, const mac_nr_grant_dl_t& grant, tb_action_dl_result_t result) override {}
|
||||
void new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, tb_action_ul_t* action) override {}
|
||||
void prach_sent(uint32_t tti, uint32_t s_id, uint32_t t_id, uint32_t f_id, uint32_t ul_carrier_id) override {}
|
||||
bool sr_opportunity(uint32_t tti, uint32_t sr_id, bool meas_gap, bool ul_sch_tx) override { return false; }
|
||||
};
|
||||
|
||||
class test_bench
|
||||
{
|
||||
private:
|
||||
srsenb::nr::worker_pool gnb_phy;
|
||||
phy_common gnb_phy_com;
|
||||
srsue::nr::worker_pool ue_phy;
|
||||
phy_common ue_phy_com;
|
||||
ue_dummy_stack ue_stack;
|
||||
bool initialised = false;
|
||||
|
||||
public:
|
||||
struct args_t {
|
||||
uint32_t nof_threads = 6;
|
||||
uint32_t nof_prb = 52;
|
||||
|
||||
bool parse(int argc, char** argv);
|
||||
};
|
||||
|
||||
test_bench(const args_t& args) : ue_phy(args.nof_threads), gnb_phy(args.nof_threads)
|
||||
{
|
||||
// Prepare cell list
|
||||
srsenb::phy_cell_cfg_list_nr_t cell_list(1);
|
||||
cell_list[0].carrier.nof_prb = args.nof_prb;
|
||||
|
||||
// Prepare gNb PHY arguments
|
||||
srsenb::phy_args_t gnb_phy_args = {};
|
||||
|
||||
// Initialise gnb
|
||||
if (not gnb_phy.init(cell_list, gnb_phy_args, gnb_phy_com, srslog::get_default_sink(), 31)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare PHY
|
||||
srsue::phy_args_nr_t ue_phy_args = {};
|
||||
|
||||
// Initialise UE PHY
|
||||
if (not ue_phy.init(ue_phy_args, ue_phy_com, &ue_stack, 31)) {
|
||||
return;
|
||||
}
|
||||
|
||||
initialised = true;
|
||||
}
|
||||
|
||||
~test_bench()
|
||||
{
|
||||
gnb_phy.stop();
|
||||
ue_phy.stop();
|
||||
}
|
||||
|
||||
bool is_initialised() const { return initialised; }
|
||||
};
|
||||
|
||||
bool test_bench::args_t::parse(int argc, char** argv)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
test_bench::args_t args = {};
|
||||
|
||||
// Parse arguments
|
||||
TESTASSERT(args.parse(argc, argv));
|
||||
|
||||
// Create test bench
|
||||
test_bench tb(args);
|
||||
|
||||
// Assert bench is initialised correctly
|
||||
TESTASSERT(tb.is_initialised());
|
||||
|
||||
// If reached here, the test is successful
|
||||
return SRSRAN_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue