dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 1 | /* |
| 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.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 21 | #include "radioVector.h" |
| 22 | #include "radioClock.h" |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 23 | |
Alexander Chemeris | d734e2d | 2013-06-16 14:30:58 +0400 | [diff] [blame] | 24 | static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods |
| 25 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 26 | /** class to interface the transceiver with the USRP */ |
| 27 | class RadioInterface { |
| 28 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 29 | protected: |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 30 | |
| 31 | Thread mAlignRadioServiceLoopThread; ///< thread that synchronizes transmit and receive sections |
| 32 | |
| 33 | VectorFIFO mReceiveFIFO; ///< FIFO that holds receive bursts |
| 34 | |
| 35 | RadioDevice *mRadio; ///< the USRP object |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 36 | |
| 37 | int mSPSTx; |
| 38 | int mSPSRx; |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 39 | signalVector *sendBuffer; |
| 40 | signalVector *recvBuffer; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 41 | unsigned sendCursor; |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 42 | unsigned recvCursor; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 43 | |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 44 | short *convertRecvBuffer; |
| 45 | short *convertSendBuffer; |
| 46 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 47 | bool underrun; ///< indicates writes to USRP are too slow |
| 48 | bool overrun; ///< indicates reads from USRP are too slow |
| 49 | TIMESTAMP writeTimestamp; ///< sample timestamp of next packet written to USRP |
| 50 | TIMESTAMP readTimestamp; ///< sample timestamp of next packet read from USRP |
| 51 | |
| 52 | RadioClock mClock; ///< the basestation clock! |
| 53 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 54 | int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 55 | |
| 56 | bool mOn; ///< indicates radio is on |
| 57 | |
| 58 | double powerScaling; |
| 59 | |
| 60 | bool loadTest; |
| 61 | int mNumARFCNs; |
| 62 | signalVector *finalVec, *finalVec9; |
| 63 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 64 | private: |
| 65 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 66 | /** format samples to USRP */ |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 67 | int radioifyVector(signalVector &wVector, |
| 68 | float *floatVector, |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 69 | bool zero); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 70 | |
| 71 | /** format samples from USRP */ |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 72 | int unRadioifyVector(float *floatVector, signalVector &wVector); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 73 | |
| 74 | /** push GSM bursts into the transmit buffer */ |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 75 | virtual void pushBuffer(void); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 76 | |
| 77 | /** pull GSM bursts from the receive buffer */ |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 78 | virtual void pullBuffer(void); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 79 | |
| 80 | public: |
| 81 | |
| 82 | /** start the interface */ |
| 83 | void start(); |
| 84 | |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 85 | /** intialization */ |
Thomas Tsou | fe269fe | 2013-10-14 23:56:51 -0400 | [diff] [blame] | 86 | virtual bool init(int type); |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 87 | virtual void close(); |
| 88 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 89 | /** constructor */ |
| 90 | RadioInterface(RadioDevice* wRadio = NULL, |
| 91 | int receiveOffset = 3, |
Thomas Tsou | fe269fe | 2013-10-14 23:56:51 -0400 | [diff] [blame] | 92 | int wSPS = 4, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 93 | GSM::Time wStartTime = GSM::Time(0)); |
| 94 | |
| 95 | /** destructor */ |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 96 | virtual ~RadioInterface(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 97 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 98 | /** check for underrun, resets underrun value */ |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 99 | bool isUnderrun(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 100 | |
| 101 | /** attach an existing USRP to this interface */ |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 102 | void attach(RadioDevice *wRadio, int wRadioOversampling); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 103 | |
| 104 | /** return the receive FIFO */ |
| 105 | VectorFIFO* receiveFIFO() { return &mReceiveFIFO;} |
| 106 | |
| 107 | /** return the basestation clock */ |
| 108 | RadioClock* getClock(void) { return &mClock;}; |
| 109 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 110 | /** set transmit frequency */ |
| 111 | bool tuneTx(double freq); |
| 112 | |
| 113 | /** set receive frequency */ |
| 114 | bool tuneRx(double freq); |
| 115 | |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 116 | /** set receive gain */ |
| 117 | double setRxGain(double dB); |
| 118 | |
| 119 | /** get receive gain */ |
| 120 | double getRxGain(void); |
| 121 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 122 | /** drive transmission of GSM bursts */ |
| 123 | void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst); |
| 124 | |
| 125 | /** drive reception of GSM bursts */ |
| 126 | void driveReceiveRadio(); |
| 127 | |
| 128 | void setPowerAttenuation(double atten); |
| 129 | |
| 130 | /** returns the full-scale transmit amplitude **/ |
| 131 | double fullScaleInputValue(); |
| 132 | |
| 133 | /** returns the full-scale receive amplitude **/ |
| 134 | double fullScaleOutputValue(); |
| 135 | |
kurtis.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 136 | /** set thread priority on current thread */ |
| 137 | void setPriority() { mRadio->setPriority(); } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 138 | |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 139 | /** get transport window type of attached device */ |
| 140 | enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); } |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 141 | |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 142 | #if USRP1 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 143 | protected: |
| 144 | |
| 145 | /** drive synchronization of Tx/Rx of USRP */ |
| 146 | void alignRadio(); |
| 147 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 148 | friend void *AlignRadioServiceLoopAdapter(RadioInterface*); |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 149 | #endif |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 152 | #if USRP1 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 153 | /** synchronization thread loop */ |
| 154 | void *AlignRadioServiceLoopAdapter(RadioInterface*); |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 155 | #endif |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 156 | |
| 157 | class RadioInterfaceResamp : public RadioInterface { |
| 158 | |
| 159 | private: |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 160 | signalVector *innerSendBuffer; |
| 161 | signalVector *outerSendBuffer; |
| 162 | signalVector *innerRecvBuffer; |
| 163 | signalVector *outerRecvBuffer; |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 164 | |
| 165 | void pushBuffer(); |
| 166 | void pullBuffer(); |
| 167 | |
| 168 | public: |
| 169 | |
| 170 | RadioInterfaceResamp(RadioDevice* wRadio = NULL, |
| 171 | int receiveOffset = 3, |
Thomas Tsou | fe269fe | 2013-10-14 23:56:51 -0400 | [diff] [blame] | 172 | int wSPS = 4, |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 173 | GSM::Time wStartTime = GSM::Time(0)); |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 174 | |
| 175 | ~RadioInterfaceResamp(); |
| 176 | |
Thomas Tsou | fe269fe | 2013-10-14 23:56:51 -0400 | [diff] [blame] | 177 | bool init(int type); |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 178 | void close(); |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 179 | }; |