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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "sigProcLib.h"
|
|
|
|
#include "GSMCommon.h"
|
|
|
|
#include "LinkedLists.h"
|
|
|
|
#include "radioDevice.h"
|
2011-11-26 03:18:30 +00:00
|
|
|
#include "radioVector.h"
|
|
|
|
#include "radioClock.h"
|
2013-11-14 04:38:09 +00:00
|
|
|
#include "Resampler.h"
|
2011-10-12 07:44:40 +00:00
|
|
|
|
2013-06-16 10:30:58 +00:00
|
|
|
static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods
|
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** class to interface the transceiver with the USRP */
|
|
|
|
class RadioInterface {
|
|
|
|
|
2013-04-08 18:18:26 +00:00
|
|
|
protected:
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
Thread mAlignRadioServiceLoopThread; ///< thread that synchronizes transmit and receive sections
|
|
|
|
|
2013-10-29 22:34:16 +00:00
|
|
|
std::vector<VectorFIFO> mReceiveFIFO; ///< FIFO that holds receive bursts
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
RadioDevice *mRadio; ///< the USRP object
|
2013-10-11 17:49:55 +00:00
|
|
|
|
2013-10-29 22:34:16 +00:00
|
|
|
size_t mSPSTx;
|
|
|
|
size_t mSPSRx;
|
|
|
|
size_t mChans;
|
2013-11-14 04:38:09 +00:00
|
|
|
size_t mMIMO;
|
|
|
|
|
2013-10-29 22:34:16 +00:00
|
|
|
std::vector<signalVector *> sendBuffer;
|
|
|
|
std::vector<signalVector *> recvBuffer;
|
2011-10-12 07:44:40 +00:00
|
|
|
unsigned sendCursor;
|
2013-08-21 00:54:54 +00:00
|
|
|
unsigned recvCursor;
|
|
|
|
|
2013-10-29 22:34:16 +00:00
|
|
|
std::vector<short *> convertRecvBuffer;
|
|
|
|
std::vector<short *> convertSendBuffer;
|
2013-11-15 19:15:47 +00:00
|
|
|
std::vector<float> powerScaling;
|
2011-10-12 07:44:40 +00:00
|
|
|
bool underrun; ///< indicates writes to USRP are too slow
|
|
|
|
bool overrun; ///< indicates reads from USRP are too slow
|
|
|
|
TIMESTAMP writeTimestamp; ///< sample timestamp of next packet written to USRP
|
|
|
|
TIMESTAMP readTimestamp; ///< sample timestamp of next packet read from USRP
|
|
|
|
|
|
|
|
RadioClock mClock; ///< the basestation clock!
|
|
|
|
|
|
|
|
int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
|
|
|
|
|
|
|
|
bool mOn; ///< indicates radio is on
|
|
|
|
|
2013-04-08 18:18:26 +00:00
|
|
|
private:
|
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** format samples to USRP */
|
2011-11-26 03:18:34 +00:00
|
|
|
int radioifyVector(signalVector &wVector,
|
|
|
|
float *floatVector,
|
|
|
|
bool zero);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** format samples from USRP */
|
2011-11-26 03:18:34 +00:00
|
|
|
int unRadioifyVector(float *floatVector, signalVector &wVector);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** push GSM bursts into the transmit buffer */
|
2013-04-08 18:18:26 +00:00
|
|
|
virtual void pushBuffer(void);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** pull GSM bursts from the receive buffer */
|
2013-04-08 18:18:26 +00:00
|
|
|
virtual void pullBuffer(void);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** start the interface */
|
|
|
|
void start();
|
|
|
|
|
2013-08-21 00:54:54 +00:00
|
|
|
/** intialization */
|
2013-10-15 03:56:51 +00:00
|
|
|
virtual bool init(int type);
|
2013-08-21 00:54:54 +00:00
|
|
|
virtual void close();
|
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** constructor */
|
|
|
|
RadioInterface(RadioDevice* wRadio = NULL,
|
2013-11-14 04:38:09 +00:00
|
|
|
size_t sps = 4, size_t chans = 1, size_t diversity = 1,
|
|
|
|
int receiveOffset = 3, GSM::Time wStartTime = GSM::Time(0));
|
2013-10-29 22:34:16 +00:00
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** destructor */
|
2013-08-21 00:54:54 +00:00
|
|
|
virtual ~RadioInterface();
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** check for underrun, resets underrun value */
|
2011-11-26 03:18:46 +00:00
|
|
|
bool isUnderrun();
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** return the receive FIFO */
|
2013-10-29 22:34:16 +00:00
|
|
|
VectorFIFO* receiveFIFO(size_t chan = 0);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** return the basestation clock */
|
|
|
|
RadioClock* getClock(void) { return &mClock;};
|
|
|
|
|
|
|
|
/** set transmit frequency */
|
2013-10-29 22:34:16 +00:00
|
|
|
bool tuneTx(double freq, size_t chan = 0);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** set receive frequency */
|
2013-11-14 04:38:09 +00:00
|
|
|
virtual bool tuneRx(double freq, size_t chan = 0);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
2011-11-26 03:18:46 +00:00
|
|
|
/** set receive gain */
|
2013-10-29 22:34:16 +00:00
|
|
|
double setRxGain(double dB, size_t chan = 0);
|
2011-11-26 03:18:46 +00:00
|
|
|
|
|
|
|
/** get receive gain */
|
2013-10-29 22:34:16 +00:00
|
|
|
double getRxGain(size_t chan = 0);
|
2011-11-26 03:18:46 +00:00
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** drive transmission of GSM bursts */
|
2013-10-29 22:34:16 +00:00
|
|
|
void driveTransmitRadio(std::vector<signalVector *> &bursts,
|
|
|
|
std::vector<bool> &zeros);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** drive reception of GSM bursts */
|
2013-10-29 22:34:16 +00:00
|
|
|
bool driveReceiveRadio();
|
2011-10-12 07:44:40 +00:00
|
|
|
|
2013-10-29 22:34:16 +00:00
|
|
|
void setPowerAttenuation(double atten, size_t chan = 0);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** returns the full-scale transmit amplitude **/
|
|
|
|
double fullScaleInputValue();
|
|
|
|
|
|
|
|
/** returns the full-scale receive amplitude **/
|
|
|
|
double fullScaleOutputValue();
|
|
|
|
|
2011-11-26 03:17:21 +00:00
|
|
|
/** set thread priority on current thread */
|
2013-11-08 17:50:03 +00:00
|
|
|
void setPriority(float prio = 0.5) { mRadio->setPriority(prio); }
|
2011-10-12 07:44:40 +00:00
|
|
|
|
2013-04-05 19:36:30 +00:00
|
|
|
/** get transport window type of attached device */
|
|
|
|
enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
|
2011-11-26 03:18:55 +00:00
|
|
|
|
2013-04-08 17:35:36 +00:00
|
|
|
#if USRP1
|
2011-10-12 07:44:40 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/** drive synchronization of Tx/Rx of USRP */
|
|
|
|
void alignRadio();
|
|
|
|
|
|
|
|
friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
|
2013-04-08 17:35:36 +00:00
|
|
|
#endif
|
2011-10-12 07:44:40 +00:00
|
|
|
};
|
|
|
|
|
2013-04-08 17:35:36 +00:00
|
|
|
#if USRP1
|
2011-10-12 07:44:40 +00:00
|
|
|
/** synchronization thread loop */
|
|
|
|
void *AlignRadioServiceLoopAdapter(RadioInterface*);
|
2013-04-08 17:35:36 +00:00
|
|
|
#endif
|
2013-04-08 18:18:26 +00:00
|
|
|
|
|
|
|
class RadioInterfaceResamp : public RadioInterface {
|
|
|
|
|
|
|
|
private:
|
2013-08-21 00:54:54 +00:00
|
|
|
signalVector *innerSendBuffer;
|
|
|
|
signalVector *outerSendBuffer;
|
|
|
|
signalVector *innerRecvBuffer;
|
|
|
|
signalVector *outerRecvBuffer;
|
2013-04-08 18:18:26 +00:00
|
|
|
|
|
|
|
void pushBuffer();
|
|
|
|
void pullBuffer();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-11-14 04:38:09 +00:00
|
|
|
RadioInterfaceResamp(RadioDevice* wRadio, size_t wSPS = 4, size_t chans = 1);
|
2013-08-21 00:54:54 +00:00
|
|
|
|
|
|
|
~RadioInterfaceResamp();
|
|
|
|
|
2013-10-15 03:56:51 +00:00
|
|
|
bool init(int type);
|
2013-08-21 00:54:54 +00:00
|
|
|
void close();
|
2013-04-08 18:18:26 +00:00
|
|
|
};
|
2013-11-14 04:38:09 +00:00
|
|
|
|
|
|
|
class RadioInterfaceDiversity : public RadioInterface {
|
|
|
|
public:
|
|
|
|
RadioInterfaceDiversity(RadioDevice* wRadio,
|
|
|
|
size_t sps = 4, size_t chans = 2);
|
|
|
|
|
|
|
|
~RadioInterfaceDiversity();
|
|
|
|
|
|
|
|
bool init(int type);
|
|
|
|
void close();
|
|
|
|
bool tuneRx(double freq, size_t chan);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Resampler *> dnsamplers;
|
|
|
|
std::vector<float> phases;
|
|
|
|
signalVector *outerRecvBuffer;
|
|
|
|
|
|
|
|
bool mDiversity;
|
|
|
|
double mFreqSpacing;
|
|
|
|
|
|
|
|
bool setupDiversityChannels();
|
|
|
|
void pullBuffer();
|
|
|
|
};
|