blob: cac20de2294513b024e9ddb1acc01c27c4092d8c [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
dburgessb3a0ca42011-10-12 07:44:40 +000029/** class to interface the transceiver with the USRP */
30class RadioInterface {
31
32private:
33
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
39
kurtis.heimerl9b557832011-11-26 03:18:34 +000040 float *sendBuffer;
dburgessb3a0ca42011-10-12 07:44:40 +000041 unsigned sendCursor;
42
kurtis.heimerl9b557832011-11-26 03:18:34 +000043 float *rcvBuffer;
dburgessb3a0ca42011-10-12 07:44:40 +000044 unsigned rcvCursor;
45
46 bool underrun; ///< indicates writes to USRP are too slow
47 bool overrun; ///< indicates reads from USRP are too slow
48 TIMESTAMP writeTimestamp; ///< sample timestamp of next packet written to USRP
49 TIMESTAMP readTimestamp; ///< sample timestamp of next packet read from USRP
50
51 RadioClock mClock; ///< the basestation clock!
52
53 int samplesPerSymbol; ///< samples per GSM symbol
54 int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
55 int mRadioOversampling;
56 int mTransceiverOversampling;
57
58 bool mOn; ///< indicates radio is on
59
60 double powerScaling;
61
62 bool loadTest;
63 int mNumARFCNs;
64 signalVector *finalVec, *finalVec9;
65
66 /** format samples to USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000067 int radioifyVector(signalVector &wVector,
68 float *floatVector,
69 float scale,
70 bool zero);
dburgessb3a0ca42011-10-12 07:44:40 +000071
72 /** format samples from USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000073 int unRadioifyVector(float *floatVector, signalVector &wVector);
dburgessb3a0ca42011-10-12 07:44:40 +000074
75 /** push GSM bursts into the transmit buffer */
76 void pushBuffer(void);
77
78 /** pull GSM bursts from the receive buffer */
79 void pullBuffer(void);
80
81public:
82
83 /** start the interface */
84 void start();
85
86 /** constructor */
87 RadioInterface(RadioDevice* wRadio = NULL,
88 int receiveOffset = 3,
89 int wRadioOversampling = SAMPSPERSYM,
90 int wTransceiverOversampling = SAMPSPERSYM,
91 GSM::Time wStartTime = GSM::Time(0));
92
93 /** destructor */
94 ~RadioInterface();
95
96 void setSamplesPerSymbol(int wSamplesPerSymbol) {if (!mOn) samplesPerSymbol = wSamplesPerSymbol;}
97
98 int getSamplesPerSymbol() { return samplesPerSymbol;}
99
100 /** check for underrun, resets underrun value */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000101 bool isUnderrun();
dburgessb3a0ca42011-10-12 07:44:40 +0000102
103 /** attach an existing USRP to this interface */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000104 void attach(RadioDevice *wRadio, int wRadioOversampling);
dburgessb3a0ca42011-10-12 07:44:40 +0000105
106 /** return the receive FIFO */
107 VectorFIFO* receiveFIFO() { return &mReceiveFIFO;}
108
109 /** return the basestation clock */
110 RadioClock* getClock(void) { return &mClock;};
111
dburgessb3a0ca42011-10-12 07:44:40 +0000112 /** set transmit frequency */
113 bool tuneTx(double freq);
114
115 /** set receive frequency */
116 bool tuneRx(double freq);
117
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000118 /** set receive gain */
119 double setRxGain(double dB);
120
121 /** get receive gain */
122 double getRxGain(void);
123
dburgessb3a0ca42011-10-12 07:44:40 +0000124 /** drive transmission of GSM bursts */
125 void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst);
126
127 /** drive reception of GSM bursts */
128 void driveReceiveRadio();
129
130 void setPowerAttenuation(double atten);
131
132 /** returns the full-scale transmit amplitude **/
133 double fullScaleInputValue();
134
135 /** returns the full-scale receive amplitude **/
136 double fullScaleOutputValue();
137
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000138 /** set thread priority on current thread */
139 void setPriority() { mRadio->setPriority(); }
dburgessb3a0ca42011-10-12 07:44:40 +0000140
kurtis.heimerle380af32011-11-26 03:18:55 +0000141 /** get transport bus type of attached device */
142 enum RadioDevice::busType getBus() { return mRadio->getBus(); }
143
dburgessb3a0ca42011-10-12 07:44:40 +0000144protected:
145
146 /** drive synchronization of Tx/Rx of USRP */
147 void alignRadio();
148
149 /** reset the interface */
150 void reset();
151
152 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
153
154};
155
156/** synchronization thread loop */
157void *AlignRadioServiceLoopAdapter(RadioInterface*);