Skip to content

Commit

Permalink
Gain configuration for different devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojeker committed Apr 29, 2024
1 parent 2b0d4b1 commit e370c20
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
8 changes: 4 additions & 4 deletions configs/lime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ slicing:
sd: 1

amf:
addr: 10.43.205.70
addr: 10.43.28.216
bind_addr: 192.168.0.104

#ru_sdr:
Expand Down Expand Up @@ -35,7 +35,7 @@ ru_sdr:
device_driver: lime
# LNAH, LNAL, LNAW
# device_args: rxcalibrate=0,txcalibrate=0,usepoll=1,rxpath=LNAL,txpath=BAND1,rxPacketsInBatch=2,txMaxPacketsInBatch=1,rxSamplesInPacket=1024,txSamplesInPacket=1024,rxoversample=2,txoversample=2,lmsconfig=/home/sens/Download/srs-5g/configs/xtrx_cfgs/LimeSDR.ini
device_args: usepoll=1,rxpath=LNAL,txpath=BAND1,rxPacketsInBatch=2,txMaxPacketsInBatch=1,rxSamplesInPacket=1024,txSamplesInPacket=1024,rxoversample=2,txoversample=2,lmsconfig=/home/sens/Download/srs-5g/configs/xtrx_cfgs/LimeSDR.ini
device_args: usepoll=1,rxpath=LNAL,txpath=BAND1,rxPacketsInBatch=2,txMaxPacketsInBatch=1,rxSamplesInPacket=1024,txSamplesInPacket=1024,rxoversample=2,txoversample=2,lmsconfig=/home/sens/Downloads/srs-5g/configs/xtrx_cfgs/LimeSDR.ini
# clock:
# sync:
# srate: 92.16
Expand All @@ -54,8 +54,8 @@ cell_cfg:
#channel_bandwidth_MHz: 60
# channel_bandwidth_MHz: 80
common_scs: 30 # Subcarrier spacing in kHz used for data.
plmn: "001001"
#plmn: "00104" # PLMN broadcasted by the gNB.
# plmn: "001001"
plmn: "00101"
tac: 1 # Tracking area code (needs to match the core configuration).
pci: 1 # Physical cell ID.
tdd_ul_dl_cfg:
Expand Down
13 changes: 9 additions & 4 deletions lib/radio/lime/radio_lime_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,19 @@ class radio_lime_device : public lime_exception_handler
logger.debug("Radio configured in {}ms.", std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count());
}

bool set_tx_gain(unsigned ch, double gain)
bool set_tx_gain(unsigned ch, double gain){
// By default, set the PAD gain (i.e., the internal PA gain)
return set_tx_gain(ch, lime::eGainTypes::PAD, gain);
}

bool set_tx_gain(unsigned ch, lime::eGainTypes gainType, double gain)
{
logger.debug("Setting channel {} Tx gain to {:.2f} dB.", ch, gain);

return safe_execution([this, ch, gain]() {
return safe_execution([this, ch, gainType, gain]() {

// Use the internal PA (currently no external amplifier is used!)
lime::Range range = device->dev()->GetDescriptor().rfSOC[0].gainRange.at(lime::TRXDir::Tx).at(lime::eGainTypes::UNKNOWN);
lime::Range range = device->dev()->GetDescriptor().rfSOC[0].gainRange.at(lime::TRXDir::Tx).at(gainType);
logger.debug("Range for TX gain is [{}, {}] w/ step {}", range.min, range.max, range.step);

if (!radio_lime_device_validate_gain_range(range, gain)) {
Expand All @@ -364,7 +369,7 @@ class radio_lime_device : public lime_exception_handler

// Set all channels at once
for(int i = 0; i < device->GetChannelCount(); i++){
lime::OpStatus stat = device->dev()->SetGain(0, lime::TRXDir::Tx, i, lime::eGainTypes::UNKNOWN, gain);
lime::OpStatus stat = device->dev()->SetGain(0, lime::TRXDir::Tx, i, gainType, gain);
if(stat != lime::OpStatus::Success){
on_error("Could not configure channel {} to frequency {}", i, gain);
}
Expand Down
25 changes: 19 additions & 6 deletions lib/radio/lime/radio_lime_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool radio_session_lime_impl::wait_sensor_locked(const std::string& sensor_name,
return is_locked;
}

bool radio_session_lime_impl::set_tx_gain_unprotected(unsigned port_idx, double gain_dB)
bool radio_session_lime_impl::set_tx_gain_unprotected(unsigned port_idx, lime::eGainTypes gainType, double gain_dB)
{
if (port_idx >= tx_port_map.size()) {
fmt::print(
Expand All @@ -118,14 +118,14 @@ bool radio_session_lime_impl::set_tx_gain_unprotected(unsigned port_idx, double
}

// Setup gain.
if (!device.set_tx_gain(port_idx, gain_dB)) {
if (!device.set_tx_gain(port_idx, gainType, gain_dB)) {
fmt::print("Error: setting gain for transmitter {}. {}\n", port_idx, device.get_error_message());
}

return true;
}

bool radio_session_lime_impl::set_rx_gain_unprotected(unsigned port_idx, double gain_dB)
bool radio_session_lime_impl::set_rx_gain_unprotected(unsigned port_idx, lime::eGainTypes gainType, double gain_dB)
{
if (port_idx >= rx_port_map.size()) {
fmt::print("Error: receive port index ({}) exceeds the number of ports ({}).\n", port_idx, (int)rx_port_map.size());
Expand Down Expand Up @@ -306,12 +306,19 @@ radio_session_lime_impl::radio_session_lime_impl(const radio_configuration::radi
device.set_time_unknown_pps(0);
}


fmt::print("Setting up the Center Frequencies! [RX / TX]");


// Lists of stream descriptions.
std::vector<radio_lime_tx_stream::stream_description> tx_stream_description_list;
std::vector<radio_lime_rx_stream::stream_description> rx_stream_description_list;

// For each transmit stream, create stream and configure RF ports.
for (unsigned stream_idx = 0; stream_idx != radio_config.tx_streams.size(); ++stream_idx) {

fmt::print("Configuring steram {}", stream_idx);

// Select stream.
const radio_configuration::stream& stream = radio_config.tx_streams[stream_idx];

Expand Down Expand Up @@ -342,8 +349,9 @@ radio_session_lime_impl::radio_session_lime_impl(const radio_configuration::radi
// Extract port configuration.
const radio_configuration::channel& channel = stream.channels[channel_idx];

// Setup gain.
set_tx_gain_unprotected(port_idx, channel.gain_dB);
// Setup gain. (PAD is the one in the config, the IAMP is max by default)
set_tx_gain_unprotected(port_idx, lime::eGainTypes::IAMP, 12);
set_tx_gain_unprotected(port_idx, lime::eGainTypes::PAD, channel.gain_dB);

// Setup frequency.
if (!set_tx_freq(port_idx, channel.freq)) {
Expand Down Expand Up @@ -393,7 +401,12 @@ radio_session_lime_impl::radio_session_lime_impl(const radio_configuration::radi
const radio_configuration::channel& channel = stream.channels[channel_idx];

// Setup gain.
if (!set_rx_gain_unprotected(port_idx, channel.gain_dB)) {
bool res = set_rx_gain_unprotected(port_idx, lime::eGainTypes::LNA, channel.gain_dB);
res = res || set_rx_gain_unprotected(port_idx, lime::eGainTypes::PGA, 19);
res = res || set_rx_gain_unprotected(port_idx, lime::eGainTypes::TIA, 12);

// Check the config was successful.
if (!res) {
return;
}

Expand Down
19 changes: 15 additions & 4 deletions lib/radio/lime/radio_lime_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ class radio_session_lime_impl : public radio_session, private radio_management_p

/// \brief Set transmission gain from the class itself.
/// \param[in] port_idx Indicates the port index.
/// \param[in] gainType Gain Type [PAD, IAMP - [0;52], [-12;12] respectively
/// \param[in] gain_dB Indicates the gain value.
/// \return True if the port index and gain value are valid, and no exception is caught. Otherwise false.
bool set_tx_gain_unprotected(unsigned port_idx, double gain_dB);
bool set_tx_gain_unprotected(unsigned port_idx, lime::eGainTypes gainType, double gain_dB);

/// \brief Set reception gain from the class itself.
/// \param[in] port_idx Indicates the port index.
/// \param[in] gainType Gain Type [LNA, PGA, TIA - [0;30], [-12;19], [0;12] respectively
/// \param[in] gain_dB Indicates the gain value.
/// \return True if the port index and gain value are valid, and no exception is caught. Otherwise false.
bool set_rx_gain_unprotected(unsigned port_idx, double gain_dB);
bool set_rx_gain_unprotected(unsigned port_idx, lime::eGainTypes gainType, double gain_dB);

/// \brief Set transmission frequency.
/// \param[in] port_idx Indicates the port index.
Expand Down Expand Up @@ -136,10 +138,19 @@ class radio_session_lime_impl : public radio_session, private radio_management_p
void stop() override;

// See interface for documentation.
bool set_tx_gain(unsigned port_idx, double gain_dB) override { return set_tx_gain_unprotected(port_idx, gain_dB); }
// Set the power amplifier gain in dB [0; 52]
bool set_tx_gain(unsigned ch, double gain) override {return set_tx_gain(ch, lime::eGainTypes::PAD, gain);};

// Set the power amplifier gain in dB [0; 52]
// Set the IAMP gain [-12; 12]
bool set_tx_gain(unsigned port_idx, lime::eGainTypes gainType, double gain_dB) { return set_tx_gain_unprotected(port_idx, gainType, gain_dB); }


// See interface for documentation.
bool set_rx_gain(unsigned port_idx, double gain_dB) override { return set_rx_gain_unprotected(port_idx, gain_dB); }
// Set the LNA gain in dB [0; 30]
bool set_rx_gain(unsigned port_idx, double gain_dB) override { return set_rx_gain(port_idx, lime::eGainTypes::LNA, gain_dB); }
// Set LNA [0;30], PGA [-12;19], TIA [0;12]
bool set_rx_gain(unsigned port_idx, lime::eGainTypes gainType, double gain_dB) { return set_rx_gain_unprotected(port_idx, gainType, gain_dB); }
};

class radio_factory_lime_impl : public radio_factory
Expand Down
9 changes: 6 additions & 3 deletions lib/radio/lime/radio_lime_rx_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ radio_lime_rx_stream::radio_lime_rx_stream(std::shared_ptr<LimeHandle> device_,

logger.debug("Creating receive stream {}.", id);

srslog::fetch_basic_logger("LOWER PHY").debug(
"eduard | radio_lime_rx_stream.cpp | radio_lime_rx_stream (constructor): srate_Hz={}", srate_Hz);
logger.debug("eduard | radio_lime_rx_stream.cpp | radio_lime_rx_stream (constructor): srate_Hz={}", srate_Hz);


// Get the number of channels and check if valid
// unsigned int availablePortsRX = device->GetStreamConfig().channels[lime::TRXDir::Rx].size();
// unsigned int availablePortsTX = device->GetStreamConfig().channels[lime::TRXDir::Tx].size();
Expand All @@ -95,6 +93,8 @@ radio_lime_rx_stream::radio_lime_rx_stream(std::shared_ptr<LimeHandle> device_,
return;
}

logger.debug("eduard | radio_lime_rx_stream.cpp | radio_lime_rx_stream (constructor): availRxPorts={}, availTxPorts={}, nof_channels={}", availablePortsRX, availablePortsTX, nof_channels);

// Build stream arguments.
lime::DataFormat wire_format;

Expand Down Expand Up @@ -129,6 +129,9 @@ radio_lime_rx_stream::radio_lime_rx_stream(std::shared_ptr<LimeHandle> device_,
device->GetStreamConfig().channels.at(lime::TRXDir::Rx).push_back(i);

device->GetDeviceConfig().channel[i].rx.enabled = true;

device->GetDeviceConfig().channel[i].rx.lpf = 0;
device->GetDeviceConfig().channel[i].rx.calibrate = false;
device->GetDeviceConfig().channel[i].rx.sampleRate = srate_Hz;
device->GetDeviceConfig().channel[i].rx.oversample = 2;
}
Expand Down

0 comments on commit e370c20

Please sign in to comment.