This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
pespin gerrit-no-reply at lists.osmocom.orgpespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/16876 ) Change subject: lms: Store device type specific parameters in one place ...................................................................... lms: Store device type specific parameters in one place Add an enum containing each supported device type (LimeSDR-USB, LimeSDR-Mini and LimeNet-Micro) plus "unknown", to leave some room for yet-to-come devices to run with some generic parameters without rebuilding osmo-trx. Each device type is assigned a dev_desc structure, and all of them are put in HashMap, similar to what's already done in UHDDevice.cpp. Device type is infered from string provided by LMS_GetDeviceInfo(), as it was already done before in several places. From now on, we only need to parse the string once since we store the device type after first during open time. Later on, more fields will be moved to device-type specific structure, such as Tx timing offset, clock rate, etc. Change-Id: I7658615787c5bc41c365bab9c11733b701ac2ae5 --- M Transceiver52M/device/lms/LMSDevice.cpp M Transceiver52M/device/lms/LMSDevice.h 2 files changed, 89 insertions(+), 22 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/76/16876/1 diff --git a/Transceiver52M/device/lms/LMSDevice.cpp b/Transceiver52M/device/lms/LMSDevice.cpp index a533e7e..2e164ed 100644 --- a/Transceiver52M/device/lms/LMSDevice.cpp +++ b/Transceiver52M/device/lms/LMSDevice.cpp @@ -20,6 +20,9 @@ #include <stdint.h> #include <string.h> #include <stdlib.h> + +#include <map> + #include "Logger.h" #include "Threads.h" #include "LMSDevice.h" @@ -44,11 +47,62 @@ #define LMS_CALIBRATE_BW_HZ OSMO_MAX(GSM_CARRIER_BW, LMS_MIN_BW_SUPPORTED) #define SAMPLE_BUF_SZ (1 << 20) /* Size of Rx timestamp based Ring buffer, in bytes */ + +/* Device Name Prefixes as presented by LimeSuite API LMS_GetDeviceInfo(): */ +#define LMS_DEV_SDR_USB_PREFIX_NAME "LimeSDR-USB" +#define LMS_DEV_SDR_MINI_PREFIX_NAME "LimeSDR-Mini" +#define LMS_DEV_NET_MICRO_PREFIX_NAME "LimeNET-Micro" + +/* Device parameter descriptor */ +struct dev_desc { + /* Does LimeSuite allow switching the clock source for this device? + * LimeSDR-Mini does not have switches but needs soldering to select + * external/internal clock. Any call to LMS_SetClockFreq() will fail. + */ + bool clock_src_switchable; + /* Does LimeSuite allow using REF_INTERNAL for this device? + * LimeNET-Micro does not like selecting internal clock + */ + bool clock_src_int_usable; + /* Device specific maximum tx levels selected by phasenoise measurements, in dB */ + double max_tx_gain; + /* Device Name Prefix as presented by LimeSuite API LMS_GetDeviceInfo() */ + std::string name_prefix; +}; + +static const std::map<enum lms_dev_type, struct dev_desc> dev_param_map { + { LMS_DEV_SDR_USB, { true, true, 73.0, LMS_DEV_SDR_USB_PREFIX_NAME } }, + { LMS_DEV_SDR_MINI, { false, true, 66.0, LMS_DEV_SDR_MINI_PREFIX_NAME } }, + { LMS_DEV_NET_MICRO, { true, false, 71.0, LMS_DEV_NET_MICRO_PREFIX_NAME } }, + { LMS_DEV_UNKNOWN, { true, true, 73.0, "UNKNOWN" } }, +}; + +static enum lms_dev_type parse_dev_type(lms_device_t *m_lms_dev) +{ + std::map<enum lms_dev_type, struct dev_desc>::const_iterator it = dev_param_map.begin(); + + const lms_dev_info_t* device_info = LMS_GetDeviceInfo(m_lms_dev); + + // Iterate over the map using Iterator till end. + while (it != dev_param_map.end()) + { + enum lms_dev_type dev_type = it->first; + struct dev_desc desc = it->second; + + if (strncmp(device_info->deviceName, desc.name_prefix.c_str(), desc.name_prefix.length()) == 0) { + LOGC(DDEV, INFO) << "Device identified as " << desc.name_prefix; + return dev_type; + } + it++; + } + return LMS_DEV_UNKNOWN; +} + LMSDevice::LMSDevice(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t chan_num, double lo_offset, const std::vector<std::string>& tx_paths, const std::vector<std::string>& rx_paths): RadioDevice(tx_sps, rx_sps, iface, chan_num, lo_offset, tx_paths, rx_paths), - m_lms_dev(NULL), started(false) + m_lms_dev(NULL), started(false), dev_type(LMS_DEV_UNKNOWN) { LOGC(DDEV, INFO) << "creating LMS device..."; @@ -138,11 +192,11 @@ int LMSDevice::open(const std::string &args, int ref, bool swap_channels) { lms_info_str_t* info_list; - const lms_dev_info_t* device_info; lms_range_t range_sr; float_type sr_host, sr_rf; unsigned int i, n; int rc, dev_id; + struct dev_desc dev_desc; LOGC(DDEV, INFO) << "Opening LMS device.."; @@ -179,20 +233,24 @@ delete [] info_list; - device_info = LMS_GetDeviceInfo(m_lms_dev); + dev_type = parse_dev_type(m_lms_dev); + dev_desc = dev_param_map.at(dev_type); 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 */ + /* if reference clock is external, setup must happen _before_ calling LMS_Init */ /* FIXME make external reference frequency configurable */ - if (ref == REF_EXTERNAL) { + if (dev_desc.clock_src_switchable && 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; + } else { + LOGC(DDEV, INFO) << "Device type " << dev_desc.name_prefix + << " doesn't support switching clock source through SW"; } LOGC(DDEV, INFO) << "Init LMS device"; @@ -201,22 +259,23 @@ 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; + /* if reference clock is internal, setup must happen _after_ calling LMS_Init */ + if (dev_desc.clock_src_switchable && ref == REF_INTERNAL) { + LOGC(DDEV, INFO) << "Setting Internal clock reference"; + if (!dev_desc.clock_src_int_usable) { + LOGC(DDEV, ERROR) << "Device type " << dev_desc.name_prefix + << " doesn't support internal reference clock"; + 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?*/ + /* According to lms using LMS_CLOCK_EXTREF with a + frequency <= 0 is the correct way to set clock to + internal reference*/ + if (LMS_SetClockFreq(m_lms_dev, LMS_CLOCK_EXTREF, -1) < 0) + goto out_close; + } else { + LOGC(DDEV, INFO) << "Device type " << dev_desc.name_prefix + << " doesn't support switching clock source through SW"; + } /* enable all used channels */ for (i=0; i<chans; i++) { @@ -383,7 +442,7 @@ double LMSDevice::maxTxGain() { - return maxTxGainClamp; + return dev_param_map.at(dev_type).max_tx_gain; } double LMSDevice::minTxGain() diff --git a/Transceiver52M/device/lms/LMSDevice.h b/Transceiver52M/device/lms/LMSDevice.h index cdba72c..2489539 100644 --- a/Transceiver52M/device/lms/LMSDevice.h +++ b/Transceiver52M/device/lms/LMSDevice.h @@ -41,6 +41,13 @@ * A^2 = 1 */ #define LIMESDR_TX_AMPL 0.707 +enum lms_dev_type { + LMS_DEV_SDR_USB, /* LimeSDR-USB */ + LMS_DEV_SDR_MINI, /* LimeSDR-Mini */ + LMS_DEV_NET_MICRO, /* LimeNet-micro */ + LMS_DEV_UNKNOWN, +}; + /** A class to handle a LimeSuite supported device */ class LMSDevice:public RadioDevice { @@ -59,7 +66,8 @@ TIMESTAMP ts_initial, ts_offset; std::vector<double> tx_gains, rx_gains; - double maxTxGainClamp; + + enum lms_dev_type dev_type; bool do_calib(size_t chan); bool do_filters(size_t chan); -- To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/16876 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: I7658615787c5bc41c365bab9c11733b701ac2ae5 Gerrit-Change-Number: 16876 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200114/7af0c8f3/attachment.htm>