blob: 8fb9f2746b1293c09aadfd3332309e6e773370c2 [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
40 short *sendBuffer; //[2*2*INCHUNK];
41 unsigned sendCursor;
42
43 short *rcvBuffer; //[2*2*OUTCHUNK];
44 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.heimerlee5347a2011-11-26 03:18:05 +000067 short *radioifyVector(signalVector &wVector,
68 short *shortVector,
69 float scale,
70 bool zeroOut);
dburgessb3a0ca42011-10-12 07:44:40 +000071
72 /** format samples from USRP */
73 void unRadioifyVector(short *shortVector, signalVector &wVector);
74
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 */
101 bool isUnderrun() { bool retVal = underrun; underrun = false; return retVal;}
102
103 /** attach an existing USRP to this interface */
104 void attach(RadioDevice *wRadio, int wRadioOversampling) {if (!mOn) {mRadio = wRadio; mRadioOversampling = SAMPSPERSYM;} }
105
106 /** return the receive FIFO */
107 VectorFIFO* receiveFIFO() { return &mReceiveFIFO;}
108
109 /** return the basestation clock */
110 RadioClock* getClock(void) { return &mClock;};
111
112 /** set receive gain */
113 double setRxGain(double dB) {if (mRadio) return mRadio->setRxGain(dB); else return -1;}
114
115 /** get receive gain */
116 double getRxGain(void) {if (mRadio) return mRadio->getRxGain(); else return -1;}
117
118
119 /** set transmit frequency */
120 bool tuneTx(double freq);
121
122 /** set receive frequency */
123 bool tuneRx(double freq);
124
125 /** 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
142protected:
143
144 /** drive synchronization of Tx/Rx of USRP */
145 void alignRadio();
146
147 /** reset the interface */
148 void reset();
149
150 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
151
152};
153
154/** synchronization thread loop */
155void *AlignRadioServiceLoopAdapter(RadioInterface*);