blob: 98d0f9d22c0055d4d0fa133cc26efb737ccb5325 [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 */
Thomas Tsoua57bc8a2013-09-05 08:16:47 +080025#define SAMPSPERSYM 4
dburgessb3a0ca42011-10-12 07:44:40 +000026
Alexander Chemerisd734e2d2013-06-16 14:30:58 +040027static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods
28
dburgessb3a0ca42011-10-12 07:44:40 +000029/** class to interface the transceiver with the USRP */
30class RadioInterface {
31
Thomas Tsoucb69f082013-04-08 14:18:26 -040032protected:
dburgessb3a0ca42011-10-12 07:44:40 +000033
34 Thread mAlignRadioServiceLoopThread; ///< thread that synchronizes transmit and receive sections
35
36 VectorFIFO mReceiveFIFO; ///< FIFO that holds receive bursts
37
38 RadioDevice *mRadio; ///< the USRP object
Thomas Tsouc1f7c422013-10-11 13:49:55 -040039
40 int mSPSTx;
41 int mSPSRx;
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
dburgessb3a0ca42011-10-12 07:44:40 +000057 int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
dburgessb3a0ca42011-10-12 07:44:40 +000058
59 bool mOn; ///< indicates radio is on
60
61 double powerScaling;
62
63 bool loadTest;
64 int mNumARFCNs;
65 signalVector *finalVec, *finalVec9;
66
Thomas Tsoucb69f082013-04-08 14:18:26 -040067private:
68
dburgessb3a0ca42011-10-12 07:44:40 +000069 /** format samples to USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000070 int radioifyVector(signalVector &wVector,
71 float *floatVector,
kurtis.heimerl9b557832011-11-26 03:18:34 +000072 bool zero);
dburgessb3a0ca42011-10-12 07:44:40 +000073
74 /** format samples from USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000075 int unRadioifyVector(float *floatVector, signalVector &wVector);
dburgessb3a0ca42011-10-12 07:44:40 +000076
77 /** push GSM bursts into the transmit buffer */
Thomas Tsoucb69f082013-04-08 14:18:26 -040078 virtual void pushBuffer(void);
dburgessb3a0ca42011-10-12 07:44:40 +000079
80 /** pull GSM bursts from the receive buffer */
Thomas Tsoucb69f082013-04-08 14:18:26 -040081 virtual void pullBuffer(void);
dburgessb3a0ca42011-10-12 07:44:40 +000082
83public:
84
85 /** start the interface */
86 void start();
87
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040088 /** intialization */
89 virtual bool init();
90 virtual void close();
91
dburgessb3a0ca42011-10-12 07:44:40 +000092 /** constructor */
93 RadioInterface(RadioDevice* wRadio = NULL,
94 int receiveOffset = 3,
Thomas Tsou312e3872013-04-08 13:45:55 -040095 int wSPS = SAMPSPERSYM,
dburgessb3a0ca42011-10-12 07:44:40 +000096 GSM::Time wStartTime = GSM::Time(0));
97
98 /** destructor */
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040099 virtual ~RadioInterface();
dburgessb3a0ca42011-10-12 07:44:40 +0000100
dburgessb3a0ca42011-10-12 07:44:40 +0000101 /** check for underrun, resets underrun value */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000102 bool isUnderrun();
dburgessb3a0ca42011-10-12 07:44:40 +0000103
104 /** attach an existing USRP to this interface */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000105 void attach(RadioDevice *wRadio, int wRadioOversampling);
dburgessb3a0ca42011-10-12 07:44:40 +0000106
107 /** return the receive FIFO */
108 VectorFIFO* receiveFIFO() { return &mReceiveFIFO;}
109
110 /** return the basestation clock */
111 RadioClock* getClock(void) { return &mClock;};
112
dburgessb3a0ca42011-10-12 07:44:40 +0000113 /** set transmit frequency */
114 bool tuneTx(double freq);
115
116 /** set receive frequency */
117 bool tuneRx(double freq);
118
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000119 /** set receive gain */
120 double setRxGain(double dB);
121
122 /** get receive gain */
123 double getRxGain(void);
124
dburgessb3a0ca42011-10-12 07:44:40 +0000125 /** drive transmission of GSM bursts */
126 void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst);
127
128 /** drive reception of GSM bursts */
129 void driveReceiveRadio();
130
131 void setPowerAttenuation(double atten);
132
133 /** returns the full-scale transmit amplitude **/
134 double fullScaleInputValue();
135
136 /** returns the full-scale receive amplitude **/
137 double fullScaleOutputValue();
138
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000139 /** set thread priority on current thread */
140 void setPriority() { mRadio->setPriority(); }
dburgessb3a0ca42011-10-12 07:44:40 +0000141
Thomas Tsou02d88d12013-04-05 15:36:30 -0400142 /** get transport window type of attached device */
143 enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
kurtis.heimerle380af32011-11-26 03:18:55 +0000144
Thomas Tsouf2293b82013-04-08 13:35:36 -0400145#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000146protected:
147
148 /** drive synchronization of Tx/Rx of USRP */
149 void alignRadio();
150
dburgessb3a0ca42011-10-12 07:44:40 +0000151 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400152#endif
dburgessb3a0ca42011-10-12 07:44:40 +0000153};
154
Thomas Tsouf2293b82013-04-08 13:35:36 -0400155#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000156/** synchronization thread loop */
157void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400158#endif
Thomas Tsoucb69f082013-04-08 14:18:26 -0400159
160class RadioInterfaceResamp : public RadioInterface {
161
162private:
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400163 signalVector *innerSendBuffer;
164 signalVector *outerSendBuffer;
165 signalVector *innerRecvBuffer;
166 signalVector *outerRecvBuffer;
Thomas Tsoucb69f082013-04-08 14:18:26 -0400167
168 void pushBuffer();
169 void pullBuffer();
170
171public:
172
173 RadioInterfaceResamp(RadioDevice* wRadio = NULL,
174 int receiveOffset = 3,
175 int wSPS = SAMPSPERSYM,
176 GSM::Time wStartTime = GSM::Time(0));
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400177
178 ~RadioInterfaceResamp();
179
180 bool init();
181 void close();
Thomas Tsoucb69f082013-04-08 14:18:26 -0400182};