blob: 3c58222f49e9693608c87862dd111249cc02ebcc [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
34private:
35
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
55 int samplesPerSymbol; ///< samples per GSM symbol
56 int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
57 int mRadioOversampling;
58 int mTransceiverOversampling;
59
60 bool mOn; ///< indicates radio is on
61
62 double powerScaling;
63
64 bool loadTest;
65 int mNumARFCNs;
66 signalVector *finalVec, *finalVec9;
67
68 /** 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 */
78 void pushBuffer(void);
79
80 /** pull GSM bursts from the receive buffer */
81 void pullBuffer(void);
82
83public:
84
85 /** start the interface */
86 void start();
87
88 /** constructor */
89 RadioInterface(RadioDevice* wRadio = NULL,
90 int receiveOffset = 3,
91 int wRadioOversampling = SAMPSPERSYM,
92 int wTransceiverOversampling = SAMPSPERSYM,
93 GSM::Time wStartTime = GSM::Time(0));
94
95 /** destructor */
96 ~RadioInterface();
97
98 void setSamplesPerSymbol(int wSamplesPerSymbol) {if (!mOn) samplesPerSymbol = wSamplesPerSymbol;}
99
100 int getSamplesPerSymbol() { return samplesPerSymbol;}
101
102 /** check for underrun, resets underrun value */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000103 bool isUnderrun();
dburgessb3a0ca42011-10-12 07:44:40 +0000104
105 /** attach an existing USRP to this interface */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000106 void attach(RadioDevice *wRadio, int wRadioOversampling);
dburgessb3a0ca42011-10-12 07:44:40 +0000107
108 /** return the receive FIFO */
109 VectorFIFO* receiveFIFO() { return &mReceiveFIFO;}
110
111 /** return the basestation clock */
112 RadioClock* getClock(void) { return &mClock;};
113
dburgessb3a0ca42011-10-12 07:44:40 +0000114 /** set transmit frequency */
115 bool tuneTx(double freq);
116
117 /** set receive frequency */
118 bool tuneRx(double freq);
119
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000120 /** set receive gain */
121 double setRxGain(double dB);
122
123 /** get receive gain */
124 double getRxGain(void);
125
dburgessb3a0ca42011-10-12 07:44:40 +0000126 /** drive transmission of GSM bursts */
127 void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst);
128
129 /** drive reception of GSM bursts */
130 void driveReceiveRadio();
131
132 void setPowerAttenuation(double atten);
133
134 /** returns the full-scale transmit amplitude **/
135 double fullScaleInputValue();
136
137 /** returns the full-scale receive amplitude **/
138 double fullScaleOutputValue();
139
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000140 /** set thread priority on current thread */
141 void setPriority() { mRadio->setPriority(); }
dburgessb3a0ca42011-10-12 07:44:40 +0000142
Thomas Tsou02d88d12013-04-05 15:36:30 -0400143 /** get transport window type of attached device */
144 enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
kurtis.heimerle380af32011-11-26 03:18:55 +0000145
dburgessb3a0ca42011-10-12 07:44:40 +0000146protected:
147
148 /** drive synchronization of Tx/Rx of USRP */
149 void alignRadio();
150
151 /** reset the interface */
152 void reset();
153
154 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
155
156};
157
158/** synchronization thread loop */
159void *AlignRadioServiceLoopAdapter(RadioInterface*);