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"
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** samples per GSM symbol */
|
2013-09-05 00:16:47 +00:00
|
|
|
#define SAMPSPERSYM 4
|
2011-10-12 07:44:40 +00:00
|
|
|
#define INCHUNK (625)
|
|
|
|
#define OUTCHUNK (625)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
VectorFIFO mReceiveFIFO; ///< FIFO that holds receive bursts
|
|
|
|
|
|
|
|
RadioDevice *mRadio; ///< the USRP object
|
|
|
|
|
2013-08-21 00:54:54 +00:00
|
|
|
signalVector *sendBuffer;
|
|
|
|
signalVector *recvBuffer;
|
2011-10-12 07:44:40 +00:00
|
|
|
unsigned sendCursor;
|
2013-08-21 00:54:54 +00:00
|
|
|
unsigned recvCursor;
|
|
|
|
|
|
|
|
short *convertRecvBuffer;
|
|
|
|
short *convertSendBuffer;
|
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!
|
|
|
|
|
2013-08-20 19:41:45 +00:00
|
|
|
int sps; ///< samples per GSM symbol
|
2011-10-12 07:44:40 +00:00
|
|
|
int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
|
|
|
|
|
|
|
|
bool mOn; ///< indicates radio is on
|
|
|
|
|
|
|
|
double powerScaling;
|
|
|
|
|
|
|
|
bool loadTest;
|
|
|
|
int mNumARFCNs;
|
|
|
|
signalVector *finalVec, *finalVec9;
|
|
|
|
|
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 */
|
|
|
|
virtual bool init();
|
|
|
|
virtual void close();
|
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** constructor */
|
|
|
|
RadioInterface(RadioDevice* wRadio = NULL,
|
|
|
|
int receiveOffset = 3,
|
2013-04-08 17:45:55 +00:00
|
|
|
int wSPS = SAMPSPERSYM,
|
2011-10-12 07:44:40 +00:00
|
|
|
GSM::Time wStartTime = GSM::Time(0));
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** attach an existing USRP to this interface */
|
2011-11-26 03:18:46 +00:00
|
|
|
void attach(RadioDevice *wRadio, int wRadioOversampling);
|
2011-10-12 07:44:40 +00:00
|
|
|
|
|
|
|
/** return the receive FIFO */
|
|
|
|
VectorFIFO* receiveFIFO() { return &mReceiveFIFO;}
|
|
|
|
|
|
|
|
/** return the basestation clock */
|
|
|
|
RadioClock* getClock(void) { return &mClock;};
|
|
|
|
|
|
|
|
/** set transmit frequency */
|
|
|
|
bool tuneTx(double freq);
|
|
|
|
|
|
|
|
/** set receive frequency */
|
|
|
|
bool tuneRx(double freq);
|
|
|
|
|
2011-11-26 03:18:46 +00:00
|
|
|
/** set receive gain */
|
|
|
|
double setRxGain(double dB);
|
|
|
|
|
|
|
|
/** get receive gain */
|
|
|
|
double getRxGain(void);
|
|
|
|
|
2011-10-12 07:44:40 +00:00
|
|
|
/** drive transmission of GSM bursts */
|
|
|
|
void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst);
|
|
|
|
|
|
|
|
/** drive reception of GSM bursts */
|
|
|
|
void driveReceiveRadio();
|
|
|
|
|
|
|
|
void setPowerAttenuation(double atten);
|
|
|
|
|
|
|
|
/** 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 */
|
|
|
|
void setPriority() { mRadio->setPriority(); }
|
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:
|
|
|
|
|
|
|
|
RadioInterfaceResamp(RadioDevice* wRadio = NULL,
|
|
|
|
int receiveOffset = 3,
|
|
|
|
int wSPS = SAMPSPERSYM,
|
|
|
|
GSM::Time wStartTime = GSM::Time(0));
|
2013-08-21 00:54:54 +00:00
|
|
|
|
|
|
|
~RadioInterfaceResamp();
|
|
|
|
|
|
|
|
bool init();
|
|
|
|
void close();
|
2013-04-08 18:18:26 +00:00
|
|
|
};
|