diff options
author | Joachim Steiger <jsteiger@sysmocom.de> | 2019-04-16 17:10:13 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2019-04-17 18:24:11 +0000 |
commit | 2875290d9556291182fb33d248ce1324057adf81 (patch) | |
tree | aab3b0140a131f1cc6ebbe17529b1f95427c40ce | |
parent | 4ce4555d0e28d461bc5b1f21b62e78d07ab9a2ac (diff) |
lms: add device type detection and device specific gains
add device dependant max gain setup - limesdr mini and limenet micro need slightly reduced maximum gains to get a PASS on phase error measurements
rework clock reference setup - external clock needs to be selected before calling LMS_Init(), internal can only be set after.
remove now unused compat_LMS_VCTCXO* functions - we do not set the VCTXCO directly anymore
Change-Id: I3cf905b0a84bc1ec200891762a6646141ee37181
-rw-r--r-- | Transceiver52M/device/lms/LMSDevice.cpp | 83 | ||||
-rw-r--r-- | Transceiver52M/device/lms/LMSDevice.h | 1 | ||||
-rw-r--r-- | configure.ac | 14 |
3 files changed, 40 insertions, 58 deletions
diff --git a/Transceiver52M/device/lms/LMSDevice.cpp b/Transceiver52M/device/lms/LMSDevice.cpp index 083b88e..34ad6e8 100644 --- a/Transceiver52M/device/lms/LMSDevice.cpp +++ b/Transceiver52M/device/lms/LMSDevice.cpp @@ -41,24 +41,6 @@ constexpr double LMSDevice::masterClockRate; #define LMS_MIN_BW_SUPPORTED 2.5e6 /* 2.5mHz, minimum supported by LMS */ #define LMS_CALIBRATE_BW_HZ OSMO_MAX(GSM_CARRIER_BW, LMS_MIN_BW_SUPPORTED) -static int compat_LMS_VCTCXORead(lms_device_t *dev, uint16_t *val, bool memory) -{ -#if HAVE_LMS_VCTCXO_EEPROM_SAVING - return LMS_VCTCXORead(dev, val, memory); -#else - return LMS_VCTCXORead(dev, val); -#endif -} - -static int compat_LMS_VCTCXOWrite(lms_device_t *dev, uint16_t val, bool memory) -{ -#if HAVE_LMS_VCTCXO_EEPROM_SAVING - return LMS_VCTCXOWrite(dev, val, memory); -#else - return LMS_VCTCXOWrite(dev, val); -#endif -} - LMSDevice::LMSDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t chans, double lo_offset, const std::vector<std::string>& tx_paths, const std::vector<std::string>& rx_paths): @@ -151,11 +133,10 @@ int info_list_find(lms_info_str_t* info_list, unsigned int count, const std::str int LMSDevice::open(const std::string &args, int ref, bool swap_channels) { - //lms_info_str_t dev_str; lms_info_str_t* info_list; + const lms_dev_info_t* device_info; lms_range_t range_sr; float_type sr_host, sr_rf; - uint16_t dac_val; unsigned int i, n; int rc, dev_id; @@ -194,12 +175,45 @@ int LMSDevice::open(const std::string &args, int ref, bool swap_channels) delete [] info_list; + device_info = LMS_GetDeviceInfo(m_lms_dev); + + if ((ref != REF_EXTERNAL) && (ref != REF_INTERNAL)){ + LOGC(DDEV, ERROR) << "Invalid reference type"; + goto out_close; + } + + /* if reference clock is external setup must happen _before_ calling LMS_Init */ + /* FIXME make external reference frequency configurable */ + if (ref == REF_EXTERNAL) { + LOGC(DDEV, INFO) << "Setting External clock reference to 10MHz"; + /* Assume an external 10 MHz reference clock */ + if (LMS_SetClockFreq(m_lms_dev, LMS_CLOCK_EXTREF, 10000000.0) < 0) + goto out_close; + } + LOGC(DDEV, INFO) << "Init LMS device"; if (LMS_Init(m_lms_dev) != 0) { LOGC(DDEV, ERROR) << "LMS_Init() failed"; goto out_close; } + /* LimeSDR-Mini does not have switches but needs soldering to select external/internal clock */ + /* LimeNET-Micro also does not like selecting internal clock*/ + /* also set device specific maximum tx levels selected by phasenoise measurements*/ + if (strncmp(device_info->deviceName,"LimeSDR-USB",11) == 0){ + /* if reference clock is internal setup must happen _after_ calling LMS_Init */ + /* according to lms using LMS_CLOCK_EXTREF with a frequency <= 0 is the correct way to set clock to internal reference*/ + if (ref == REF_INTERNAL) { + LOGC(DDEV, INFO) << "Setting Internal clock reference"; + if (LMS_SetClockFreq(m_lms_dev, LMS_CLOCK_EXTREF, -1) < 0) + goto out_close; + } + maxTxGainClamp = 73.0; + } else if (strncmp(device_info->deviceName,"LimeSDR-Mini",12) == 0) + maxTxGainClamp = 66.0; + else + maxTxGainClamp = 71.0; /* "LimeNET-Micro", etc FIXME pciE based LMS boards?*/ + /* enable all used channels */ for (i=0; i<chans; i++) { if (LMS_EnableChannel(m_lms_dev, LMS_CH_RX, i, true) < 0) @@ -223,27 +237,6 @@ int LMSDevice::open(const std::string &args, int ref, bool swap_channels) /* FIXME: make this device/model dependent, like UHDDevice:dev_param_map! */ ts_offset = static_cast<TIMESTAMP>(8.9e-5 * GSMRATE * tx_sps); /* time * sample_rate */ - switch (ref) { - case REF_INTERNAL: - LOGC(DDEV, INFO) << "Setting Internal clock reference"; - /* Ugly API: Selecting clock source implicit by writing to VCTCXO DAC ?!? */ - if (compat_LMS_VCTCXORead(m_lms_dev, &dac_val, false) < 0) - goto out_close; - LOGC(DDEV, INFO) << "Setting VCTCXO to " << dac_val; - if (compat_LMS_VCTCXOWrite(m_lms_dev, dac_val, false) < 0) - goto out_close; - break; - case REF_EXTERNAL: - LOGC(DDEV, INFO) << "Setting External clock reference to " << 10000000.0; - /* Assume an external 10 MHz reference clock */ - if (LMS_SetClockFreq(m_lms_dev, LMS_CLOCK_EXTREF, 10000000.0) < 0) - goto out_close; - break; - default: - LOGC(DDEV, ALERT) << "Invalid reference type"; - goto out_close; - } - if (!set_antennas()) { LOGC(DDEV, ALERT) << "LMS antenna setting failed"; return -1; @@ -275,8 +268,10 @@ bool LMSDevice::start() /* configure the channels/streams */ for (i=0; i<chans; i++) { - // Set gains to midpoint - setTxGain((minTxGain() + maxTxGain()) / 2, i); + /* Set gains for calibration/filter setup */ + /* TX gain to maximum */ + setTxGain(maxTxGain(), i); + /* RX gain to midpoint */ setRxGain((minRxGain() + maxRxGain()) / 2, i); /* set up Rx and Tx filters */ @@ -385,7 +380,7 @@ bool LMSDevice::do_filters(size_t chan) double LMSDevice::maxTxGain() { - return 73.0; + return maxTxGainClamp; } double LMSDevice::minTxGain() diff --git a/Transceiver52M/device/lms/LMSDevice.h b/Transceiver52M/device/lms/LMSDevice.h index 67f4691..d1cb12a 100644 --- a/Transceiver52M/device/lms/LMSDevice.h +++ b/Transceiver52M/device/lms/LMSDevice.h @@ -64,6 +64,7 @@ private: TIMESTAMP ts_initial, ts_offset; double rxGain; + double maxTxGainClamp; bool do_calib(size_t chan); bool do_filters(size_t chan); diff --git a/configure.ac b/configure.ac index 2ce4462..bd421aa 100644 --- a/configure.ac +++ b/configure.ac @@ -162,20 +162,6 @@ AS_IF([test "x$with_usrp1" = "xyes"], [ AS_IF([test "x$with_lms" = "xyes"], [ PKG_CHECK_MODULES(LMS, LimeSuite) - - # LimeSuite dc124e4e2ed9b549b142410af172f0592f9f0c23 > 18.10 broke API compatibility: - _cflags_save=$CFLAGS - CFLAGS="$CFLAGS $LMS_CFLAGS" - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [[#include <lime/LimeSuite.h>]], - [[LMS_VCTCXOWrite(NULL, 0, false); LMS_VCTCXORead(NULL, 0, false);]] - )], - [AC_DEFINE([HAVE_LMS_VCTCXO_EEPROM_SAVING], [1], - [LMS_VCTCXO* requires memory parameter])], - [AC_DEFINE([HAVE_LMS_VCTCXO_EEPROM_SAVING], [0], - [LMS_VCTCXO* has no memory parameter])]) - CFLAGS=$_cflags_save ]) AS_IF([test "x$with_uhd" != "xno"],[ |