Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rainey19 committed Feb 7, 2024
1 parent c549fc0 commit 73c4712
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 97 deletions.
69 changes: 28 additions & 41 deletions configs/lime.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,47 @@
amf:
addr: 192.168.0.206
bind_addr: 192.168.0.116
addr: 172.22.0.10
bind_addr: 142.168.1.144

rf_driver:
ru_sdr:
device_driver: lime
# nrbandwidth, (rx/tx)lpf, (rx/tx)oversample, (rx/tx)gfir, (rx/tx)calibrate, (rx/tx)testSignal, (rx/tx)pathint, (rx/tx)path
# usepoll, rxPacketsInBatch, txMaxPacketsInBatch, rxSamplesInPacket, txSamplesInPacket, lmsconfig
# lna: 0-min, 15-max
# pga: 0-min, 31-max
# iamp: 0-min, 64-max
# txpad: 0-max, 31-min
device_args: rxpath=LNAH,txpath=BAND1,rxPacketsInBatch=1,txMaxPacketsInBatch=1,rxSamplesInPacket=1024,txSamplesInPacket=1024,lmsconfig=/home/user/repos/srsRAN_Project/configs/lms/xtrx_config.ini
clock:
sync:
srate: 11.52
# device_args: rxpath=LNAH,txpath=BAND1,rxPacketsInBatch=1,txMaxPacketsInBatch=1,rxSamplesInPacket=1024,txSamplesInPacket=1024,lmsconfig=/home/user/repos/srsRAN_Project/configs/lms/xtrx_config.ini
# device_args: rxcalibrate=1,txcalibrate=1,rxpath=LNAH,txpath=BAND1,rxPacketsInBatch=1,txMaxPacketsInBatch=1,rxSamplesInPacket=1024,txSamplesInPacket=1024
device_args: rxpath=LNAH,txpath=BAND1,rxPacketsInBatch=1,txMaxPacketsInBatch=1,rxSamplesInPacket=1024,txSamplesInPacket=1024
# clock:
# sync:
srate: 23.04
otw_format: sc16
tx_gain: 70
rx_gain: 50
time_alignment_calibration: # Rx to Tx radio time alignment calibration in samples.
tx_gain: 74
rx_gain: 74
# time_alignment_calibration: # Rx to Tx radio time alignment calibration in samples.
# Positive values reduce the RF transmission delay with respect
# to the RF reception, while negative values increase it

cell_cfg:
# dl_arfcn: 368640
# band: 3
dl_arfcn: 632628
band: 78
# dl_arfcn: 519000
# band: 41
channel_bandwidth_MHz: 10
common_scs: 30
plmn: "00101"
tac: 7
pci: 1
nof_antennas_ul: 1
nof_antennas_dl: 1
dl_arfcn: 518670 # ARFCN of the downlink carrier (center frequency).
band: 41 # The NR band.
channel_bandwidth_MHz: 20 # Bandwith in MHz. Number of PRBs will be automatically derived.
common_scs: 30 # Subcarrier spacing in kHz used for data.
plmn: "00101" # PLMN broadcasted by the gNB.
tac: 7 # Tracking area code (needs to match the core configuration).
pci: 1 # Physical cell ID.

amplitude_control:
tx_gain_backoff: 12 # Gain back-off to accommodate the signal PAPR in decibels
enable_clipping: 0 # Signal clipping
ceiling: -0.5 # Clipping ceiling referenced to full scale

expert_phy:
low_phy_thread_profile: quad
# expert_phy:
# low_phy_thread_profile: quad

log:
# filename: stdout
filename: /tmp/srslog.txt
all_level: info
filename: stdout
# filename: /tmp/gnb.log # Path of the log file.
all_level: warning # Logging level applied to all layers.
# radio_level: debug

pcap:
mac_enable: false
mac_filename: /tmp/gnb_mac.pcap
ngap_enable: false
ngap_filename: /tmp/gnb_ngap.pcap
mac_enable: false # Set to true to enable MAC-layer PCAPs.
mac_filename: /tmp/gnb_mac.pcap # Path where the MAC PCAP is stored.
ngap_enable: false # Set to true to enable NGAP PCAPs.
ngap_filename: /tmp/gnb_ngap.pcap # Path where the NGAP PCAP is stored.

# test_mode:
# test_ue:
Expand Down
32 changes: 17 additions & 15 deletions lib/radio/lime/radio_lime_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ if (reused_bool) { \
logger.error("Error setting {}! (returned {})", thing, reused_bool); \
}


/// \brief Determines whether a frequency is valid within a range.
///
/// A frequency is considered valid within a range if the range clips the frequency value within 1 Hz error.
Expand Down Expand Up @@ -134,6 +133,7 @@ class radio_lime_device : public lime_exception_handler
return true;
}

// TODO
bool get_mboard_sensor_names(std::vector<std::string>& sensors)
{
sensors.push_back("temp");
Expand Down Expand Up @@ -177,6 +177,7 @@ class radio_lime_device : public lime_exception_handler
return true;
}

// TODO
bool get_time_now(uint64_t& timespec)
{
timespec = 0;
Expand Down Expand Up @@ -338,10 +339,9 @@ class radio_lime_device : public lime_exception_handler
{
logger.debug("Setting channel {} Tx gain to {:.2f} dB.", ch, gain);

// TODO!

return safe_execution([this, ch, gain]() {
lime::Range range(0, 70, 0.1);
// WITH NEW_GAIN_BEHAVIOUR MAX GAIN VALUE IS 62
lime::Range range(0, 74, 0.1);

if (!radio_lime_device_validate_gain_range(range, gain)) {
on_error("Tx gain (i.e., {} dB) is out-of-range. Range is [{}, {}] dB in steps of {} dB.",
Expand All @@ -352,22 +352,22 @@ class radio_lime_device : public lime_exception_handler
return;
}

// TODO: not implemented in limesuite yet!
// LMS_SetGaindB(device->dev(), true, ch, gain);
// if (device->dev()->SetGain(0, lime::TRXDir::Tx, ch, lime::eGainTypes::UNKNOWN, gain)) {
// on_error("Error setting TX gain!");
// return;
// }

// lime::SDRDevice::SDRConfig& conf = device->GetDeviceConfig();
// conf.channel[ch].tx.gain = gain;
lime::SDRDevice::SDRConfig& conf = device->GetDeviceConfig();
conf.channel[ch].tx.gain.emplace(std::pair<lime::eGainTypes, double>(lime::eGainTypes::UNKNOWN, gain));
});
}

bool set_rx_gain(size_t ch, double gain)
{
logger.debug("Setting channel {} Rx gain to {:.2f} dB.", ch, gain);

// TODO!

return safe_execution([this, ch, gain]() {
lime::Range range(0, 70, 0.1);
lime::Range range(0, 74, 0.1);

if (!radio_lime_device_validate_gain_range(range, gain)) {
on_error("Rx gain (i.e., {} dB) is out-of-range. Range is [{}, {}] dB in steps of {} dB.",
Expand All @@ -378,11 +378,13 @@ class radio_lime_device : public lime_exception_handler
return;
}

// TODO: not implemented in limesuite yet!
// LMS_SetGaindB(device->dev(), false, ch, gain);
// if (device->dev()->SetGain(0, lime::TRXDir::Rx, ch, lime::eGainTypes::UNKNOWN, gain)) {
// on_error("Error setting TX gain!");
// return;
// }

// lime::SDRDevice::SDRConfig& conf = device->GetDeviceConfig();
// conf.channel[ch].rx.gain = gain;
lime::SDRDevice::SDRConfig& conf = device->GetDeviceConfig();
conf.channel[ch].rx.gain.emplace(std::pair<lime::eGainTypes, double>(lime::eGainTypes::UNKNOWN, gain));
});
}

Expand Down
4 changes: 0 additions & 4 deletions lib/radio/lime/radio_lime_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,16 @@ radio_session_lime_impl::radio_session_lime_impl(const radio_configuration::radi
}

// Set Tx rate.
double actual_tx_rate_Hz = 0.0;
if (!device.set_tx_rate(radio_config.sampling_rate_hz)) {
fmt::print("Error: setting Tx sampling rate. {}\n", device.get_error_message());
return;
}
srsran_assert(std::isnormal(actual_tx_rate_Hz), "Actual transmit sampling rate is invalid.");

// Set Rx rate.
double actual_rx_rate_Hz = 0.0;
if (!device.set_rx_rate(radio_config.sampling_rate_hz)) {
fmt::print("Error: setting Rx sampling rate. {}\n", device.get_error_message());
return;
}
srsran_assert(std::isnormal(actual_rx_rate_Hz), "Actual receive sampling rate is invalid.");

// Reset timestamps.
if ((total_rx_channel_count > 1 || total_tx_channel_count > 1) &&
Expand Down
18 changes: 9 additions & 9 deletions lib/radio/lime/radio_lime_rx_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ bool radio_lime_rx_stream::receive_block(unsigned& nof_rxd
// Extract number of samples.
unsigned num_samples = data.get_nof_samples() - offset;

// Protect concurrent call of reception and stop.
std::unique_lock<std::mutex> lock(stream_mutex);

// Ignore reception if it is not streaming.
if (state != states::STREAMING) {
nof_rxd_samples = num_samples;
Expand All @@ -50,10 +47,13 @@ bool radio_lime_rx_stream::receive_block(unsigned& nof_rxd
buffs_flat_ptr[channel] = (void*)data[channel].subspan(offset, num_samples).data();
}

md.timestamp = 0;
lime::complex32f_t** buffer = (lime::complex32f_t**)buffs_flat_ptr.data();

// Protect concurrent call of reception and stop.
std::unique_lock<std::mutex> lock(stream_mutex);

return safe_execution([this, buffs_flat_ptr, num_samples, &md, &nof_rxd_samples]() {
nof_rxd_samples = stream->StreamRx(chipIndex, (lime::complex16_t**)buffs_flat_ptr.data(), num_samples, &md);
return safe_execution([this, buffer, num_samples, &md, &nof_rxd_samples]() {
nof_rxd_samples = stream->StreamRx(chipIndex, buffer, num_samples, &md);
});
}

Expand Down Expand Up @@ -274,12 +274,12 @@ baseband_gateway_receiver::metadata radio_lime_rx_stream::receive(baseband_gatew

bool radio_lime_rx_stream::stop()
{
// Protect concurrent call of stop and reception.
std::unique_lock<std::mutex> lock(stream_mutex);

// Transition state to stop before locking to prevent real time priority thread owning the lock constantly.
state = states::STOP;

// Protect concurrent call of stop and reception.
std::unique_lock<std::mutex> lock(stream_mutex);

// Try to stop the stream.
stream->StreamStop(chipIndex);

Expand Down
13 changes: 12 additions & 1 deletion lib/radio/lime/radio_lime_sdrdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
#include "radio_lime_handle.h"
#pragma GCC diagnostic pop


struct RxGainRow {
int lna;
int pga;
};

struct TxGainRow {
int main;
int lin;
};

namespace lime
{
static inline int64_t ts_to_time(int64_t fs, int64_t ts)
Expand All @@ -50,4 +61,4 @@ namespace lime
void* state_fsm;
void* notifier;
} callback_info_t;
}
}
47 changes: 21 additions & 26 deletions lib/radio/lime/radio_lime_tx_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,14 @@ bool recv_async_msg(bool is_tx, const lime::SDRDevice::StreamStats *stream_stats
bool radio_lime_tx_stream::transmit_block(unsigned& nof_txd_samples,
const baseband_gateway_buffer_reader& buffs,
unsigned buffer_offset,
uint64_t time_spec)
lime::SDRDevice::StreamMeta& md)
{
// if (state_fsm.is_stopped()) {
// return false;
// }

// Prepare metadata.
lime::SDRDevice::StreamMeta meta;

// Extract number of samples.
unsigned num_samples = buffs[0].size() - buffer_offset;

// Make sure the number of channels is equal.
report_fatal_error_if_not(buffs.get_nof_channels() == nof_channels, "Number of channels does not match.");

// Run states.
// if (!state_fsm.transmit_block(meta, time_spec)) {
// nof_txd_samples = num_samples;
// return true;
// }
// TODO: add burst flags back in!
// meta.flush = (md->flags & TRX_WRITE_MD_FLAG_END_OF_BURST);
meta.flush=false;
meta.timestamp=time_spec;
meta.useTimestamp=true;

// Flatten buffers.
static_vector<void*, RADIO_MAX_NOF_CHANNELS> buffs_flat_ptr(nof_channels);
for (unsigned channel = 0; channel != nof_channels; ++channel) {
Expand All @@ -99,12 +81,10 @@ bool radio_lime_tx_stream::transmit_block(unsigned& n
const lime::complex32f_t** buffer = const_cast<const lime::complex32f_t **>((lime::complex32f_t**)buffs_flat_ptr.data());

// Safe transmission.
return safe_execution([this, &buffer, num_samples, &meta, &nof_txd_samples]() {
nof_txd_samples = stream->StreamTx(chipIndex, buffer, num_samples, &meta);
return safe_execution([this, &buffer, num_samples, &md, &nof_txd_samples]() {
nof_txd_samples = stream->StreamTx(chipIndex, buffer, num_samples, &md);
// TODO: if nof_txd_samples < 0, increment underrun flag!
});

return true;
}

radio_lime_tx_stream::radio_lime_tx_stream(std::shared_ptr<LimeHandle> device_,
Expand Down Expand Up @@ -278,21 +258,36 @@ void radio_lime_tx_stream::transmit(const baseband_gateway_buffer_reader& data,
// Protect stream transmitter.
std::unique_lock<std::mutex> lock(stream_transmit_mutex);

uint64_t time_spec = tx_md.ts;
lime::SDRDevice::StreamMeta meta;

unsigned nsamples = data.get_nof_samples();
unsigned txd_samples_total = 0;

// Run states.
// if (!state_fsm.transmit_block(meta, time_spec)) {
// nof_txd_samples = num_samples;
// return true;
// }
// TODO: add burst flags back in!
// meta.flush = (md->flags & TRX_WRITE_MD_FLAG_END_OF_BURST);
meta.flush=false;
meta.timestamp=tx_md.ts;
meta.useTimestamp=true;

if (state_fsm.is_stopping()) {
return;
}

// Receive stream in multiple blocks.
while (txd_samples_total < nsamples) {
unsigned txd_samples = 0;
if (!transmit_block(txd_samples, data, txd_samples_total, time_spec)) {
if (!transmit_block(txd_samples, data, txd_samples_total, meta)) {
logger.error("Error: failed transmitting packet. {}.", get_error_message().c_str());
return;
}

// Save timespec for first block.
time_spec += txd_samples;
meta.timestamp += txd_samples;

// Increment the total amount of received samples.
txd_samples_total += txd_samples;
Expand Down
2 changes: 1 addition & 1 deletion lib/radio/lime/radio_lime_tx_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class radio_lime_tx_stream : public baseband_gateway_transmitter, public lime_ex
bool transmit_block(unsigned& nof_txd_samples,
const baseband_gateway_buffer_reader& data,
unsigned offset,
uint64_t time_spec);
lime::SDRDevice::StreamMeta& md);

public:
/// Describes the necessary parameters to create a Lime transmit stream.
Expand Down

0 comments on commit 73c4712

Please sign in to comment.