UHD: Improved RFNOC

master
Xavier Arteaga 4 years ago committed by Xavier Arteaga
parent 38d9545e99
commit dcf05f7a53

@ -126,8 +126,8 @@ public:
return err;
}
size_t max_samp = 0;
err = get_rx_stream(max_samp);
size_t max_samp = 0;
err = get_rx_stream(max_samp);
// If no error getting RX stream, return
if (err == UHD_ERROR_NONE) {

@ -120,7 +120,7 @@ struct rf_uhd_handler_t {
double current_master_clock = 0.0;
bool rx_stream_enabled = false;
bool rx_stream_enabled = false;
std::mutex tx_mutex;
std::mutex rx_mutex;

@ -56,8 +56,8 @@ private:
// Constant parameters
const std::string RADIO_BLOCK_NAME = "Radio";
const std::string DDC_BLOCK_NAME = "DDC";
const std::string DUC_BLOCK_NAME = "DUC";
const std::string DDC_BLOCK_NAME = "DDC";
const std::string DUC_BLOCK_NAME = "DUC";
#ifdef UHD_ENABLE_CUSTOM_RFNOC
const std::string DDC_CUSTOM_BLOCK_NAME = "DDCch2";
const std::string DUC_CUSTOM_BLOCK_NAME = "DUCch2";
@ -69,7 +69,7 @@ private:
const uhd::fs_path TREE_RX_SENSORS = "/mboards/0/dboards/A/rx_frontends/0/sensors";
const std::string TX_ANTENNA_PORT = "TX/RX";
const std::string RX_ANTENNA_PORT = "RX2";
const size_t spp = 246;
const size_t spp = 1920 / 8;
// Primary parameters
double master_clock_rate = 184.32e6;
@ -78,8 +78,7 @@ private:
size_t nof_channels = 1; ///< Number of Channels per Radio
std::vector<double> rx_freq_hz;
std::vector<double> tx_freq_hz;
size_t nof_samples_per_packet = spp * 4 + 2 * sizeof(uint64_t);
size_t dma_fifo_depth = 8192UL * 4096UL;
size_t dma_fifo_depth = 8192UL * 4096UL;
// Radio control
std::vector<uhd::rfnoc::radio_ctrl::sptr> radio_ctrl = {};
@ -181,7 +180,10 @@ private:
radio_ctrl[i]->set_tx_antenna(TX_ANTENNA_PORT, 0);
radio_ctrl[i]->enable_rx_timestamps(true, 0);
radio_ctrl[i]->set_arg("spp", spp);
if (spp) {
radio_ctrl[i]->set_arg("spp", spp);
}
}
// Sleep for some time
@ -274,6 +276,12 @@ private:
uhd_error connect()
{
size_t nof_samples_per_packet = 0;
if (spp != 0) {
nof_samples_per_packet = spp * 4 + 2 * sizeof(uint64_t);
}
UHD_SAFE_C_SAVE_ERROR(this,
// Get Tx and Rx Graph
@ -437,7 +445,8 @@ public:
this, uhd::stream_args_t stream_args("fc32", "sc16");
stream_args.channels.resize(nof_radios * nof_channels);
stream_args.args["spp"] = std::to_string(spp);
if (spp != 0) { stream_args.args["spp"] = std::to_string(spp); }
// Populate stream arguments with RF-NOC blocks interfaces
size_t channel_count = 0;
@ -461,7 +470,7 @@ public:
this, uhd::stream_args_t stream_args("fc32", "sc16");
stream_args.channels.resize(nof_radios * nof_channels);
stream_args.args["spp"] = std::to_string(spp);
if (spp != 0) { stream_args.args["spp"] = std::to_string(spp); }
// Populate stream arguments with RF-NOC blocks interfaces
size_t channel_count = 0;
@ -546,33 +555,34 @@ public:
tx_freq_hz[ch] = target_freq;
actual_freq = tx_freq_hz[ch];
UHD_SAFE_C_SAVE_ERROR(this,
Debug("Tuning Tx " << ch << " to " << actual_freq / 1e6 << " MHz...");
size_t i = ch / nof_channels;
// For each radio...
for (size_t i = 0; i < nof_radios; i++) {
// Calculate center frequency from average
double center_freq_hz = 0.0;
for (size_t j = 0; j < nof_channels; j++) {
if (not std::isnormal(tx_freq_hz[i * nof_channels + j])) {
tx_freq_hz[i * nof_channels + j] = target_freq;
}
center_freq_hz += tx_freq_hz[i * nof_channels + j];
}
center_freq_hz /= nof_channels;
// Calculate center frequency from average
double center_freq_hz = 0.0;
for (size_t j = 0; j < nof_channels; j++) {
if (not std::isnormal(tx_freq_hz[i * nof_channels + j])) {
tx_freq_hz[i * nof_channels + j] = target_freq;
}
center_freq_hz += tx_freq_hz[i * nof_channels + j];
}
center_freq_hz /= nof_channels;
// Set Radio Tx freq
UHD_LOG_DEBUG(radio_id[i], "Setting TX Freq: " << center_freq_hz / 1e6 << " MHz...");
radio_ctrl[i]->set_tx_frequency(center_freq_hz, 0);
center_freq_hz = radio_ctrl[i]->get_tx_frequency(0);
UHD_LOG_DEBUG(radio_id[i], "Actual TX Freq: " << center_freq_hz / 1e6 << " MHz...");
UHD_SAFE_C_SAVE_ERROR(
this,
// Setup DUC
for (size_t j = 0; j < nof_channels; j++) {
double freq_hz = tx_freq_hz[nof_channels * i + j] - center_freq_hz;
UHD_LOG_DEBUG(duc_id[i], "Setting " << j << " freq: " << freq_hz / 1e6 << " MHz ...");
duc_ctrl[i]->set_arg("freq", std::to_string(freq_hz), j);
}
})
// Set Radio Tx freq
UHD_LOG_DEBUG(radio_id[i], "Setting TX Freq: " << center_freq_hz / 1e6 << " MHz...");
radio_ctrl[i]->set_tx_frequency(center_freq_hz, 0);
center_freq_hz = radio_ctrl[i]->get_tx_frequency(0);
UHD_LOG_DEBUG(radio_id[i], "Actual TX Freq: " << center_freq_hz / 1e6 << " MHz...");
// Setup DUC
for (size_t j = 0; j < nof_channels; j++) {
double freq_hz = tx_freq_hz[nof_channels * i + j] - center_freq_hz;
UHD_LOG_DEBUG(duc_id[i], "Setting " << j << " freq: " << freq_hz / 1e6 << " MHz ...");
duc_ctrl[i]->set_arg("freq", std::to_string(freq_hz), j);
})
}
uhd_error set_rx_freq(uint32_t ch, double target_freq, double& actual_freq) override
{
@ -596,30 +606,34 @@ public:
rx_freq_hz[ch] = target_freq;
actual_freq = rx_freq_hz[ch];
UHD_SAFE_C_SAVE_ERROR(this, for (size_t i = 0; i < nof_radios; i++) {
// Calculate center frequency from average
double center_freq_hz = 0.0;
for (size_t j = 0; j < nof_channels; j++) {
if (not std::isnormal(rx_freq_hz[i * nof_channels + j])) {
rx_freq_hz[i * nof_channels + j] = target_freq;
}
center_freq_hz += rx_freq_hz[i * nof_channels + j];
Debug("Tuning Rx " << ch << " to " << actual_freq / 1e6 << " MHz...");
size_t i = ch / nof_channels;
// Calculate center frequency from average
double center_freq_hz = 0.0;
for (size_t j = 0; j < nof_channels; j++) {
if (not std::isnormal(rx_freq_hz[i * nof_channels + j])) {
rx_freq_hz[i * nof_channels + j] = target_freq;
}
center_freq_hz /= nof_channels;
center_freq_hz += rx_freq_hz[i * nof_channels + j];
}
center_freq_hz /= nof_channels;
// Set Radio Tx freq
UHD_LOG_DEBUG(radio_id[i], "Setting RX Freq: " << center_freq_hz / 1e6 << " MHz...");
radio_ctrl[i]->set_rx_frequency(center_freq_hz, 0);
center_freq_hz = radio_ctrl[i]->get_rx_frequency(0);
UHD_LOG_DEBUG(radio_id[i], "Actual RX Freq: " << center_freq_hz / 1e6 << " MHz...");
UHD_SAFE_C_SAVE_ERROR(
this,
// Setup DDC
for (size_t j = 0; j < nof_channels; j++) {
double freq_hz = center_freq_hz - rx_freq_hz[nof_channels * i + j];
UHD_LOG_DEBUG(ddc_id[i], "Setting " << j << " freq: " << freq_hz / 1e6 << " MHz ...");
ddc_ctrl[i]->set_arg("freq", freq_hz, j);
}
})
// Set Radio Tx freq
UHD_LOG_DEBUG(radio_id[i], "Setting RX Freq: " << center_freq_hz / 1e6 << " MHz...");
radio_ctrl[i]->set_rx_frequency(center_freq_hz, 0);
center_freq_hz = radio_ctrl[i]->get_rx_frequency(0);
UHD_LOG_DEBUG(radio_id[i], "Actual RX Freq: " << center_freq_hz / 1e6 << " MHz...");
// Setup DDC
for (size_t j = 0; j < nof_channels; j++) {
double freq_hz = center_freq_hz - rx_freq_hz[nof_channels * i + j];
UHD_LOG_DEBUG(ddc_id[i], "Setting " << j << " freq: " << freq_hz / 1e6 << " MHz ...");
ddc_ctrl[i]->set_arg("freq", freq_hz, j);
})
}
};

@ -119,7 +119,7 @@ public:
virtual uhd_error get_rx_sensor(const std::string& sensor_name, uhd::sensor_value_t& sensor_value) = 0;
virtual uhd_error set_time_unknown_pps(const uhd::time_spec_t& timespec) = 0;
virtual uhd_error get_time_now(uhd::time_spec_t& timespec) = 0;
virtual uhd_error start_rx_stream(double delay)
uhd_error start_rx_stream(double delay)
{
uhd::time_spec_t time_spec;
uhd_error err = get_time_now(time_spec);
@ -134,7 +134,7 @@ public:
rx_stream->issue_stream_cmd(stream_cmd);)
}
virtual uhd_error stop_rx_stream()
uhd_error stop_rx_stream()
{
UHD_SAFE_C_SAVE_ERROR(this, uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
rx_stream->issue_stream_cmd(stream_cmd);)
@ -155,7 +155,7 @@ public:
virtual uhd_error get_tx_gain(double& gain) = 0;
virtual uhd_error set_tx_freq(uint32_t ch, double target_freq, double& actual_freq) = 0;
virtual uhd_error set_rx_freq(uint32_t ch, double target_freq, double& actual_freq) = 0;
virtual uhd_error receive(void** buffs,
uhd_error receive(void** buffs,
const size_t nsamps_per_buff,
uhd::rx_metadata_t& metadata,
const double timeout,
@ -169,11 +169,11 @@ public:
{
UHD_SAFE_C_SAVE_ERROR(this, valid = tx_stream->recv_async_msg(async_metadata, timeout);)
}
virtual uhd_error send(void** buffs,
const size_t nsamps_per_buff,
const uhd::tx_metadata_t& metadata,
const double timeout,
size_t& nof_txd_samples)
uhd_error send(void** buffs,
const size_t nsamps_per_buff,
const uhd::tx_metadata_t& metadata,
const double timeout,
size_t& nof_txd_samples)
{
UHD_SAFE_C_SAVE_ERROR(this, uhd::tx_streamer::buffs_type buffs_cpp(buffs, tx_stream->get_num_channels());
nof_txd_samples = tx_stream->send(buffs_cpp, nsamps_per_buff, metadata, timeout);)

Loading…
Cancel
Save