uhd: Add command line option for GPS reference

Unlike earlier versions of UHD, the current release (3.9.2)
does not automatically select on-board GPSDO as the reference
source. Modify the command line settings to allow explicit
selection of GPS in addition to the external setting.

Simultaneous GPS and external reference settingis disallowed.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
This commit is contained in:
Tom Tsou 2016-07-17 19:29:08 -07:00
parent cbfef6e40a
commit 2f3e60bc1f
5 changed files with 60 additions and 13 deletions

View File

@ -269,7 +269,7 @@ public:
size_t chans, double offset);
~uhd_device();
int open(const std::string &args, bool extref, bool swap_channels);
int open(const std::string &args, int ref, bool swap_channels);
bool start();
bool stop();
bool restart();
@ -770,8 +770,10 @@ static bool uhd_e3xx_version_chk()
return true;
}
int uhd_device::open(const std::string &args, bool extref, bool swap_channels)
int uhd_device::open(const std::string &args, int ref, bool swap_channels)
{
const char *refstr;
// Find UHD devices
uhd::device_addr_t addr(args);
uhd::device_addrs_t dev_addrs = uhd::device::find(addr);
@ -828,8 +830,22 @@ int uhd_device::open(const std::string &args, bool extref, bool swap_channels)
rx_gains.resize(chans);
rx_buffers.resize(chans);
if (extref)
usrp_dev->set_clock_source("external");
switch (ref) {
case REF_INTERNAL:
refstr = "internal";
break;
case REF_EXTERNAL:
refstr = "external";
break;
case REF_GPS:
refstr = "gpsdo";
break;
default:
LOG(ALERT) << "Invalid reference type";
return -1;
}
usrp_dev->set_clock_source(refstr);
// Set rates
double _rx_rate = select_rate(dev_type, rx_sps, iface);

View File

@ -89,7 +89,7 @@ USRPDevice::USRPDevice(size_t sps)
#endif
}
int USRPDevice::open(const std::string &, bool, bool)
int USRPDevice::open(const std::string &, int, bool)
{
writeLock.unlock();

View File

@ -99,7 +99,7 @@ private:
USRPDevice(size_t sps);
/** Instantiate the USRP */
int open(const std::string &, bool, bool);
int open(const std::string &, int, bool);
/** Start the USRP */
bool start();

View File

@ -72,6 +72,7 @@ struct trx_config {
unsigned rtsc;
unsigned rach_delay;
bool extref;
bool gpsref;
Transceiver::FillerType filler;
bool diversity;
bool mcbts;
@ -183,10 +184,16 @@ bool trx_setup_config(struct trx_config *config)
}
edgestr = config->edge ? "Enabled" : "Disabled";
refstr = config->extref ? "Enabled" : "Disabled";
divstr = config->diversity ? "Enabled" : "Disabled";
mcstr = config->mcbts ? "Enabled" : "Disabled";
if (config->extref)
refstr = "External";
else if (config->gpsref)
refstr = "GPS";
else
refstr = "Internal";
switch (config->filler) {
case Transceiver::FILLER_DUMMY:
fillstr = "Dummy bursts";
@ -215,7 +222,7 @@ bool trx_setup_config(struct trx_config *config)
ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
ost << " EDGE support............ " << edgestr << std::endl;
ost << " External Reference...... " << refstr << std::endl;
ost << " Reference............... " << refstr << std::endl;
ost << " C0 Filler Table......... " << fillstr << std::endl;
ost << " Multi-Carrier........... " << mcstr << std::endl;
ost << " Diversity............... " << divstr << std::endl;
@ -331,9 +338,10 @@ static void print_help()
" -i IP address of GSM core\n"
" -p Base port number\n"
" -e Enable EDGE receiver\n"
" -d Enable dual channel diversity receiver\n"
" -d Enable dual channel diversity receiver (deprecated)\n"
" -m Enable multi-ARFCN transceiver (default=disabled)\n"
" -x Enable external 10 MHz reference\n"
" -g Enable GPSDO reference\n"
" -s Tx samples-per-symbol (1 or 4)\n"
" -b Rx samples-per-symbol (1 or 4)\n"
" -c Number of ARFCN channels (default=1)\n"
@ -357,6 +365,7 @@ static void handle_options(int argc, char **argv, struct trx_config *config)
config->rtsc = 0;
config->rach_delay = 0;
config->extref = false;
config->gpsref = false;
config->filler = Transceiver::FILLER_ZERO;
config->mcbts = false;
config->diversity = false;
@ -365,7 +374,7 @@ static void handle_options(int argc, char **argv, struct trx_config *config)
config->swap_channels = false;
config->edge = false;
while ((option = getopt(argc, argv, "ha:l:i:p:c:dmxfo:s:b:r:A:R:Se")) != -1) {
while ((option = getopt(argc, argv, "ha:l:i:p:c:dmxgfo:s:b:r:A:R:Se")) != -1) {
switch (option) {
case 'h':
print_help();
@ -395,6 +404,9 @@ static void handle_options(int argc, char **argv, struct trx_config *config)
case 'x':
config->extref = true;
break;
case 'g':
config->gpsref = true;
break;
case 'f':
config->filler = Transceiver::FILLER_DUMMY;
break;
@ -430,6 +442,12 @@ static void handle_options(int argc, char **argv, struct trx_config *config)
}
}
if (config->gpsref && config->extref) {
printf("External and GPSDO references unavailable at the same time\n\n");
print_help();
exit(0);
}
/* Force 4 SPS for EDGE or multi-ARFCN configurations */
if ((config->edge) || (config->mcbts)) {
config->tx_sps = 4;
@ -461,7 +479,7 @@ static void handle_options(int argc, char **argv, struct trx_config *config)
int main(int argc, char *argv[])
{
int type, chans;
int type, chans, ref;
RadioDevice *usrp;
RadioInterface *radio = NULL;
Transceiver *trx = NULL;
@ -486,9 +504,16 @@ int main(int argc, char *argv[])
if (config.mcbts)
iface = RadioDevice::MULTI_ARFCN;
if (config.extref)
ref = RadioDevice::REF_EXTERNAL;
else if (config.gpsref)
ref = RadioDevice::REF_GPS;
else
ref = RadioDevice::REF_INTERNAL;
usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
config.chans, config.offset);
type = usrp->open(config.dev_args, config.extref, config.swap_channels);
type = usrp->open(config.dev_args, ref, config.swap_channels);
if (type < 0) {
LOG(ALERT) << "Failed to create radio device" << std::endl;
goto shutdown;

View File

@ -44,11 +44,17 @@ class RadioDevice {
DIVERSITY,
};
enum ReferenceType {
REF_INTERNAL,
REF_EXTERNAL,
REF_GPS,
};
static RadioDevice *make(size_t tx_sps, size_t rx_sps, InterfaceType type,
size_t chans = 1, double offset = 0.0);
/** Initialize the USRP */
virtual int open(const std::string &args = "", bool extref = false, bool swap_channels = false)=0;
virtual int open(const std::string &args, int ref, bool swap_channels)=0;
virtual ~RadioDevice() { }