diff options
-rw-r--r-- | Transceiver52M/UHDDevice.cpp | 39 | ||||
-rw-r--r-- | Transceiver52M/USRPDevice.cpp | 8 | ||||
-rw-r--r-- | Transceiver52M/USRPDevice.h | 2 | ||||
-rw-r--r-- | Transceiver52M/radioDevice.h | 4 | ||||
-rw-r--r-- | Transceiver52M/runTransceiver.cpp | 8 |
5 files changed, 41 insertions, 20 deletions
diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp index a6fc12d..8ef03bc 100644 --- a/Transceiver52M/UHDDevice.cpp +++ b/Transceiver52M/UHDDevice.cpp @@ -35,6 +35,8 @@ #define NUM_TX_CHANS 2 #define TX_CHAN_OFFSET 2e6 #define B100_CLK_RT 52e6 +#define B100_BASE_RT GSMRATE +#define USRP2_BASE_RT 400e3 #define TX_AMPL 0.3; #define SAMPLE_BUF_SZ (1 << 20) @@ -51,6 +53,8 @@ struct uhd_dev_offset { double offset; }; +static TIMESTAMP init_rd_ts = 0; + /* * Tx / Rx sample offset values. In a perfect world, there is no group delay * though analog components, and behaviour through digital filters exactly @@ -93,7 +97,28 @@ static double get_dev_offset(enum uhd_dev_type type, int sps) return 0.0; } -static TIMESTAMP init_rd_ts = 0; +/* + * Select sample rate based on device type and requested samples-per-symbol. + * The base rate is either GSM symbol rate, 270.833 kHz, or the minimum + * usable channel spacing of 400 kHz. + */ +static double select_rate(uhd_dev_type type, int sps) +{ + if ((sps != 4) && (sps != 2) && (sps != 1)) + return -9999.99; + + switch (type) { + case USRP2: + return USRP2_BASE_RT * sps; + break; + case B100: + return B100_BASE_RT * sps; + break; + } + + LOG(ALERT) << "Unknown device type " << type; + return -9999.99; +} /** Timestamp conversion @param timestamp a UHD or OpenBTS timestamp @@ -185,7 +210,7 @@ private: */ class uhd_device : public RadioDevice { public: - uhd_device(double rate, int sps, bool skip_rx); + uhd_device(int sps, bool skip_rx); ~uhd_device(); bool open(const std::string &args); @@ -314,9 +339,8 @@ void uhd_msg_handler(uhd::msg::type_t type, const std::string &msg) } } -uhd_device::uhd_device(double rate, int sps, bool skip_rx) - : desired_smpl_rt(rate), actual_smpl_rt(0), - tx_gain(0.0), tx_gain_min(0.0), tx_gain_max(0.0), +uhd_device::uhd_device(int sps, bool skip_rx) + : tx_gain(0.0), tx_gain_min(0.0), tx_gain_max(0.0), rx_gain(0.0), rx_gain_min(0.0), rx_gain_max(0.0), tx_freq(0.0), rx_freq(0.0), tx_spp(0), rx_spp(0), started(false), aligned(false), rx_pkt_cnt(0), drop_cnt(0), @@ -536,6 +560,7 @@ bool uhd_device::open(const std::string &args) rx_spp = rx_stream->get_max_num_samps(); // Set rates + desired_smpl_rt = select_rate(dev_type, sps); if (set_rates(desired_smpl_rt) < 0) return false; @@ -1077,7 +1102,7 @@ std::string smpl_buf::str_code(ssize_t code) } } -RadioDevice *RadioDevice::make(double smpl_rt, int sps, bool skip_rx) +RadioDevice *RadioDevice::make(int sps, bool skip_rx) { - return new uhd_device(smpl_rt, sps, skip_rx); + return new uhd_device(sps, skip_rx); } diff --git a/Transceiver52M/USRPDevice.cpp b/Transceiver52M/USRPDevice.cpp index 237c5f1..cb933a3 100644 --- a/Transceiver52M/USRPDevice.cpp +++ b/Transceiver52M/USRPDevice.cpp @@ -59,11 +59,11 @@ const dboardConfigType dboardConfig = TXA_RXB; const double USRPDevice::masterClockRate = 52.0e6; -USRPDevice::USRPDevice (double _desiredSampleRate, bool skipRx) +USRPDevice::USRPDevice(int sps, bool skipRx) : skipRx(skipRx) { LOG(INFO) << "creating USRP device..."; - decimRate = (unsigned int) round(masterClockRate/_desiredSampleRate); + decimRate = (unsigned int) round(masterClockRate/((GSMRATE) * (double) sps)); actualSampleRate = masterClockRate/decimRate; rxGain = 0; @@ -556,7 +556,7 @@ bool USRPDevice::setTxFreq(double wFreq) { return true;}; bool USRPDevice::setRxFreq(double wFreq) { return true;}; #endif -RadioDevice *RadioDevice::make(double desiredSampleRate, bool skipRx) +RadioDevice *RadioDevice::make(int sps, bool skipRx) { - return new USRPDevice(desiredSampleRate, skipRx); + return new USRPDevice(sps, skipRx); } diff --git a/Transceiver52M/USRPDevice.h b/Transceiver52M/USRPDevice.h index f2a9a6d..1417beb 100644 --- a/Transceiver52M/USRPDevice.h +++ b/Transceiver52M/USRPDevice.h @@ -112,7 +112,7 @@ private: public: /** Object constructor */ - USRPDevice (double _desiredSampleRate, bool skipRx); + USRPDevice(int sps, bool skipRx); /** Instantiate the USRP */ bool open(const std::string &); diff --git a/Transceiver52M/radioDevice.h b/Transceiver52M/radioDevice.h index 2c47736..d2308d5 100644 --- a/Transceiver52M/radioDevice.h +++ b/Transceiver52M/radioDevice.h @@ -21,6 +21,8 @@ #include "config.h" #endif +#define GSMRATE 1625e3/6 + /** a 64-bit virtual timestamp for radio data */ typedef unsigned long long TIMESTAMP; @@ -31,7 +33,7 @@ class RadioDevice { /* Available transport bus types */ enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED }; - static RadioDevice *make(double desiredSampleRate, int sps, bool skipRx = false); + static RadioDevice *make(int sps, bool skipRx = false); /** Initialize the USRP */ virtual bool open(const std::string &args)=0; diff --git a/Transceiver52M/runTransceiver.cpp b/Transceiver52M/runTransceiver.cpp index 43ee82e..6b35797 100644 --- a/Transceiver52M/runTransceiver.cpp +++ b/Transceiver52M/runTransceiver.cpp @@ -36,12 +36,6 @@ #include <Logger.h> #include <Configuration.h> -#ifdef RESAMPLE - #define DEVICERATE 400e3 -#else - #define DEVICERATE 1625e3/6 -#endif - using namespace std; ConfigurationTable gConfig("/etc/OpenBTS/OpenBTS.db"); @@ -89,7 +83,7 @@ int main(int argc, char *argv[]) srandom(time(NULL)); - RadioDevice *usrp = RadioDevice::make(DEVICERATE * SAMPSPERSYM, SAMPSPERSYM); + RadioDevice *usrp = RadioDevice::make(SAMPSPERSYM); if (!usrp->open(deviceArgs)) { LOG(ALERT) << "Transceiver exiting..." << std::endl; return EXIT_FAILURE; |