blob: 1e58ecb90b427d1adc7d93bc50f34f395e2e63c1 [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
Alexander Chemerisd734e2d2013-06-16 14:30:58 +040024static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods
25
dburgessb3a0ca42011-10-12 07:44:40 +000026/** class to interface the transceiver with the USRP */
27class RadioInterface {
28
Thomas Tsoucb69f082013-04-08 14:18:26 -040029protected:
dburgessb3a0ca42011-10-12 07:44:40 +000030
31 Thread mAlignRadioServiceLoopThread; ///< thread that synchronizes transmit and receive sections
32
Thomas Tsou204a9f12013-10-29 18:34:16 -040033 std::vector<VectorFIFO> mReceiveFIFO; ///< FIFO that holds receive bursts
dburgessb3a0ca42011-10-12 07:44:40 +000034
35 RadioDevice *mRadio; ///< the USRP object
Thomas Tsouc1f7c422013-10-11 13:49:55 -040036
Thomas Tsou204a9f12013-10-29 18:34:16 -040037 size_t mSPSTx;
38 size_t mSPSRx;
39 size_t mChans;
40 std::vector<signalVector *> sendBuffer;
41 std::vector<signalVector *> recvBuffer;
dburgessb3a0ca42011-10-12 07:44:40 +000042 unsigned sendCursor;
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040043 unsigned recvCursor;
dburgessb3a0ca42011-10-12 07:44:40 +000044
Thomas Tsou204a9f12013-10-29 18:34:16 -040045 std::vector<short *> convertRecvBuffer;
46 std::vector<short *> convertSendBuffer;
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040047
dburgessb3a0ca42011-10-12 07:44:40 +000048 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
dburgessb3a0ca42011-10-12 07:44:40 +000055 int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
dburgessb3a0ca42011-10-12 07:44:40 +000056
57 bool mOn; ///< indicates radio is on
58
59 double powerScaling;
60
61 bool loadTest;
62 int mNumARFCNs;
63 signalVector *finalVec, *finalVec9;
64
Thomas Tsoucb69f082013-04-08 14:18:26 -040065private:
66
dburgessb3a0ca42011-10-12 07:44:40 +000067 /** format samples to USRP */
kurtis.heimerl9b557832011-11-26 03:18:34 +000068 int radioifyVector(signalVector &wVector,
69 float *floatVector,
kurtis.heimerl9b557832011-11-26 03:18:34 +000070 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 */
Thomas Tsoucb69f082013-04-08 14:18:26 -040076 virtual void pushBuffer(void);
dburgessb3a0ca42011-10-12 07:44:40 +000077
78 /** pull GSM bursts from the receive buffer */
Thomas Tsoucb69f082013-04-08 14:18:26 -040079 virtual void pullBuffer(void);
dburgessb3a0ca42011-10-12 07:44:40 +000080
81public:
82
83 /** start the interface */
84 void start();
85
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040086 /** intialization */
Thomas Tsoufe269fe2013-10-14 23:56:51 -040087 virtual bool init(int type);
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040088 virtual void close();
89
dburgessb3a0ca42011-10-12 07:44:40 +000090 /** constructor */
91 RadioInterface(RadioDevice* wRadio = NULL,
92 int receiveOffset = 3,
Thomas Tsou204a9f12013-10-29 18:34:16 -040093 size_t sps = 4, size_t chans = 1,
dburgessb3a0ca42011-10-12 07:44:40 +000094 GSM::Time wStartTime = GSM::Time(0));
Thomas Tsou204a9f12013-10-29 18:34:16 -040095
dburgessb3a0ca42011-10-12 07:44:40 +000096 /** destructor */
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040097 virtual ~RadioInterface();
dburgessb3a0ca42011-10-12 07:44:40 +000098
dburgessb3a0ca42011-10-12 07:44:40 +000099 /** check for underrun, resets underrun value */
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000100 bool isUnderrun();
dburgessb3a0ca42011-10-12 07:44:40 +0000101
102 /** return the receive FIFO */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400103 VectorFIFO* receiveFIFO(size_t chan = 0);
dburgessb3a0ca42011-10-12 07:44:40 +0000104
105 /** return the basestation clock */
106 RadioClock* getClock(void) { return &mClock;};
107
dburgessb3a0ca42011-10-12 07:44:40 +0000108 /** set transmit frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400109 bool tuneTx(double freq, size_t chan = 0);
dburgessb3a0ca42011-10-12 07:44:40 +0000110
111 /** set receive frequency */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400112 bool tuneRx(double freq, size_t chan = 0);
dburgessb3a0ca42011-10-12 07:44:40 +0000113
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000114 /** set receive gain */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400115 double setRxGain(double dB, size_t chan = 0);
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000116
117 /** get receive gain */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400118 double getRxGain(size_t chan = 0);
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000119
dburgessb3a0ca42011-10-12 07:44:40 +0000120 /** drive transmission of GSM bursts */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400121 void driveTransmitRadio(std::vector<signalVector *> &bursts,
122 std::vector<bool> &zeros);
dburgessb3a0ca42011-10-12 07:44:40 +0000123
124 /** drive reception of GSM bursts */
Thomas Tsou204a9f12013-10-29 18:34:16 -0400125 bool driveReceiveRadio();
dburgessb3a0ca42011-10-12 07:44:40 +0000126
Thomas Tsou204a9f12013-10-29 18:34:16 -0400127 void setPowerAttenuation(double atten, size_t chan = 0);
dburgessb3a0ca42011-10-12 07:44:40 +0000128
129 /** returns the full-scale transmit amplitude **/
130 double fullScaleInputValue();
131
132 /** returns the full-scale receive amplitude **/
133 double fullScaleOutputValue();
134
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000135 /** set thread priority on current thread */
136 void setPriority() { mRadio->setPriority(); }
dburgessb3a0ca42011-10-12 07:44:40 +0000137
Thomas Tsou02d88d12013-04-05 15:36:30 -0400138 /** get transport window type of attached device */
139 enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
kurtis.heimerle380af32011-11-26 03:18:55 +0000140
Thomas Tsouf2293b82013-04-08 13:35:36 -0400141#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000142protected:
143
144 /** drive synchronization of Tx/Rx of USRP */
145 void alignRadio();
146
dburgessb3a0ca42011-10-12 07:44:40 +0000147 friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400148#endif
dburgessb3a0ca42011-10-12 07:44:40 +0000149};
150
Thomas Tsouf2293b82013-04-08 13:35:36 -0400151#if USRP1
dburgessb3a0ca42011-10-12 07:44:40 +0000152/** synchronization thread loop */
153void *AlignRadioServiceLoopAdapter(RadioInterface*);
Thomas Tsouf2293b82013-04-08 13:35:36 -0400154#endif
Thomas Tsoucb69f082013-04-08 14:18:26 -0400155
156class RadioInterfaceResamp : public RadioInterface {
157
158private:
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400159 signalVector *innerSendBuffer;
160 signalVector *outerSendBuffer;
161 signalVector *innerRecvBuffer;
162 signalVector *outerRecvBuffer;
Thomas Tsoucb69f082013-04-08 14:18:26 -0400163
164 void pushBuffer();
165 void pullBuffer();
166
167public:
168
169 RadioInterfaceResamp(RadioDevice* wRadio = NULL,
170 int receiveOffset = 3,
Thomas Tsou204a9f12013-10-29 18:34:16 -0400171 size_t wSPS = 4, size_t chans = 1,
Thomas Tsoucb69f082013-04-08 14:18:26 -0400172 GSM::Time wStartTime = GSM::Time(0));
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400173
174 ~RadioInterfaceResamp();
175
Thomas Tsoufe269fe2013-10-14 23:56:51 -0400176 bool init(int type);
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400177 void close();
Thomas Tsoucb69f082013-04-08 14:18:26 -0400178};