2011-10-12 07:44:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion.
|
|
|
|
*
|
|
|
|
* This use of this software may be subject to additional restrictions.
|
|
|
|
* See the LEGAL file in the main directory for details.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _USRP_DEVICE_H_
|
|
|
|
#define _USRP_DEVICE_H_
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "radioDevice.h"
|
|
|
|
|
2013-10-11 18:55:31 +00:00
|
|
|
#include <usrp/usrp_standard.h>
|
|
|
|
#include <usrp/usrp_bytesex.h>
|
|
|
|
#include <usrp/usrp_prims.h>
|
2011-10-12 07:44:40 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
typedef boost::shared_ptr<usrp_standard_tx> usrp_standard_tx_sptr;
|
|
|
|
typedef boost::shared_ptr<usrp_standard_rx> usrp_standard_rx_sptr;
|
|
|
|
|
|
|
|
/** A class to handle a USRP rev 4, with a two RFX900 daughterboards */
|
|
|
|
class USRPDevice: public RadioDevice {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static const double masterClockRate; ///< the USRP clock rate
|
|
|
|
double desiredSampleRate; ///< the desired sampling rate
|
|
|
|
usrp_standard_rx_sptr m_uRx; ///< the USRP receiver
|
|
|
|
usrp_standard_tx_sptr m_uTx; ///< the USRP transmitter
|
2011-11-26 03:16:48 +00:00
|
|
|
|
|
|
|
db_base_sptr m_dbRx; ///< rx daughterboard
|
|
|
|
db_base_sptr m_dbTx; ///< tx daughterboard
|
|
|
|
usrp_subdev_spec rxSubdevSpec;
|
|
|
|
usrp_subdev_spec txSubdevSpec;
|
|
|
|
|
2013-10-11 17:49:55 +00:00
|
|
|
int sps;
|
2011-10-12 07:44:40 +00:00
|
|
|
double actualSampleRate; ///< the actual USRP sampling rate
|
|
|
|
unsigned int decimRate; ///< the USRP decimation rate
|
|
|
|
|
|
|
|
unsigned long long samplesRead; ///< number of samples read from USRP
|
|
|
|
unsigned long long samplesWritten; ///< number of samples sent to USRP
|
|
|
|
|
|
|
|
bool started; ///< flag indicates USRP has started
|
|
|
|
bool skipRx; ///< set if USRP is transmit-only.
|
|
|
|
|
|
|
|
static const unsigned int currDataSize_log2 = 21;
|
|
|
|
static const unsigned long currDataSize = (1 << currDataSize_log2);
|
|
|
|
short *data;
|
|
|
|
unsigned long dataStart;
|
|
|
|
unsigned long dataEnd;
|
|
|
|
TIMESTAMP timeStart;
|
|
|
|
TIMESTAMP timeEnd;
|
|
|
|
bool isAligned;
|
|
|
|
|
|
|
|
Mutex writeLock;
|
|
|
|
|
|
|
|
short *currData; ///< internal data buffer when reading from USRP
|
|
|
|
TIMESTAMP currTimestamp; ///< timestamp of internal data buffer
|
|
|
|
unsigned currLen; ///< size of internal data buffer
|
|
|
|
|
|
|
|
TIMESTAMP timestampOffset; ///< timestamp offset b/w Tx and Rx blocks
|
|
|
|
TIMESTAMP latestWriteTimestamp; ///< timestamp of most recent ping command
|
|
|
|
TIMESTAMP pingTimestamp; ///< timestamp of most recent ping response
|
2013-10-11 17:49:55 +00:00
|
|
|
|
|
|
|
long long pingOffset;
|
2011-10-12 07:44:40 +00:00
|
|
|
unsigned long hi32Timestamp;
|
|
|
|
unsigned long lastPktTimestamp;
|
|
|
|
|
|
|
|
double rxGain;
|
|
|
|
|
2018-02-05 12:04:41 +00:00
|
|
|
#ifdef SWLOOPBACK
|
2011-10-12 07:44:40 +00:00
|
|
|
short loopbackBuffer[1000000];
|
|
|
|
int loopbackBufferSize;
|
2018-02-05 12:04:41 +00:00
|
|
|
double samplePeriod;
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
struct timeval startTime;
|
|
|
|
struct timeval lastReadTime;
|
|
|
|
bool firstRead;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Object constructor */
|
2016-03-06 09:28:40 +00:00
|
|
|
USRPDevice(size_t sps);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** Instantiate the USRP */
|
2016-07-18 02:29:08 +00:00
|
|
|
int open(const std::string &, int, bool);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** Start the USRP */
|
|
|
|
bool start();
|
|
|
|
|
|
|
|
/** Stop the USRP */
|
|
|
|
bool stop();
|
|
|
|
|
2011-11-26 03:17:15 +00:00
|
|
|
/** Set priority not supported */
|
2013-11-08 17:50:03 +00:00
|
|
|
void setPriority(float prio = 0.5) { }
|
2011-11-26 03:17:15 +00:00
|
|
|
|
2013-04-05 19:36:30 +00:00
|
|
|
enum TxWindowType getWindowType() { return TX_WINDOW_USRP1; }
|
2011-11-26 03:18:55 +00:00
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/**
|
|
|
|
Read samples from the USRP.
|
|
|
|
@param buf preallocated buf to contain read result
|
|
|
|
@param len number of samples desired
|
|
|
|
@param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
|
|
|
|
@param timestamp The timestamp of the first samples to be read
|
|
|
|
@param underrun Set if USRP does not have data to transmit, e.g. data not being sent fast enough
|
|
|
|
@param RSSI The received signal strength of the read result
|
|
|
|
@return The number of samples actually read
|
|
|
|
*/
|
2013-10-29 22:34:16 +00:00
|
|
|
int readSamples(std::vector<short *> &buf, int len, bool *overrun,
|
|
|
|
TIMESTAMP timestamp = 0xffffffff, bool *underrun = NULL,
|
|
|
|
unsigned *RSSI = NULL);
|
2011-10-12 07:44:40 +00:00
|
|
|
/**
|
|
|
|
Write samples to the USRP.
|
|
|
|
@param buf Contains the data to be written.
|
|
|
|
@param len number of samples to write.
|
|
|
|
@param underrun Set if USRP does not have data to transmit, e.g. data not being sent fast enough
|
|
|
|
@param timestamp The timestamp of the first sample of the data buffer.
|
|
|
|
@param isControl Set if data is a control packet, e.g. a ping command
|
|
|
|
@return The number of samples actually written
|
|
|
|
*/
|
2013-10-29 22:34:16 +00:00
|
|
|
int writeSamples(std::vector<short *> &bufs, int len, bool *underrun,
|
|
|
|
TIMESTAMP timestamp = 0xffffffff, bool isControl = false);
|
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** Update the alignment between the read and write timestamps */
|
|
|
|
bool updateAlignment(TIMESTAMP timestamp);
|
2013-10-29 22:34:16 +00:00
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** Set the transmitter frequency */
|
2013-10-29 22:34:16 +00:00
|
|
|
bool setTxFreq(double wFreq, size_t chan = 0);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** Set the receiver frequency */
|
2013-10-29 22:34:16 +00:00
|
|
|
bool setRxFreq(double wFreq, size_t chan = 0);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** Returns the starting write Timestamp*/
|
2011-11-02 00:06:34 +00:00
|
|
|
TIMESTAMP initialWriteTimestamp(void) { return 20000;}
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** Returns the starting read Timestamp*/
|
2011-11-02 00:06:34 +00:00
|
|
|
TIMESTAMP initialReadTimestamp(void) { return 20000;}
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** returns the full-scale transmit amplitude **/
|
|
|
|
double fullScaleInputValue() {return 13500.0;}
|
|
|
|
|
|
|
|
/** returns the full-scale receive amplitude **/
|
|
|
|
double fullScaleOutputValue() {return 9450.0;}
|
|
|
|
|
|
|
|
/** sets the receive chan gain, returns the gain setting **/
|
2013-10-29 22:34:16 +00:00
|
|
|
double setRxGain(double dB, size_t chan = 0);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** get the current receive gain */
|
2013-10-29 22:34:16 +00:00
|
|
|
double getRxGain(size_t chan = 0) { return rxGain; }
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** return maximum Rx Gain **/
|
2011-11-26 03:16:48 +00:00
|
|
|
double maxRxGain(void);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** return minimum Rx Gain **/
|
2011-11-26 03:16:48 +00:00
|
|
|
double minRxGain(void);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** sets the transmit chan gain, returns the gain setting **/
|
2013-10-29 22:34:16 +00:00
|
|
|
double setTxGain(double dB, size_t chan = 0);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** return maximum Tx Gain **/
|
2011-11-26 03:16:48 +00:00
|
|
|
double maxTxGain(void);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** return minimum Rx Gain **/
|
2011-11-26 03:16:48 +00:00
|
|
|
double minTxGain(void);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
Add support to set Rx/TxAntenna
Some devices have different Rx or Tx ports with different RF characteristics.
For instance LimeSDR has H (High), L (Low) and W (Wide) band Rx ports,
each of one being more suitable to a specific range of frequencies.
In case one wants to support several GSM bands, the best option is to
use the WideBand port and connect the antenna physically to that port in
the board. Then the firmware must be instructed ro read from that port.
Support for Rx/Tx port configuration is already in there for all the
layers (Limesuite, SoapySDR, SoapyUHD, UHD), but we are missing the
required bits in osmo-trx to make use of the available UHD API. This
commit addresses it.
Before this patch, the Rx/Tx paths configured could be changed by means
of the LimeSuiteGUI app, but after running osmo-trx, the values were
changed to the default ones.
One can now start using osmo-trx with 1 channel and specific Rx/Tx ports
by using for instance: osmo-trx -c 1 -y BAND1 -z LNAW
Default behaviour if no specific path or an empry path is passed ("") is
to do the same as preiously, ie. nothing by not calling the
set{T,R}xAntenna APIs.
One can also configure only specific channels, for instance to configure
only the first Tx channel and the second Rx channel:
osmo-trx -c 2 -y BAND1, -z ,LNAW
Change-Id: I1735e6ab05a05b0312d6d679b16ebd4a2260fa23
2018-02-05 12:05:06 +00:00
|
|
|
/** sets the RX path to use, returns true if successful and false otherwise */
|
|
|
|
bool setRxAntenna(const std::string &ant, size_t chan = 0);
|
|
|
|
|
|
|
|
/* return the used RX path */
|
|
|
|
std::string getRxAntenna(size_t chan = 0);
|
|
|
|
|
|
|
|
/** sets the RX path to use, returns true if successful and false otherwise */
|
|
|
|
bool setTxAntenna(const std::string &ant, size_t chan = 0);
|
|
|
|
|
|
|
|
/* return the used RX path */
|
|
|
|
std::string getTxAntenna(size_t chan = 0);
|
|
|
|
|
2018-04-24 15:48:52 +00:00
|
|
|
/** return whether user drives synchronization of Tx/Rx of USRP */
|
|
|
|
bool requiresRadioAlign();
|
|
|
|
|
2018-04-24 16:43:51 +00:00
|
|
|
/** return whether user drives synchronization of Tx/Rx of USRP */
|
|
|
|
virtual GSM::Time minLatency();
|
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** Return internal status values */
|
2013-10-29 22:34:16 +00:00
|
|
|
inline double getTxFreq(size_t chan = 0) { return 0; }
|
|
|
|
inline double getRxFreq(size_t chan = 0) { return 0; }
|
|
|
|
inline double getSampleRate() { return actualSampleRate; }
|
2011-10-12 07:44:40 +00:00
|
|
|
inline double numberRead() { return samplesRead; }
|
2013-10-29 22:34:16 +00:00
|
|
|
inline double numberWritten() { return samplesWritten; }
|
2011-10-12 07:44:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _USRP_DEVICE_H_
|