blob: a64702be4fcec0688b9a28c061b54933c966b6ed [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
kurtis.heimerl9b557832011-11-26 03:18:34 +000042 float *sendBuffer;
dburgessb3a0ca42011-10-12 07:44:40 +000043 unsigned sendCursor;
44
kurtis.heimerl9b557832011-11-26 03:18:34 +000045 float *rcvBuffer;
dburgessb3a0ca42011-10-12 07:44:40 +000046 unsigned rcvCursor;
47
48 bool underrun; ///< indicates writes to USRP are too slow
49 bool overrun; ///< indicates reads from USRP are too slow
50 TIMESTAMP writeTimestamp; ///< sample timestamp of next packet written to USRP
51 TIMESTAMP readTimestamp; ///< sample timestamp of next packet read from USRP
52
53 RadioClock mClock; ///< the basestation clock!
54
Thomas Tsoud24cc2c2013-08-20 15:41:45 -040055 int sps; ///< samples per GSM symbol
dburgessb3a0ca42011-10-12 07:44:40 +000056 int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
dburgessb3a0ca42011-10-12 07:44:40 +000057
58 bool mOn; ///< indicates radio is on
59
60 double powerScaling;
61
62 bool loadTest;
63 int mNumARFCNs;
64 signalVector *finalVec, *finalVec9;
65
Thomas Tsoucb69f082013-04-08 14:18:26 -040066private:
67
dburgessb3a0ca42011-10-12 07:44:40 +000068 /** format samples to USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000069 int radioifyVector(signalVector &wVector,
70 float *floatVector,
71 float scale,
72 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
88 /** constructor */
89 RadioInterface(RadioDevice* wRadio = NULL,
90 int receiveOffset = 3,
Thomas Tsou312e3872013-04-08 13:45:55 -040091 int wSPS = SAMPSPERSYM,
dburgessb3a0ca42011-10-12 07:44:40 +000092 GSM::Time wStartTime = GSM::Time(0));
93
94 /** destructor */
95 ~RadioInterface();
96
dburgessb3a0ca42011-10-12 07:44:40 +000097 /** check for underrun, resets underrun value */
kurtis.heimerle724d6d2011-11-26 03:18:46 +000098 bool isUnderrun();
dburgessb3a0ca42011-10-12 07:44:40 +000099
100 /** attach an existing USRP to this interface */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000101 void attach(RadioDevice *wRadio, int wRadioOversampling);
dburgessb3a0ca42011-10-12 07:44:40 +0000102
103 /** return the receive FIFO */
104 VectorFIFO* receiveFIFO() { return &mReceiveFIFO;}
105
106 /** return the basestation clock */
107 RadioClock* getClock(void) { return &mClock;};
108
dburgessb3a0ca42011-10-12 07:44:40 +0000109 /** set transmit frequency */
110 bool tuneTx(double freq);
111
112 /** set receive frequency */
113 bool tuneRx(double freq);
114
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000115 /** set receive gain */
116 double setRxGain(double dB);
117
118 /** get receive gain */
119 double getRxGain(void);
120
dburgessb3a0ca42011-10-12 07:44:40 +0000121 /** drive transmission of GSM bursts */
122 void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst);
123
124 /** drive reception of GSM bursts */
125 void driveReceiveRadio();
126
127 void setPowerAttenuation(double atten);
128
129 /** returns the full-scale transmit amplitude **/
130 double fullScaleInputValue();
131
132 /** returns the full-scale receive amplitude **/
133 double fullScaleOutputValue();
134
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000135 /** set thread priority on current thread */
136 void setPriority() { mRadio->setPriority(); }
dburgessb3a0ca42011-10-12 07:44:40 +0000137
Thomas Tsou02d88d12013-04-05 15:36:30 -0400138 /** get transport window type of attached device */
139 enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
kurtis.heimerle380af32011-11-26 03:18:55 +0000140
Thomas Tsouf2293b82013-04-08 13:35:36 -0400141#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000142protected:
143
144 /** drive synchronization of Tx/Rx of USRP */
145 void alignRadio();
146
dburgessb3a0ca42011-10-12 07:44:40 +0000147 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400148#endif
dburgessb3a0ca42011-10-12 07:44:40 +0000149};
150
Thomas Tsouf2293b82013-04-08 13:35:36 -0400151#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000152/** synchronization thread loop */
153void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400154#endif
Thomas Tsoucb69f082013-04-08 14:18:26 -0400155
156class RadioInterfaceResamp : public RadioInterface {
157
158private:
159
160 void pushBuffer();
161 void pullBuffer();
162
163public:
164
165 RadioInterfaceResamp(RadioDevice* wRadio = NULL,
166 int receiveOffset = 3,
167 int wSPS = SAMPSPERSYM,
168 GSM::Time wStartTime = GSM::Time(0));
169};