blob: 216cf3ececacb43d6e9655fe1f1cb63eb427427c [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
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
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,
Thomas Tsou312e3872013-04-08 13:45:55 -040089 int wSPS = SAMPSPERSYM,
dburgessb3a0ca42011-10-12 07:44:40 +000090 GSM::Time wStartTime = GSM::Time(0));
91
92 /** destructor */
93 ~RadioInterface();
94
95 void setSamplesPerSymbol(int wSamplesPerSymbol) {if (!mOn) samplesPerSymbol = wSamplesPerSymbol;}
96
97 int getSamplesPerSymbol() { return samplesPerSymbol;}
98
99 /** check for underrun, resets underrun value */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000100 bool isUnderrun();
dburgessb3a0ca42011-10-12 07:44:40 +0000101
102 /** attach an existing USRP to this interface */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000103 void attach(RadioDevice *wRadio, int wRadioOversampling);
dburgessb3a0ca42011-10-12 07:44:40 +0000104
105 /** return the receive FIFO */
106 VectorFIFO* receiveFIFO() { return &mReceiveFIFO;}
107
108 /** return the basestation clock */
109 RadioClock* getClock(void) { return &mClock;};
110
dburgessb3a0ca42011-10-12 07:44:40 +0000111 /** set transmit frequency */
112 bool tuneTx(double freq);
113
114 /** set receive frequency */
115 bool tuneRx(double freq);
116
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000117 /** set receive gain */
118 double setRxGain(double dB);
119
120 /** get receive gain */
121 double getRxGain(void);
122
dburgessb3a0ca42011-10-12 07:44:40 +0000123 /** drive transmission of GSM bursts */
124 void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst);
125
126 /** drive reception of GSM bursts */
127 void driveReceiveRadio();
128
129 void setPowerAttenuation(double atten);
130
131 /** returns the full-scale transmit amplitude **/
132 double fullScaleInputValue();
133
134 /** returns the full-scale receive amplitude **/
135 double fullScaleOutputValue();
136
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000137 /** set thread priority on current thread */
138 void setPriority() { mRadio->setPriority(); }
dburgessb3a0ca42011-10-12 07:44:40 +0000139
Thomas Tsou02d88d12013-04-05 15:36:30 -0400140 /** get transport window type of attached device */
141 enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
kurtis.heimerle380af32011-11-26 03:18:55 +0000142
Thomas Tsouf2293b82013-04-08 13:35:36 -0400143#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000144protected:
145
146 /** drive synchronization of Tx/Rx of USRP */
147 void alignRadio();
148
dburgessb3a0ca42011-10-12 07:44:40 +0000149 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400150#endif
dburgessb3a0ca42011-10-12 07:44:40 +0000151};
152
Thomas Tsouf2293b82013-04-08 13:35:36 -0400153#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000154/** synchronization thread loop */
155void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400156#endif