Change in osmo-trx[master]: lms: Several improvements and compilation/runtime fixes

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Jun 13 21:45:33 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/9600 )

Change subject: lms: Several improvements and compilation/runtime fixes
......................................................................

lms: Several improvements and compilation/runtime fixes

Continuation of initial work done on LimeSuite support from Harald.

Change-Id: Ib2fca81b76d027b08e2891056fa076d071597783
---
M CommonLibs/Logger.h
M CommonLibs/debug.c
M CommonLibs/debug.h
M Transceiver52M/device/lms/LMSDevice.cpp
M Transceiver52M/device/lms/LMSDevice.h
M Transceiver52M/device/radioDevice.h
6 files changed, 274 insertions(+), 127 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index 5b0b05c..e18ecfb 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -53,6 +53,9 @@
 #define LOGC(category, level) \
 	Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "
 
+#define LOGLV(category, level) \
+	Log(category, level, __BASE_FILE__, __LINE__).get() <<  "[tid=" << pthread_self() << "] "
+
 /**
 	A C++ stream-based thread-safe logger.
 	This object is NOT the global logger;
diff --git a/CommonLibs/debug.c b/CommonLibs/debug.c
index e4db2f3..01854c0 100644
--- a/CommonLibs/debug.c
+++ b/CommonLibs/debug.c
@@ -10,6 +10,12 @@
 		.color = NULL,
 		.enabled = 1, .loglevel = LOGL_NOTICE,
 	},
+	[DLMS] = {
+		.name = "DLMS",
+		.description = "LimeSuite category",
+		.color = NULL,
+		.enabled = 1, .loglevel = LOGL_NOTICE,
+	},
 };
 
 const struct log_info log_info = {
diff --git a/CommonLibs/debug.h b/CommonLibs/debug.h
index 7038f4c..06ad74e 100644
--- a/CommonLibs/debug.h
+++ b/CommonLibs/debug.h
@@ -5,4 +5,5 @@
 /* Debug Areas of the code */
 enum {
 	DMAIN,
+	DLMS,
 };
diff --git a/Transceiver52M/device/lms/LMSDevice.cpp b/Transceiver52M/device/lms/LMSDevice.cpp
index ed51cdb..603b23d 100644
--- a/Transceiver52M/device/lms/LMSDevice.cpp
+++ b/Transceiver52M/device/lms/LMSDevice.cpp
@@ -24,26 +24,40 @@
 
 #include <lime/LimeSuite.h>
 
+#include <osmocom/core/utils.h>
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 using namespace std;
 
-const double LMSDevice::masterClockRate = 52.0e6;
+constexpr double LMSDevice::masterClockRate;
 
-LMSDevice::LMSDevice(size_t sps)
+#define MAX_ANTENNA_LIST_SIZE 10
+#define LMS_SAMPLE_RATE GSMRATE*32
+#define GSM_CARRIER_BW 270000.0 /* 270kHz */
+#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)
+
+LMSDevice::LMSDevice(size_t sps, size_t chans):
+	m_lms_dev(NULL), sps(sps), chans(chans)
 {
 	LOG(INFO) << "creating LMS device...";
 
-	m_lms_device = NULL;
-	this->sps = sps;
+	m_lms_stream_rx.resize(chans);
+	m_lms_stream_tx.resize(chans);
+
+	m_last_rx_underruns.resize(chans, 0);
+	m_last_rx_overruns.resize(chans, 0);
+	m_last_tx_underruns.resize(chans, 0);
+	m_last_tx_overruns.resize(chans, 0);
 }
 
 static void lms_log_callback(int lvl, const char *msg)
 {
 	/* map lime specific log levels */
-	static const lvl_map[4] = {
+	static const int lvl_map[5] = {
 		[0] = LOGL_FATAL,
 		[1] = LOGL_ERROR,
 		[2] = LOGL_NOTICE,
@@ -51,40 +65,71 @@
 		[4] = LOGL_DEBUG,
 	};
 	/* protect against future higher log level values (lower importance) */
-	if (lvl >= ARRAY_SIZE(lvl_map))
+	if ((unsigned int) lvl >= ARRAY_SIZE(lvl_map))
 		lvl = ARRAY_SIZE(lvl_map)-1;
 
-	LOG(lvl) << msg;
+	LOGLV(DLMS, lvl) << msg;
 }
 
-int LMSDevice::open(const std::string &, int, bool)
+static void thread_enable_cancel(bool cancel)
 {
-	lms_info_str dev_str;
-	uint16_t dac_val;
+	cancel ? pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) :
+		 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+}
 
-	LOG(INFO) << "opening LMS device..";
+int LMSDevice::open(const std::string &args, int ref, bool swap_channels)
+{
+	//lms_info_str_t dev_str;
+	lms_info_str_t* info_list;
+	uint16_t dac_val;
+	unsigned int i, n;
+	int rc;
+
+	LOG(INFO) << "Opening LMS device..";
 
 	LMS_RegisterLogHandler(&lms_log_callback);
 
-	rc = LMS_Open(&m_lms_dev, NULL, NULL);
-	if (rc != 0)
-		return -1;
+        if ((n = LMS_GetDeviceList(NULL)) < 0)
+            LOG(ERROR) << "LMS_GetDeviceList(NULL) failed";
+        LOG(DEBUG) << "Devices found: " << n;
+        if (n < 1)
+            return -1;
 
-	if (LMS_SetSampleRate(m_lms_dev, GSMRATE, sps) < 0)
+        info_list = new lms_info_str_t[n];
+
+        if (LMS_GetDeviceList(info_list) < 0)                //Populate device list
+            LOG(ERROR) << "LMS_GetDeviceList(info_list) failed";
+
+        for (i = 0; i < n; i++)                     //print device list
+           LOG(DEBUG) << "Device [" << i << "]: " << info_list[i];
+
+	rc = LMS_Open(&m_lms_dev, info_list[0], NULL);
+	if (rc != 0) {
+		LOG(ERROR) << "LMS_GetDeviceList() failed)";
+		delete [] info_list;
+		return -1;
+	}
+
+	delete [] info_list;
+
+	LOG(DEBUG) << "Setting sample rate to " << GSMRATE*sps << " " << sps;
+	if (LMS_SetSampleRate(m_lms_dev, GSMRATE*sps, 32) < 0)
 		goto out_close;
 	/* FIXME: make this device/model dependent, like UHDDevice:dev_param_map! */
-	ts_offset = static_caset<TIMESTAMP>(8.9e-5 * GSMRATE);
+	ts_offset = static_cast<TIMESTAMP>(8.9e-5 * GSMRATE);
 
 	switch (ref) {
 	case REF_INTERNAL:
+		LOG(DEBUG) << "Setting Internal clock reference";
 		/* Ugly API: Selecting clock source implicit by writing to VCTCXO DAC ?!? */
 		if (LMS_VCTCXORead(m_lms_dev, &dac_val) < 0)
 			goto out_close;
-
+		LOG(DEBUG) << "Setting VCTCXO to " << dac_val;
 		if (LMS_VCTCXOWrite(m_lms_dev, dac_val) < 0)
 			goto out_close;
 		break;
-	case REF_EXTENAL:
+	case REF_EXTERNAL:
+		LOG(DEBUG) << "Setting Internal 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;
@@ -94,14 +139,18 @@
 		goto out_close;
 	}
 
+	LOG(INFO) << "Init LMS device";
 	if (LMS_Init(m_lms_dev) < 0)
 		goto out_close;
 
 	/* Perform Rx and Tx calibration */
-	if (LMS_Calibrate(m_lms_dev, LMS_CH_RX, chan, 270000.0, 0) < 0)
-		goto out_close;
-	if (LMS_Calibrate(m_lms_dev, LMS_CH_TX, chan, 270000.0, 0) < 0)
-		goto out_close;
+	for (i=0; i<chans; i++) {
+		LOG(INFO) << "Calibrating chan " << i;
+		if (LMS_Calibrate(m_lms_dev, LMS_CH_RX, i, LMS_CALIBRATE_BW_HZ, 0) < 0)
+			goto out_close;
+		if (LMS_Calibrate(m_lms_dev, LMS_CH_TX, i, LMS_CALIBRATE_BW_HZ, 0) < 0)
+			goto out_close;
+	}
 
 	samplesRead = 0;
 	samplesWritten = 0;
@@ -119,42 +168,47 @@
 {
 	LOG(INFO) << "starting LMS...";
 
-	if (LMS_EnableChannel(m_lms_dev, LMS_CH_RX, 0, true) < 0)
-		return false;
+	unsigned int i;
 
-	if (LMS_EnableChannel(m_lms_dev, LMS_CH_TX, 0, true) < 0)
-		return false;
+	for (i=0; i<chans; i++) {
+		if (LMS_EnableChannel(m_lms_dev, LMS_CH_RX, i, true) < 0)
+			return false;
 
-	// Set gains to midpoint
-	setTxGain((minTxGain() + maxTxGain()) / 2);
-	setRxGain((minRxGain() + maxRxGain()) / 2);
+		if (LMS_EnableChannel(m_lms_dev, LMS_CH_TX, i, true) < 0)
+			return false;
 
-	m_lms_stream_rx = {
-		.isTx = false,
-		.channel = 0,
-		.fifoSize = 1024 * 1024,
-		.throughputVsLatency = 0.3,
-		.dataFmt = LMS_FMT_I16,
-	}
-	m_lms_stream_tx = {
-		.ixTx = true,
-		.channel = 0,
-		.fifoSize = 1024 * 1024,
-		.throughputVsLatency = 0.3,
-		.dataFmt = LMS_FMT_I16,
+		// Set gains to midpoint
+		setTxGain((minTxGain() + maxTxGain()) / 2, i);
+		setRxGain((minRxGain() + maxRxGain()) / 2, i);
+
+		m_lms_stream_rx[i] = {};
+		m_lms_stream_rx[i].isTx = false;
+		m_lms_stream_rx[i].channel = i;
+		m_lms_stream_rx[i].fifoSize = 1024 * 1024;
+		m_lms_stream_rx[i].throughputVsLatency = 0.3;
+		m_lms_stream_rx[i].dataFmt = lms_stream_t::LMS_FMT_I16;
+
+		m_lms_stream_tx[i] = {};
+		m_lms_stream_tx[i].isTx = true;
+		m_lms_stream_tx[i].channel = i;
+		m_lms_stream_tx[i].fifoSize = 1024 * 1024;
+		m_lms_stream_tx[i].throughputVsLatency = 0.3;
+		m_lms_stream_tx[i].dataFmt = lms_stream_t::LMS_FMT_I16;
+
+		if (LMS_SetupStream(m_lms_dev, &m_lms_stream_rx[i]) < 0)
+			return false;
+
+		if (LMS_SetupStream(m_lms_dev, &m_lms_stream_tx[i]) < 0)
+			return false;
+
+		if (LMS_StartStream(&m_lms_stream_rx[i]) < 0)
+			return false;
+
+		if (LMS_StartStream(&m_lms_stream_tx[i]) < 0)
+			return false;
 	}
 
-	if (LMS_SetupStream(m_lms_dev, &m_lms_stream_rx) < 0)
-		return false;
-
-	if (LMS_SetupStream(m_lms_dev, &m_lms_stream_tx) < 0)
-		return false;
-
-	if (LMS_StartStream(&m_lms_stream_rx) < 0)
-		return false;
-
-	if (LMS_StartStream(&m_lms_stream_tx) < 0)
-		return false;
+	flush_recv(10);
 
 	started = true;
 	return true;
@@ -162,14 +216,18 @@
 
 bool LMSDevice::stop()
 {
+	unsigned int i;
+
 	if (!started)
 		return true;
 
-	LMS_StopStream(&m_lms_stream_tx);
-	LMS_StopStream(&m_lms_stream_rx);
+	for (i=0; i<chans; i++) {
+		LMS_StopStream(&m_lms_stream_tx[i]);
+		LMS_StopStream(&m_lms_stream_rx[i]);
 
-	LMS_EnableChannel(m_lms_dev, LMS_CH_RX, 0, false);
-	LMS_EnableChannel(m_lms_dev, LMS_CH_TX, 0, false);
+		LMS_EnableChannel(m_lms_dev, LMS_CH_RX, i, false);
+		LMS_EnableChannel(m_lms_dev, LMS_CH_TX, i, false);
+	}
 
 	return true;
 }
@@ -236,18 +294,50 @@
 	return dB;
 }
 
-int get_ant_idx(const char *name, bool dir_tx)
+int LMSDevice::get_ant_idx(const std::string & name, bool dir_tx, size_t chan)
 {
-	lms_name_t name_list;
+	lms_name_t name_list[MAX_ANTENNA_LIST_SIZE]; /* large enough list for antenna names. */
+	const char* c_name = name.c_str();
 	int num_names;
-	num_names = LMS_GetAntennaList(m_lms_dev, dir_tx, &name_list);
+	int i;
+
+	num_names = LMS_GetAntennaList(m_lms_dev, dir_tx, chan, name_list);
 	for (i = 0; i < num_names; i++) {
-		if (!strcmp(name, name_list[i]))
+		if (!strcmp(c_name, name_list[i]))
 			return i;
 	}
 	return -1;
 }
 
+bool LMSDevice::flush_recv(size_t num_pkts)
+{
+	#define CHUNK 625
+	int len = CHUNK * sps;
+	short *buffer = new short[len * 2];
+	int rc;
+	lms_stream_meta_t rx_metadata = {};
+	rx_metadata.flushPartialPacket = false;
+	rx_metadata.waitForTimestamp = false;
+
+	ts_initial = 0;
+
+	while (!ts_initial || (num_pkts-- > 0)) {
+		rc = LMS_RecvStream(&m_lms_stream_rx[0], &buffer[0], len, &rx_metadata, 100);
+		LOG(DEBUG) << "Flush: Recv buffer of len " << rc << " at " << std::hex << rx_metadata.timestamp;
+		if (rc != len) {
+			LOG(ALERT) << "LMS: Device receive timed out";
+			delete[] buffer;
+			return false;
+		}
+
+		ts_initial = rx_metadata.timestamp;
+	}
+
+	LOG(INFO) << "Initial timestamp " << ts_initial << std::endl;
+	delete[] buffer;
+	return true;
+}
+
 bool LMSDevice::setRxAntenna(const std::string & ant, size_t chan)
 {
 	int idx;
@@ -257,7 +347,7 @@
 		return false;
 	}
 
-	idx = get_ant_idx(ant, LMS_CH_RX);
+	idx = get_ant_idx(ant, LMS_CH_RX, chan);
 	if (idx < 0) {
 		LOG(ALERT) << "Invalid Rx Antenna";
 		return false;
@@ -272,6 +362,9 @@
 
 std::string LMSDevice::getRxAntenna(size_t chan)
 {
+	lms_name_t name_list[MAX_ANTENNA_LIST_SIZE]; /* large enough list for antenna names. */
+	int idx;
+
 	if (chan >= rx_paths.size()) {
 		LOG(ALERT) << "Requested non-existent channel " << chan;
 		return "";
@@ -283,12 +376,12 @@
 		return "";
 	}
 
-	if (LMS_GetAntennaList(m_lms_dev, LMS_CH_RX, chan, &list) < idx) {
+	if (LMS_GetAntennaList(m_lms_dev, LMS_CH_RX, chan, name_list) < idx) {
 		LOG(ALERT) << "Error getting Rx Antenna List";
 		return "";
 	}
 
-	return list[idx];
+	return name_list[idx];
 }
 
 bool LMSDevice::setTxAntenna(const std::string & ant, size_t chan)
@@ -300,7 +393,7 @@
 		return false;
 	}
 
-	idx = get_ant_idx(ant, LMS_CH_TX);
+	idx = get_ant_idx(ant, LMS_CH_TX, chan);
 	if (idx < 0) {
 		LOG(ALERT) << "Invalid Rx Antenna";
 		return false;
@@ -315,6 +408,7 @@
 
 std::string LMSDevice::getTxAntenna(size_t chan)
 {
+	lms_name_t name_list[MAX_ANTENNA_LIST_SIZE]; /* large enough list for antenna names. */
 	int idx;
 
 	if (chan >= tx_paths.size()) {
@@ -328,49 +422,73 @@
 		return "";
 	}
 
-	if (LMS_GetAntennaList(m_lms_dev, LMS_CH_TX, chan, &list) < idx) {
+	if (LMS_GetAntennaList(m_lms_dev, LMS_CH_TX, chan, name_list) < idx) {
 		LOG(ALERT) << "Error getting Tx Antenna List";
 		return "";
 	}
 
-	return list[idx];
+	return name_list[idx];
+}
+
+bool LMSDevice::requiresRadioAlign()
+{
+	return false;
+}
+
+GSM::Time LMSDevice::minLatency() {
+	/* Empirical data from a handful of
+	relatively recent machines shows that the B100 will underrun when
+	the transmit threshold is reduced to a time of 6 and a half frames,
+	so we set a minimum 7 frame threshold. */
+	return GSM::Time(6,7);
 }
 
 // NOTE: Assumes sequential reads
 int LMSDevice::readSamples(std::vector < short *>&bufs, int len, bool * overrun,
 			   TIMESTAMP timestamp, bool * underrun, unsigned *RSSI)
 {
-	lms_stream_meta_t rx_metadata = {
-		.flushPartialPacket = false,
-		.waitForTimestamp = false,
-	};
-	int rc;
+	int rc = 0;
+	unsigned int i;
+	lms_stream_status_t status;
+	lms_stream_meta_t rx_metadata = {};
+	rx_metadata.flushPartialPacket = false;
+	rx_metadata.waitForTimestamp = false;
+	/* Shift read time with respect to transmit clock */
+	timestamp += ts_offset;
+	rx_metadata.timestamp = 0;
 
-	if (bufs.size != 1) {
+	if (bufs.size() != chans) {
 		LOG(ALERT) << "Invalid channel combination " << bufs.size();
 		return -1;
 	}
 
-	/* Shift read time with respect to transmit clock */
-	timestamp += ts_offset;
-
-	rc = LMS_RecvStream(&m_lms_stream_rx, bufs[0], len, &rx_metadata, 100);
-
 	*overrun = false;
 	*underrun = false;
+	for (i = 0; i<chans; i++) {
+		thread_enable_cancel(false);
+		rc = LMS_RecvStream(&m_lms_stream_rx[i], bufs[i], len, &rx_metadata, 100);
+		LOG(ALERT) << "chan "<< i << " recv buffer of len " << rc << " expect " << std::hex << timestamp << " got " << std::hex << (TIMESTAMP)rx_metadata.timestamp << " (" << std::hex << rx_metadata.timestamp <<") diff=" << rx_metadata.timestamp - timestamp;
+		if (rc != len) {
+			LOG(ALERT) << "LMS: Device receive timed out";
+		}
 
-	if (LMS_GetStreamStatus(&m_lms_stream_rx, &status) == 0) {
-		if (status.underrun > m_last_rx_underruns)
-			*underrun = true;
-		m_last_rx_underruns = status.underrun;
+		if (LMS_GetStreamStatus(&m_lms_stream_rx[i], &status) == 0) {
+			if (status.underrun > m_last_rx_underruns[i])
+				*underrun = true;
+			m_last_rx_underruns[i] = status.underrun;
 
-		if (status.overrun > m_last_rx_overruns)
-			*overrun = true;
-		m_last_rx_overruns = status.overrun;
+			if (status.overrun > m_last_rx_overruns[i])
+				*overrun = true;
+			m_last_rx_overruns[i] = status.overrun;
+		}
+		thread_enable_cancel(true);
 	}
 
 	samplesRead += rc;
 
+	if (((TIMESTAMP) rx_metadata.timestamp) < timestamp)
+		rc = 0;
+
 	return rc;
 }
 
@@ -378,35 +496,40 @@
 			    bool * underrun, unsigned long long timestamp,
 			    bool isControl)
 {
-	lms_stream_status_t status;
-	lms_stream_meta_t tx_metadata = {
-		.flushPartialPacket = false,
-		.waitForTimestamp = true,
-		.timestamp = timestamp,
-	};
 	int rc;
+	unsigned int i;
+	lms_stream_status_t status;
+	lms_stream_meta_t tx_metadata = {};
+	tx_metadata.flushPartialPacket = false;
+	tx_metadata.waitForTimestamp = true;
+	tx_metadata.timestamp = timestamp;
 
 	if (isControl) {
 		LOG(ERR) << "Control packets not supported";
 		return 0;
 	}
 
-	if (bufs.size() != 1) {
+	if (bufs.size() != chans) {
 		LOG(ALERT) << "Invalid channel combination " << bufs.size();
 		return -1;
 	}
 
-	rc = LMS_Send_Stream(&m_lms_stream_tx, bufs[0], len, &tx_metadata, 100);
-	if (rc != len) {
-		LOG(ALERT) << "LMS: Device send timed out ";
-	}
-
 	*underrun = false;
 
-	if (LMS_GetStreamStatus(&m_lms_stream_tx, &status) == 0) {
-		if (status.underrun > m_last_tx_underruns)
-			*underrun = true;
-		m_last_tx_underruns = status.underrun;
+	for (i = 0; i<chans; i++) {
+		LOG(ALERT) << "chan "<< i << " send buffer of len " << len << " timestamp " << std::hex << tx_metadata.timestamp;
+		thread_enable_cancel(false);
+		rc = LMS_SendStream(&m_lms_stream_tx[i], bufs[i], len, &tx_metadata, 100);
+		if (rc != len) {
+			LOG(ALERT) << "LMS: Device send timed out";
+		}
+
+		if (LMS_GetStreamStatus(&m_lms_stream_tx[i], &status) == 0) {
+			if (status.underrun > m_last_tx_underruns[i])
+				*underrun = true;
+			m_last_tx_underruns[i] = status.underrun;
+		}
+		thread_enable_cancel(true);
 	}
 
 	samplesWritten += rc;
@@ -416,17 +539,7 @@
 
 bool LMSDevice::updateAlignment(TIMESTAMP timestamp)
 {
-	short data[] = { 0x00, 0x02, 0x00, 0x00 };
-	uint32_t *wordPtr = (uint32_t *) data;
-	*wordPtr = host_to_usrp_u32(*wordPtr);
-	bool tmpUnderrun;
-
-	std::vector < short *>buf(1, data);
-	if (writeSamples(buf, 1, &tmpUnderrun, timestamp & 0x0ffffffffll, true)) {
-		pingTimestamp = timestamp;
-		return true;
-	}
-	return false;
+	return true;
 }
 
 bool LMSDevice::setTxFreq(double wFreq, size_t chan)
@@ -465,5 +578,5 @@
 			       const std::vector < std::string > &tx_paths,
 			       const std::vector < std::string > &rx_paths)
 {
-	return new LMSDevice(tx_sps);
+	return new LMSDevice(tx_sps, chans);
 }
diff --git a/Transceiver52M/device/lms/LMSDevice.h b/Transceiver52M/device/lms/LMSDevice.h
index 653d159..99eed43 100644
--- a/Transceiver52M/device/lms/LMSDevice.h
+++ b/Transceiver52M/device/lms/LMSDevice.h
@@ -21,22 +21,33 @@
 
 #include "radioDevice.h"
 
-#include <lime/LMSDevice.h>
 #include <sys/time.h>
 #include <math.h>
+#include <limits.h>
 #include <string>
 #include <iostream>
+#include <lime/LimeSuite.h>
+
+#define LIMESDR_TX_AMPL  0.3
 
 /** A class to handle a LimeSuite supported device */
 class LMSDevice:public RadioDevice {
 
 private:
 
-	lms_device_t *m_lms_dev;
-	lms_stream_t m_lms_Stream_rx;
-	lms_stream_t m_lms_Stream_tx;
+	static constexpr double masterClockRate = 52.0e6;
 
-	int sps;
+	lms_device_t *m_lms_dev;
+	std::vector<lms_stream_t> m_lms_stream_rx;
+	std::vector<lms_stream_t> m_lms_stream_tx;
+
+	std::vector<uint32_t> m_last_rx_underruns;
+	std::vector<uint32_t> m_last_rx_overruns;
+	std::vector<uint32_t> m_last_tx_underruns;
+	std::vector<uint32_t> m_last_tx_overruns;
+
+	size_t sps, chans;
+	double actualSampleRate;	///< the actual USRP sampling rate
 
 	unsigned long long samplesRead;	///< number of samples read from LMS
 	unsigned long long samplesWritten;	///< number of samples sent to LMS
@@ -44,15 +55,20 @@
 	bool started;		///< flag indicates LMS has started
 	bool skipRx;		///< set if LMS is transmit-only.
 
-	TIMESTAMP ts_offset;
+	TIMESTAMP ts_initial, ts_offset;
+
+	double rxGain;
+
+	int get_ant_idx(const std::string & name, bool dir_tx, size_t chan);
+	bool flush_recv(size_t num_pkts);
 
 public:
 
 	/** Object constructor */
-	LMSDevice(size_t sps);
+	LMSDevice(size_t sps, size_t chans);
 
 	/** Instantiate the LMS */
-	int open(const std::string &, int, bool);
+	int open(const std::string &args, int ref, bool swap_channels);
 
 	/** Start the LMS */
 	bool start();
@@ -62,7 +78,9 @@
 
 	/** Set priority not supported */
 	void setPriority(float prio = 0.5) {
-	} enum TxWindowType getWindowType() {
+	}
+
+	enum TxWindowType getWindowType() {
 		return TX_WINDOW_LMS1;
 	}
 
@@ -103,22 +121,22 @@
 
 	/** Returns the starting write Timestamp*/
 	TIMESTAMP initialWriteTimestamp(void) {
-		return 20000;
+		return ts_initial;
 	}
 
 	/** Returns the starting read Timestamp*/
 	TIMESTAMP initialReadTimestamp(void) {
-		return 20000;
+		return ts_initial;
 	}
 
 	/** returns the full-scale transmit amplitude **/
 	double fullScaleInputValue() {
-		return 13500.0;
+		return(double) SHRT_MAX * LIMESDR_TX_AMPL;
 	}
 
 	/** returns the full-scale receive amplitude **/
 	double fullScaleOutputValue() {
-		return 9450.0;
+		return (double) SHRT_MAX;
 	}
 
 	/** sets the receive chan gain, returns the gain setting **/
@@ -156,6 +174,12 @@
 	/* return the used RX path */
 	std::string getTxAntenna(size_t chan = 0);
 
+	/** return whether user drives synchronization of Tx/Rx of USRP */
+        bool requiresRadioAlign();
+
+        /** return whether user drives synchronization of Tx/Rx of USRP */
+        virtual GSM::Time minLatency();
+
 	/** Return internal status values */
 	inline double getTxFreq(size_t chan = 0) {
 		return 0;
diff --git a/Transceiver52M/device/radioDevice.h b/Transceiver52M/device/radioDevice.h
index 44636d5..c5cd461 100644
--- a/Transceiver52M/device/radioDevice.h
+++ b/Transceiver52M/device/radioDevice.h
@@ -39,7 +39,7 @@
 
   public:
   /* Available transport bus types */
-  enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED };
+  enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED, TX_WINDOW_LMS1 };
 
   /* Radio interface types */
   enum InterfaceType {

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

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib2fca81b76d027b08e2891056fa076d071597783
Gerrit-Change-Number: 9600
Gerrit-PatchSet: 2
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180613/7dc903cb/attachment.htm>


More information about the gerrit-log mailing list