Skip to content

Commit

Permalink
ubx: Fix width of gain register
Browse files Browse the repository at this point in the history
- Fix width of gain portion of GPIO. It was declared as 10, but is only
  6.
- Remove _ubx_tx_atten_val and _ubx_rx_atten_val which serve no purpose,
  and are in fact redundant, since their value is already in the regs
  objects for TX and RX.
- Change a UHD_LOGGER_TRACE() into UHD_LOG_TRACE() to gain max speed
  improvements for builds that do not have TRACE as their minimum log
  level.

Note: While this was a bug, the main reason it didn't cause harm is
because gain values got clipped to a max of 31.5 dB, which corresponds
to a gain code of 63, which is exactly 6 bits wide (0b111111).
  • Loading branch information
mbr0wn authored and joergho committed Mar 20, 2024
1 parent f6b0e4a commit 20e987d
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions host/lib/usrp/dboard/db_ubx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ static const ubx_gpio_field_info_t ubx_proto_gpio_info[] = {
{TX_LO_LOCKED, dboard_iface::UNIT_TX, 6, 0x1<<6, 1, ubx_gpio_field_info_t::OUTPUT, false, 0, 0, 0, 0},
{RX_LO_LOCKED, dboard_iface::UNIT_TX, 7, 0x1<<7, 1, ubx_gpio_field_info_t::OUTPUT, false, 0, 0, 0, 0},
{CPLD_RST_N, dboard_iface::UNIT_TX, 9, 0x1<<9, 1, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0},
{TX_GAIN, dboard_iface::UNIT_TX, 10, 0x3F<<10, 10, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0},
{RX_GAIN, dboard_iface::UNIT_RX, 10, 0x3F<<10, 10, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0}
{TX_GAIN, dboard_iface::UNIT_TX, 10, 0x3F<<10, 6, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0},
{RX_GAIN, dboard_iface::UNIT_RX, 10, 0x3F<<10, 6, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0}
};

static const ubx_gpio_field_info_t ubx_v1_gpio_info[] = {
Expand All @@ -170,12 +170,12 @@ static const ubx_gpio_field_info_t ubx_v1_gpio_info[] = {
{RX_EN_N, dboard_iface::UNIT_TX, 6, 0x1<<6, 1, ubx_gpio_field_info_t::INPUT, true, 1, 1, 0, 0},
{TXLO1_SYNC, dboard_iface::UNIT_TX, 7, 0x1<<7, 1, ubx_gpio_field_info_t::INPUT, true, 0, 0, 0, 0},
{TXLO2_SYNC, dboard_iface::UNIT_TX, 9, 0x1<<9, 1, ubx_gpio_field_info_t::INPUT, true, 0, 0, 0, 0},
{TX_GAIN, dboard_iface::UNIT_TX, 10, 0x3F<<10, 10, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0},
{TX_GAIN, dboard_iface::UNIT_TX, 10, 0x3F<<10, 6, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0},
{RX_LO_LOCKED, dboard_iface::UNIT_RX, 0, 0x1, 1, ubx_gpio_field_info_t::OUTPUT, false, 0, 0, 0, 0},
{TX_LO_LOCKED, dboard_iface::UNIT_RX, 1, 0x1<<1, 1, ubx_gpio_field_info_t::OUTPUT, false, 0, 0, 0, 0},
{RXLO1_SYNC, dboard_iface::UNIT_RX, 5, 0x1<<5, 1, ubx_gpio_field_info_t::INPUT, true, 0, 0, 0, 0},
{RXLO2_SYNC, dboard_iface::UNIT_RX, 7, 0x1<<7, 1, ubx_gpio_field_info_t::INPUT, true, 0, 0, 0, 0},
{RX_GAIN, dboard_iface::UNIT_RX, 10, 0x3F<<10, 10, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0}
{RX_GAIN, dboard_iface::UNIT_RX, 10, 0x3F<<10, 6, ubx_gpio_field_info_t::INPUT, false, 0, 0, 0, 0}
};
// clang-format on

Expand Down Expand Up @@ -652,10 +652,10 @@ class ubx_xcvr : public xcvr_dboard_base
void set_gpio_field(ubx_gpio_field_id_t id, uint32_t value)
{
// Look up field info
std::map<ubx_gpio_field_id_t, ubx_gpio_field_info_t>::iterator entry =
_gpio_map.find(id);
if (entry == _gpio_map.end())
auto entry = _gpio_map.find(id);
if (entry == _gpio_map.end()) {
return;
}
ubx_gpio_field_info_t field_info = entry->second;
if (field_info.direction == ubx_gpio_field_info_t::OUTPUT)
return;
Expand All @@ -680,10 +680,10 @@ class ubx_xcvr : public xcvr_dboard_base
uint32_t get_gpio_field(ubx_gpio_field_id_t id)
{
// Look up field info
std::map<ubx_gpio_field_id_t, ubx_gpio_field_info_t>::iterator entry =
_gpio_map.find(id);
if (entry == _gpio_map.end())
auto entry = _gpio_map.find(id);
if (entry == _gpio_map.end()) {
return 0;
}
ubx_gpio_field_info_t field_info = entry->second;
if (field_info.direction == ubx_gpio_field_info_t::INPUT) {
ubx_gpio_reg_t* reg = (field_info.unit == dboard_iface::UNIT_TX
Expand Down Expand Up @@ -848,29 +848,27 @@ class ubx_xcvr : public xcvr_dboard_base
double set_tx_gain(double gain)
{
std::lock_guard<std::mutex> lock(_mutex);
gain = ubx_tx_gain_range.clip(gain);
int attn_code = int(std::floor(gain * 2));
_ubx_tx_atten_val = ((attn_code & 0x3F) << 10);
gain = ubx_tx_gain_range.clip(gain);
const int attn_code = int(std::floor(gain * 2));
set_gpio_field(TX_GAIN, attn_code);
write_gpio();
UHD_LOGGER_TRACE("UBX")
<< boost::format("UBX TX Gain: %f dB, Code: %d, IO Bits 0x%04x") % gain
% attn_code % _ubx_tx_atten_val;
UHD_LOG_TRACE("UBX",
boost::format("UBX TX Gain: %f dB, Code: %d, IO Bits 0x%04x") % gain
% attn_code % (attn_code << 10));
_tx_gain = gain;
return gain;
}

double set_rx_gain(double gain)
{
std::lock_guard<std::mutex> lock(_mutex);
gain = ubx_rx_gain_range.clip(gain);
int attn_code = int(std::floor(gain * 2));
_ubx_rx_atten_val = ((attn_code & 0x3F) << 10);
gain = ubx_rx_gain_range.clip(gain);
const int attn_code = int(std::floor(gain * 2));
set_gpio_field(RX_GAIN, attn_code);
write_gpio();
UHD_LOGGER_TRACE("UBX")
<< boost::format("UBX RX Gain: %f dB, Code: %d, IO Bits 0x%04x") % gain
% attn_code % _ubx_rx_atten_val;
UHD_LOG_TRACE("UBX",
boost::format("UBX RX Gain: %f dB, Code: %d, IO Bits 0x%04x") % gain
% attn_code % (attn_code << 10));
_rx_gain = gain;
return gain;
}
Expand Down Expand Up @@ -1446,8 +1444,6 @@ class ubx_xcvr : public xcvr_dboard_base
bool _rxlo_locked;
bool _txlo_locked;
std::string _rx_ant;
int _ubx_tx_atten_val;
int _ubx_rx_atten_val;
power_mode_t _power_mode;
xcvr_mode_t _xcvr_mode;
size_t _rev;
Expand Down

0 comments on commit 20e987d

Please sign in to comment.