roh has uploaded this change for review. ( https://gerrit.osmocom.org/13663


Change subject: add device type detection
......................................................................

add device type detection

device dependant max gain setup
rework clock reference setup
remove now unused compat_LMS_VCTCXO* functions

Change-Id: I3cf905b0a84bc1ec200891762a6646141ee37181
---
M Transceiver52M/device/lms/LMSDevice.cpp
M Transceiver52M/device/lms/LMSDevice.h
2 files changed, 50 insertions(+), 45 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/63/13663/1

diff --git a/Transceiver52M/device/lms/LMSDevice.cpp 
b/Transceiver52M/device/lms/LMSDevice.cpp
index ab4e868..06c506e 100644
--- a/Transceiver52M/device/lms/LMSDevice.cpp
+++ b/Transceiver52M/device/lms/LMSDevice.cpp
@@ -41,24 +41,6 @@
 #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 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 @@

        delete [] info_list;

+       device_info = LMS_GetDeviceInfo(m_lms_dev);
+
+       if ((ref != REF_EXTERNAL) && (ref != REF_INTERNAL)){
+               LOGC(DDEV, ALERT) << "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 */
+               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)
@@ -208,6 +222,7 @@
                        goto out_close;
        }

+       /* set samplerate */
        if (LMS_GetSampleRateRange(m_lms_dev, LMS_CH_RX, &range_sr))
                goto out_close;
        print_range("Sample Rate", &range_sr);
@@ -223,30 +238,10 @@
        /* 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;
-       }
-
+       /* configure antennas */
        if (!set_antennas()) {
                LOGC(DDEV, ALERT) << "LMS antenna setting failed";
-               return -1;
+               goto out_close;
        }

        samplesRead = 0;
@@ -275,8 +270,10 @@

        /* 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 */
@@ -286,6 +283,7 @@
                if (!do_calib(i))
                        return false;

+               /* configure Streams */
                m_lms_stream_rx[i] = {};
                m_lms_stream_rx[i].isTx = false;
                m_lms_stream_rx[i].channel = i;
@@ -385,7 +383,7 @@

 double LMSDevice::maxTxGain()
 {
-       return 73.0;
+       return maxTxGainClamp;
 }

 double LMSDevice::minTxGain()
@@ -415,6 +413,9 @@
        if (LMS_SetGaindB(m_lms_dev, LMS_CH_TX, chan, dB) < 0)
                LOGC(DDEV, ERR) << "chan " << chan <<": Error setting TX gain 
to " << dB << " dB";

+//FIXME crashes when called while stream is running
+//>----do_calib(chan);
+
        return dB;
 }

@@ -430,6 +431,9 @@
        if (LMS_SetGaindB(m_lms_dev, LMS_CH_RX, chan, dB) < 0)
                LOGC(DDEV, ERR) << "chan "<< chan << ": Error setting RX gain 
to " << dB << " dB";

+//FIXME crashes when called while stream is running
+//>----do_calib(chan);
+
        return dB;
 }

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 @@
        TIMESTAMP ts_initial, ts_offset;

        double rxGain;
+       double maxTxGainClamp;

        bool do_calib(size_t chan);
        bool do_filters(size_t chan);

--
To view, visit https://gerrit.osmocom.org/13663
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3cf905b0a84bc1ec200891762a6646141ee37181
Gerrit-Change-Number: 13663
Gerrit-PatchSet: 1
Gerrit-Owner: roh <[email protected]>

Reply via email to