blob: a590c326ad99fae656f34c848fd906ed17f181b7 [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
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
Thomas Tsoud24cc2c2013-08-20 15:41:45 -040057 int sps; ///< samples per GSM symbol
dburgessb3a0ca42011-10-12 07:44:40 +000058 int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
dburgessb3a0ca42011-10-12 07:44:40 +000059
60 bool mOn; ///< indicates radio is on
61
62 double powerScaling;
63
64 bool loadTest;
65 int mNumARFCNs;
66 signalVector *finalVec, *finalVec9;
67
Thomas Tsoucb69f082013-04-08 14:18:26 -040068private:
69
dburgessb3a0ca42011-10-12 07:44:40 +000070 /** format samples to USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000071 int radioifyVector(signalVector &wVector,
72 float *floatVector,
kurtis.heimerl9b557832011-11-26 03:18:34 +000073 bool zero);
dburgessb3a0ca42011-10-12 07:44:40 +000074
75 /** format samples from USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000076 int unRadioifyVector(float *floatVector, signalVector &wVector);
dburgessb3a0ca42011-10-12 07:44:40 +000077
78 /** push GSM bursts into the transmit buffer */
Thomas Tsoucb69f082013-04-08 14:18:26 -040079 virtual void pushBuffer(void);
dburgessb3a0ca42011-10-12 07:44:40 +000080
81 /** pull GSM bursts from the receive buffer */
Thomas Tsoucb69f082013-04-08 14:18:26 -040082 virtual void pullBuffer(void);
dburgessb3a0ca42011-10-12 07:44:40 +000083
84public:
85
86 /** start the interface */
87 void start();
88
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040089 /** intialization */
90 virtual bool init();
91 virtual void close();
92
dburgessb3a0ca42011-10-12 07:44:40 +000093 /** constructor */
94 RadioInterface(RadioDevice* wRadio = NULL,
95 int receiveOffset = 3,
Thomas Tsou312e3872013-04-08 13:45:55 -040096 int wSPS = SAMPSPERSYM,
dburgessb3a0ca42011-10-12 07:44:40 +000097 GSM::Time wStartTime = GSM::Time(0));
98
99 /** destructor */
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400100 virtual ~RadioInterface();
dburgessb3a0ca42011-10-12 07:44:40 +0000101
dburgessb3a0ca42011-10-12 07:44:40 +0000102 /** 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
Thomas Tsouf2293b82013-04-08 13:35:36 -0400146#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000147protected:
148
149 /** drive synchronization of Tx/Rx of USRP */
150 void alignRadio();
151
dburgessb3a0ca42011-10-12 07:44:40 +0000152 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400153#endif
dburgessb3a0ca42011-10-12 07:44:40 +0000154};
155
Thomas Tsouf2293b82013-04-08 13:35:36 -0400156#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000157/** synchronization thread loop */
158void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400159#endif
Thomas Tsoucb69f082013-04-08 14:18:26 -0400160
161class RadioInterfaceResamp : public RadioInterface {
162
163private:
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400164 signalVector *innerSendBuffer;
165 signalVector *outerSendBuffer;
166 signalVector *innerRecvBuffer;
167 signalVector *outerRecvBuffer;
Thomas Tsoucb69f082013-04-08 14:18:26 -0400168
169 void pushBuffer();
170 void pullBuffer();
171
172public:
173
174 RadioInterfaceResamp(RadioDevice* wRadio = NULL,
175 int receiveOffset = 3,
176 int wSPS = SAMPSPERSYM,
177 GSM::Time wStartTime = GSM::Time(0));
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400178
179 ~RadioInterfaceResamp();
180
181 bool init();
182 void close();
Thomas Tsoucb69f082013-04-08 14:18:26 -0400183};