lms: Several improvements and compilation/runtime fixes
Continuation of initial work done on LimeSuite support from Harald. Change-Id: Ib2fca81b76d027b08e2891056fa076d071597783
This commit is contained in:
parent
940738e86a
commit
c7a0bf1ffc
|
@ -53,6 +53,9 @@ extern "C" {
|
||||||
#define LOGC(category, level) \
|
#define LOGC(category, level) \
|
||||||
Log(category, LOGL_##level, __BASE_FILE__, __LINE__).get() << "[tid=" << pthread_self() << "] "
|
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.
|
A C++ stream-based thread-safe logger.
|
||||||
This object is NOT the global logger;
|
This object is NOT the global logger;
|
||||||
|
|
|
@ -10,6 +10,12 @@ static const struct log_info_cat default_categories[] = {
|
||||||
.color = NULL,
|
.color = NULL,
|
||||||
.enabled = 1, .loglevel = LOGL_NOTICE,
|
.enabled = 1, .loglevel = LOGL_NOTICE,
|
||||||
},
|
},
|
||||||
|
[DLMS] = {
|
||||||
|
.name = "DLMS",
|
||||||
|
.description = "LimeSuite category",
|
||||||
|
.color = NULL,
|
||||||
|
.enabled = 1, .loglevel = LOGL_NOTICE,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct log_info log_info = {
|
const struct log_info log_info = {
|
||||||
|
|
|
@ -5,4 +5,5 @@ extern const struct log_info log_info;
|
||||||
/* Debug Areas of the code */
|
/* Debug Areas of the code */
|
||||||
enum {
|
enum {
|
||||||
DMAIN,
|
DMAIN,
|
||||||
|
DLMS,
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,26 +24,40 @@
|
||||||
|
|
||||||
#include <lime/LimeSuite.h>
|
#include <lime/LimeSuite.h>
|
||||||
|
|
||||||
|
#include <osmocom/core/utils.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
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...";
|
LOG(INFO) << "creating LMS device...";
|
||||||
|
|
||||||
m_lms_device = NULL;
|
m_lms_stream_rx.resize(chans);
|
||||||
this->sps = sps;
|
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)
|
static void lms_log_callback(int lvl, const char *msg)
|
||||||
{
|
{
|
||||||
/* map lime specific log levels */
|
/* map lime specific log levels */
|
||||||
static const lvl_map[4] = {
|
static const int lvl_map[5] = {
|
||||||
[0] = LOGL_FATAL,
|
[0] = LOGL_FATAL,
|
||||||
[1] = LOGL_ERROR,
|
[1] = LOGL_ERROR,
|
||||||
[2] = LOGL_NOTICE,
|
[2] = LOGL_NOTICE,
|
||||||
|
@ -51,40 +65,71 @@ static void lms_log_callback(int lvl, const char *msg)
|
||||||
[4] = LOGL_DEBUG,
|
[4] = LOGL_DEBUG,
|
||||||
};
|
};
|
||||||
/* protect against future higher log level values (lower importance) */
|
/* 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;
|
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;
|
cancel ? pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) :
|
||||||
uint16_t dac_val;
|
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);
|
LMS_RegisterLogHandler(&lms_log_callback);
|
||||||
|
|
||||||
rc = LMS_Open(&m_lms_dev, NULL, NULL);
|
if ((n = LMS_GetDeviceList(NULL)) < 0)
|
||||||
if (rc != 0)
|
LOG(ERROR) << "LMS_GetDeviceList(NULL) failed";
|
||||||
return -1;
|
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;
|
goto out_close;
|
||||||
/* FIXME: make this device/model dependent, like UHDDevice:dev_param_map! */
|
/* 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) {
|
switch (ref) {
|
||||||
case REF_INTERNAL:
|
case REF_INTERNAL:
|
||||||
|
LOG(DEBUG) << "Setting Internal clock reference";
|
||||||
/* Ugly API: Selecting clock source implicit by writing to VCTCXO DAC ?!? */
|
/* Ugly API: Selecting clock source implicit by writing to VCTCXO DAC ?!? */
|
||||||
if (LMS_VCTCXORead(m_lms_dev, &dac_val) < 0)
|
if (LMS_VCTCXORead(m_lms_dev, &dac_val) < 0)
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
LOG(DEBUG) << "Setting VCTCXO to " << dac_val;
|
||||||
if (LMS_VCTCXOWrite(m_lms_dev, dac_val) < 0)
|
if (LMS_VCTCXOWrite(m_lms_dev, dac_val) < 0)
|
||||||
goto out_close;
|
goto out_close;
|
||||||
break;
|
break;
|
||||||
case REF_EXTENAL:
|
case REF_EXTERNAL:
|
||||||
|
LOG(DEBUG) << "Setting Internal clock reference to " << 10000000.0;
|
||||||
/* Assume an external 10 MHz reference clock */
|
/* Assume an external 10 MHz reference clock */
|
||||||
if (LMS_SetClockFreq(m_lms_dev, LMS_CLOCK_EXTREF, 10000000.0) < 0)
|
if (LMS_SetClockFreq(m_lms_dev, LMS_CLOCK_EXTREF, 10000000.0) < 0)
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
@ -94,14 +139,18 @@ int LMSDevice::open(const std::string &, int, bool)
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG(INFO) << "Init LMS device";
|
||||||
if (LMS_Init(m_lms_dev) < 0)
|
if (LMS_Init(m_lms_dev) < 0)
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
|
||||||
/* Perform Rx and Tx calibration */
|
/* Perform Rx and Tx calibration */
|
||||||
if (LMS_Calibrate(m_lms_dev, LMS_CH_RX, chan, 270000.0, 0) < 0)
|
for (i=0; i<chans; i++) {
|
||||||
goto out_close;
|
LOG(INFO) << "Calibrating chan " << i;
|
||||||
if (LMS_Calibrate(m_lms_dev, LMS_CH_TX, chan, 270000.0, 0) < 0)
|
if (LMS_Calibrate(m_lms_dev, LMS_CH_RX, i, LMS_CALIBRATE_BW_HZ, 0) < 0)
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
if (LMS_Calibrate(m_lms_dev, LMS_CH_TX, i, LMS_CALIBRATE_BW_HZ, 0) < 0)
|
||||||
|
goto out_close;
|
||||||
|
}
|
||||||
|
|
||||||
samplesRead = 0;
|
samplesRead = 0;
|
||||||
samplesWritten = 0;
|
samplesWritten = 0;
|
||||||
|
@ -119,42 +168,47 @@ bool LMSDevice::start()
|
||||||
{
|
{
|
||||||
LOG(INFO) << "starting LMS...";
|
LOG(INFO) << "starting LMS...";
|
||||||
|
|
||||||
if (LMS_EnableChannel(m_lms_dev, LMS_CH_RX, 0, true) < 0)
|
unsigned int i;
|
||||||
return false;
|
|
||||||
|
|
||||||
if (LMS_EnableChannel(m_lms_dev, LMS_CH_TX, 0, true) < 0)
|
for (i=0; i<chans; i++) {
|
||||||
return false;
|
if (LMS_EnableChannel(m_lms_dev, LMS_CH_RX, i, true) < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Set gains to midpoint
|
if (LMS_EnableChannel(m_lms_dev, LMS_CH_TX, i, true) < 0)
|
||||||
setTxGain((minTxGain() + maxTxGain()) / 2);
|
return false;
|
||||||
setRxGain((minRxGain() + maxRxGain()) / 2);
|
|
||||||
|
|
||||||
m_lms_stream_rx = {
|
// Set gains to midpoint
|
||||||
.isTx = false,
|
setTxGain((minTxGain() + maxTxGain()) / 2, i);
|
||||||
.channel = 0,
|
setRxGain((minRxGain() + maxRxGain()) / 2, i);
|
||||||
.fifoSize = 1024 * 1024,
|
|
||||||
.throughputVsLatency = 0.3,
|
m_lms_stream_rx[i] = {};
|
||||||
.dataFmt = LMS_FMT_I16,
|
m_lms_stream_rx[i].isTx = false;
|
||||||
}
|
m_lms_stream_rx[i].channel = i;
|
||||||
m_lms_stream_tx = {
|
m_lms_stream_rx[i].fifoSize = 1024 * 1024;
|
||||||
.ixTx = true,
|
m_lms_stream_rx[i].throughputVsLatency = 0.3;
|
||||||
.channel = 0,
|
m_lms_stream_rx[i].dataFmt = lms_stream_t::LMS_FMT_I16;
|
||||||
.fifoSize = 1024 * 1024,
|
|
||||||
.throughputVsLatency = 0.3,
|
m_lms_stream_tx[i] = {};
|
||||||
.dataFmt = LMS_FMT_I16,
|
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)
|
flush_recv(10);
|
||||||
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;
|
|
||||||
|
|
||||||
started = true;
|
started = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -162,14 +216,18 @@ bool LMSDevice::start()
|
||||||
|
|
||||||
bool LMSDevice::stop()
|
bool LMSDevice::stop()
|
||||||
{
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
if (!started)
|
if (!started)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
LMS_StopStream(&m_lms_stream_tx);
|
for (i=0; i<chans; i++) {
|
||||||
LMS_StopStream(&m_lms_stream_rx);
|
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_RX, i, false);
|
||||||
LMS_EnableChannel(m_lms_dev, LMS_CH_TX, 0, false);
|
LMS_EnableChannel(m_lms_dev, LMS_CH_TX, i, false);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -236,18 +294,50 @@ double LMSDevice::setRxGain(double dB, size_t chan)
|
||||||
return dB;
|
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;
|
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++) {
|
for (i = 0; i < num_names; i++) {
|
||||||
if (!strcmp(name, name_list[i]))
|
if (!strcmp(c_name, name_list[i]))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
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)
|
bool LMSDevice::setRxAntenna(const std::string & ant, size_t chan)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
|
@ -257,7 +347,7 @@ bool LMSDevice::setRxAntenna(const std::string & ant, size_t chan)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = get_ant_idx(ant, LMS_CH_RX);
|
idx = get_ant_idx(ant, LMS_CH_RX, chan);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
LOG(ALERT) << "Invalid Rx Antenna";
|
LOG(ALERT) << "Invalid Rx Antenna";
|
||||||
return false;
|
return false;
|
||||||
|
@ -272,6 +362,9 @@ bool LMSDevice::setRxAntenna(const std::string & ant, size_t chan)
|
||||||
|
|
||||||
std::string LMSDevice::getRxAntenna(size_t chan)
|
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()) {
|
if (chan >= rx_paths.size()) {
|
||||||
LOG(ALERT) << "Requested non-existent channel " << chan;
|
LOG(ALERT) << "Requested non-existent channel " << chan;
|
||||||
return "";
|
return "";
|
||||||
|
@ -283,12 +376,12 @@ std::string LMSDevice::getRxAntenna(size_t chan)
|
||||||
return "";
|
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";
|
LOG(ALERT) << "Error getting Rx Antenna List";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return list[idx];
|
return name_list[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LMSDevice::setTxAntenna(const std::string & ant, size_t chan)
|
bool LMSDevice::setTxAntenna(const std::string & ant, size_t chan)
|
||||||
|
@ -300,7 +393,7 @@ bool LMSDevice::setTxAntenna(const std::string & ant, size_t chan)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = get_ant_idx(ant, LMS_CH_TX);
|
idx = get_ant_idx(ant, LMS_CH_TX, chan);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
LOG(ALERT) << "Invalid Rx Antenna";
|
LOG(ALERT) << "Invalid Rx Antenna";
|
||||||
return false;
|
return false;
|
||||||
|
@ -315,6 +408,7 @@ bool LMSDevice::setTxAntenna(const std::string & ant, size_t chan)
|
||||||
|
|
||||||
std::string LMSDevice::getTxAntenna(size_t chan)
|
std::string LMSDevice::getTxAntenna(size_t chan)
|
||||||
{
|
{
|
||||||
|
lms_name_t name_list[MAX_ANTENNA_LIST_SIZE]; /* large enough list for antenna names. */
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
if (chan >= tx_paths.size()) {
|
if (chan >= tx_paths.size()) {
|
||||||
|
@ -328,49 +422,73 @@ std::string LMSDevice::getTxAntenna(size_t chan)
|
||||||
return "";
|
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";
|
LOG(ALERT) << "Error getting Tx Antenna List";
|
||||||
return "";
|
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
|
// NOTE: Assumes sequential reads
|
||||||
int LMSDevice::readSamples(std::vector < short *>&bufs, int len, bool * overrun,
|
int LMSDevice::readSamples(std::vector < short *>&bufs, int len, bool * overrun,
|
||||||
TIMESTAMP timestamp, bool * underrun, unsigned *RSSI)
|
TIMESTAMP timestamp, bool * underrun, unsigned *RSSI)
|
||||||
{
|
{
|
||||||
lms_stream_meta_t rx_metadata = {
|
int rc = 0;
|
||||||
.flushPartialPacket = false,
|
unsigned int i;
|
||||||
.waitForTimestamp = false,
|
lms_stream_status_t status;
|
||||||
};
|
lms_stream_meta_t rx_metadata = {};
|
||||||
int rc;
|
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();
|
LOG(ALERT) << "Invalid channel combination " << bufs.size();
|
||||||
return -1;
|
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;
|
*overrun = false;
|
||||||
*underrun = 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 (LMS_GetStreamStatus(&m_lms_stream_rx[i], &status) == 0) {
|
||||||
if (status.underrun > m_last_rx_underruns)
|
if (status.underrun > m_last_rx_underruns[i])
|
||||||
*underrun = true;
|
*underrun = true;
|
||||||
m_last_rx_underruns = status.underrun;
|
m_last_rx_underruns[i] = status.underrun;
|
||||||
|
|
||||||
if (status.overrun > m_last_rx_overruns)
|
if (status.overrun > m_last_rx_overruns[i])
|
||||||
*overrun = true;
|
*overrun = true;
|
||||||
m_last_rx_overruns = status.overrun;
|
m_last_rx_overruns[i] = status.overrun;
|
||||||
|
}
|
||||||
|
thread_enable_cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
samplesRead += rc;
|
samplesRead += rc;
|
||||||
|
|
||||||
|
if (((TIMESTAMP) rx_metadata.timestamp) < timestamp)
|
||||||
|
rc = 0;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,35 +496,40 @@ int LMSDevice::writeSamples(std::vector < short *>&bufs, int len,
|
||||||
bool * underrun, unsigned long long timestamp,
|
bool * underrun, unsigned long long timestamp,
|
||||||
bool isControl)
|
bool isControl)
|
||||||
{
|
{
|
||||||
lms_stream_status_t status;
|
|
||||||
lms_stream_meta_t tx_metadata = {
|
|
||||||
.flushPartialPacket = false,
|
|
||||||
.waitForTimestamp = true,
|
|
||||||
.timestamp = timestamp,
|
|
||||||
};
|
|
||||||
int rc;
|
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) {
|
if (isControl) {
|
||||||
LOG(ERR) << "Control packets not supported";
|
LOG(ERR) << "Control packets not supported";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bufs.size() != 1) {
|
if (bufs.size() != chans) {
|
||||||
LOG(ALERT) << "Invalid channel combination " << bufs.size();
|
LOG(ALERT) << "Invalid channel combination " << bufs.size();
|
||||||
return -1;
|
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;
|
*underrun = false;
|
||||||
|
|
||||||
if (LMS_GetStreamStatus(&m_lms_stream_tx, &status) == 0) {
|
for (i = 0; i<chans; i++) {
|
||||||
if (status.underrun > m_last_tx_underruns)
|
LOG(ALERT) << "chan "<< i << " send buffer of len " << len << " timestamp " << std::hex << tx_metadata.timestamp;
|
||||||
*underrun = true;
|
thread_enable_cancel(false);
|
||||||
m_last_tx_underruns = status.underrun;
|
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;
|
samplesWritten += rc;
|
||||||
|
@ -416,17 +539,7 @@ int LMSDevice::writeSamples(std::vector < short *>&bufs, int len,
|
||||||
|
|
||||||
bool LMSDevice::updateAlignment(TIMESTAMP timestamp)
|
bool LMSDevice::updateAlignment(TIMESTAMP timestamp)
|
||||||
{
|
{
|
||||||
short data[] = { 0x00, 0x02, 0x00, 0x00 };
|
return true;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LMSDevice::setTxFreq(double wFreq, size_t chan)
|
bool LMSDevice::setTxFreq(double wFreq, size_t chan)
|
||||||
|
@ -465,5 +578,5 @@ RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
|
||||||
const std::vector < std::string > &tx_paths,
|
const std::vector < std::string > &tx_paths,
|
||||||
const std::vector < std::string > &rx_paths)
|
const std::vector < std::string > &rx_paths)
|
||||||
{
|
{
|
||||||
return new LMSDevice(tx_sps);
|
return new LMSDevice(tx_sps, chans);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,22 +21,33 @@
|
||||||
|
|
||||||
#include "radioDevice.h"
|
#include "radioDevice.h"
|
||||||
|
|
||||||
#include <lime/LMSDevice.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <lime/LimeSuite.h>
|
||||||
|
|
||||||
|
#define LIMESDR_TX_AMPL 0.3
|
||||||
|
|
||||||
/** A class to handle a LimeSuite supported device */
|
/** A class to handle a LimeSuite supported device */
|
||||||
class LMSDevice:public RadioDevice {
|
class LMSDevice:public RadioDevice {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
lms_device_t *m_lms_dev;
|
static constexpr double masterClockRate = 52.0e6;
|
||||||
lms_stream_t m_lms_Stream_rx;
|
|
||||||
lms_stream_t m_lms_Stream_tx;
|
|
||||||
|
|
||||||
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 samplesRead; ///< number of samples read from LMS
|
||||||
unsigned long long samplesWritten; ///< number of samples sent to LMS
|
unsigned long long samplesWritten; ///< number of samples sent to LMS
|
||||||
|
@ -44,15 +55,20 @@ private:
|
||||||
bool started; ///< flag indicates LMS has started
|
bool started; ///< flag indicates LMS has started
|
||||||
bool skipRx; ///< set if LMS is transmit-only.
|
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:
|
public:
|
||||||
|
|
||||||
/** Object constructor */
|
/** Object constructor */
|
||||||
LMSDevice(size_t sps);
|
LMSDevice(size_t sps, size_t chans);
|
||||||
|
|
||||||
/** Instantiate the LMS */
|
/** Instantiate the LMS */
|
||||||
int open(const std::string &, int, bool);
|
int open(const std::string &args, int ref, bool swap_channels);
|
||||||
|
|
||||||
/** Start the LMS */
|
/** Start the LMS */
|
||||||
bool start();
|
bool start();
|
||||||
|
@ -62,7 +78,9 @@ public:
|
||||||
|
|
||||||
/** Set priority not supported */
|
/** Set priority not supported */
|
||||||
void setPriority(float prio = 0.5) {
|
void setPriority(float prio = 0.5) {
|
||||||
} enum TxWindowType getWindowType() {
|
}
|
||||||
|
|
||||||
|
enum TxWindowType getWindowType() {
|
||||||
return TX_WINDOW_LMS1;
|
return TX_WINDOW_LMS1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,22 +121,22 @@ public:
|
||||||
|
|
||||||
/** Returns the starting write Timestamp*/
|
/** Returns the starting write Timestamp*/
|
||||||
TIMESTAMP initialWriteTimestamp(void) {
|
TIMESTAMP initialWriteTimestamp(void) {
|
||||||
return 20000;
|
return ts_initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the starting read Timestamp*/
|
/** Returns the starting read Timestamp*/
|
||||||
TIMESTAMP initialReadTimestamp(void) {
|
TIMESTAMP initialReadTimestamp(void) {
|
||||||
return 20000;
|
return ts_initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns the full-scale transmit amplitude **/
|
/** returns the full-scale transmit amplitude **/
|
||||||
double fullScaleInputValue() {
|
double fullScaleInputValue() {
|
||||||
return 13500.0;
|
return(double) SHRT_MAX * LIMESDR_TX_AMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns the full-scale receive amplitude **/
|
/** returns the full-scale receive amplitude **/
|
||||||
double fullScaleOutputValue() {
|
double fullScaleOutputValue() {
|
||||||
return 9450.0;
|
return (double) SHRT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** sets the receive chan gain, returns the gain setting **/
|
/** sets the receive chan gain, returns the gain setting **/
|
||||||
|
@ -156,6 +174,12 @@ public:
|
||||||
/* return the used RX path */
|
/* return the used RX path */
|
||||||
std::string getTxAntenna(size_t chan = 0);
|
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 */
|
/** Return internal status values */
|
||||||
inline double getTxFreq(size_t chan = 0) {
|
inline double getTxFreq(size_t chan = 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -39,7 +39,7 @@ class RadioDevice {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Available transport bus types */
|
/* 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 */
|
/* Radio interface types */
|
||||||
enum InterfaceType {
|
enum InterfaceType {
|
||||||
|
|
Loading…
Reference in New Issue