blob: 690d57286ce3564d7d113e712ab2e9c1062c3d02 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
2* Copyright 2008 Free Software Foundation, Inc.
3*
4* This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion.
5*
6* This use of this software may be subject to additional restrictions.
7* See the LEGAL file in the main directory for details.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13*/
14
15
16
17#include "sigProcLib.h"
18#include "GSMCommon.h"
19#include "LinkedLists.h"
20#include "radioDevice.h"
kurtis.heimerl8aea56e2011-11-26 03:18:30 +000021#include "radioVector.h"
22#include "radioClock.h"
dburgessb3a0ca42011-10-12 07:44:40 +000023
24/** samples per GSM symbol */
25#define SAMPSPERSYM 1
26#define INCHUNK (625)
27#define OUTCHUNK (625)
28
Alexander Chemerisd734e2d2013-06-16 14:30:58 +040029static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods
30
dburgessb3a0ca42011-10-12 07:44:40 +000031/** class to interface the transceiver with the USRP */
32class RadioInterface {
33
Thomas Tsoucb69f082013-04-08 14:18:26 -040034protected:
dburgessb3a0ca42011-10-12 07:44:40 +000035
36 Thread mAlignRadioServiceLoopThread; ///< thread that synchronizes transmit and receive sections
37
38 VectorFIFO mReceiveFIFO; ///< FIFO that holds receive bursts
39
40 RadioDevice *mRadio; ///< the USRP object
41
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040042 signalVector *sendBuffer;
43 signalVector *recvBuffer;
dburgessb3a0ca42011-10-12 07:44:40 +000044 unsigned sendCursor;
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040045 unsigned recvCursor;
dburgessb3a0ca42011-10-12 07:44:40 +000046
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040047 short *convertRecvBuffer;
48 short *convertSendBuffer;
49
dburgessb3a0ca42011-10-12 07:44:40 +000050 bool underrun; ///< indicates writes to USRP are too slow
51 bool overrun; ///< indicates reads from USRP are too slow
52 TIMESTAMP writeTimestamp; ///< sample timestamp of next packet written to USRP
53 TIMESTAMP readTimestamp; ///< sample timestamp of next packet read from USRP
54
55 RadioClock mClock; ///< the basestation clock!
56
Thomas Tsoud24cc2c2013-08-20 15:41:45 -040057 int sps; ///< samples per GSM symbol
dburgessb3a0ca42011-10-12 07:44:40 +000058 int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
dburgessb3a0ca42011-10-12 07:44:40 +000059
60 bool mOn; ///< indicates radio is on
61
62 double powerScaling;
63
64 bool loadTest;
65 int mNumARFCNs;
66 signalVector *finalVec, *finalVec9;
67
Thomas Tsoucb69f082013-04-08 14:18:26 -040068private:
69
dburgessb3a0ca42011-10-12 07:44:40 +000070 /** format samples to USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000071 int radioifyVector(signalVector &wVector,
72 float *floatVector,
73 float scale,
74 bool zero);
dburgessb3a0ca42011-10-12 07:44:40 +000075
76 /** format samples from USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000077 int unRadioifyVector(float *floatVector, signalVector &wVector);
dburgessb3a0ca42011-10-12 07:44:40 +000078
79 /** push GSM bursts into the transmit buffer */
Thomas Tsoucb69f082013-04-08 14:18:26 -040080 virtual void pushBuffer(void);
dburgessb3a0ca42011-10-12 07:44:40 +000081
82 /** pull GSM bursts from the receive buffer */
Thomas Tsoucb69f082013-04-08 14:18:26 -040083 virtual void pullBuffer(void);
dburgessb3a0ca42011-10-12 07:44:40 +000084
85public:
86
87 /** start the interface */
88 void start();
89
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040090 /** intialization */
91 virtual bool init();
92 virtual void close();
93
dburgessb3a0ca42011-10-12 07:44:40 +000094 /** constructor */
95 RadioInterface(RadioDevice* wRadio = NULL,
96 int receiveOffset = 3,
Thomas Tsou312e3872013-04-08 13:45:55 -040097 int wSPS = SAMPSPERSYM,
dburgessb3a0ca42011-10-12 07:44:40 +000098 GSM::Time wStartTime = GSM::Time(0));
99
100 /** destructor */
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400101 virtual ~RadioInterface();
dburgessb3a0ca42011-10-12 07:44:40 +0000102
dburgessb3a0ca42011-10-12 07:44:40 +0000103 /** check for underrun, resets underrun value */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000104 bool isUnderrun();
dburgessb3a0ca42011-10-12 07:44:40 +0000105
106 /** attach an existing USRP to this interface */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000107 void attach(RadioDevice *wRadio, int wRadioOversampling);
dburgessb3a0ca42011-10-12 07:44:40 +0000108
109 /** return the receive FIFO */
110 VectorFIFO* receiveFIFO() { return &mReceiveFIFO;}
111
112 /** return the basestation clock */
113 RadioClock* getClock(void) { return &mClock;};
114
dburgessb3a0ca42011-10-12 07:44:40 +0000115 /** set transmit frequency */
116 bool tuneTx(double freq);
117
118 /** set receive frequency */
119 bool tuneRx(double freq);
120
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000121 /** set receive gain */
122 double setRxGain(double dB);
123
124 /** get receive gain */
125 double getRxGain(void);
126
dburgessb3a0ca42011-10-12 07:44:40 +0000127 /** drive transmission of GSM bursts */
128 void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst);
129
130 /** drive reception of GSM bursts */
131 void driveReceiveRadio();
132
133 void setPowerAttenuation(double atten);
134
135 /** returns the full-scale transmit amplitude **/
136 double fullScaleInputValue();
137
138 /** returns the full-scale receive amplitude **/
139 double fullScaleOutputValue();
140
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000141 /** set thread priority on current thread */
142 void setPriority() { mRadio->setPriority(); }
dburgessb3a0ca42011-10-12 07:44:40 +0000143
Thomas Tsou02d88d12013-04-05 15:36:30 -0400144 /** get transport window type of attached device */
145 enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
kurtis.heimerle380af32011-11-26 03:18:55 +0000146
Thomas Tsouf2293b82013-04-08 13:35:36 -0400147#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000148protected:
149
150 /** drive synchronization of Tx/Rx of USRP */
151 void alignRadio();
152
dburgessb3a0ca42011-10-12 07:44:40 +0000153 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400154#endif
dburgessb3a0ca42011-10-12 07:44:40 +0000155};
156
Thomas Tsouf2293b82013-04-08 13:35:36 -0400157#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000158/** synchronization thread loop */
159void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400160#endif
Thomas Tsoucb69f082013-04-08 14:18:26 -0400161
162class RadioInterfaceResamp : public RadioInterface {
163
164private:
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400165 signalVector *innerSendBuffer;
166 signalVector *outerSendBuffer;
167 signalVector *innerRecvBuffer;
168 signalVector *outerRecvBuffer;
Thomas Tsoucb69f082013-04-08 14:18:26 -0400169
170 void pushBuffer();
171 void pullBuffer();
172
173public:
174
175 RadioInterfaceResamp(RadioDevice* wRadio = NULL,
176 int receiveOffset = 3,
177 int wSPS = SAMPSPERSYM,
178 GSM::Time wStartTime = GSM::Time(0));
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400179
180 ~RadioInterfaceResamp();
181
182 bool init();
183 void close();
Thomas Tsoucb69f082013-04-08 14:18:26 -0400184};