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 | |
| 24 | /** samples per GSM symbol */ |
| 25 | #define SAMPSPERSYM 1 |
| 26 | #define INCHUNK (625) |
| 27 | #define OUTCHUNK (625) |
| 28 | |
Alexander Chemeris | d734e2d | 2013-06-16 14:30:58 +0400 | [diff] [blame] | 29 | static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods |
| 30 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 31 | /** class to interface the transceiver with the USRP */ |
| 32 | class RadioInterface { |
| 33 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 34 | protected: |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 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.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 42 | float *sendBuffer; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 43 | unsigned sendCursor; |
| 44 | |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 45 | float *rcvBuffer; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 46 | 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 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 57 | |
| 58 | bool mOn; ///< indicates radio is on |
| 59 | |
| 60 | double powerScaling; |
| 61 | |
| 62 | bool loadTest; |
| 63 | int mNumARFCNs; |
| 64 | signalVector *finalVec, *finalVec9; |
| 65 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 66 | private: |
| 67 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 68 | /** format samples to USRP */ |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 69 | int radioifyVector(signalVector &wVector, |
| 70 | float *floatVector, |
| 71 | float scale, |
| 72 | bool zero); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 73 | |
| 74 | /** format samples from USRP */ |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 75 | int unRadioifyVector(float *floatVector, signalVector &wVector); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 76 | |
| 77 | /** push GSM bursts into the transmit buffer */ |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 78 | virtual void pushBuffer(void); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 79 | |
| 80 | /** pull GSM bursts from the receive buffer */ |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 81 | virtual void pullBuffer(void); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 82 | |
| 83 | public: |
| 84 | |
| 85 | /** start the interface */ |
| 86 | void start(); |
| 87 | |
| 88 | /** constructor */ |
| 89 | RadioInterface(RadioDevice* wRadio = NULL, |
| 90 | int receiveOffset = 3, |
Thomas Tsou | 312e387 | 2013-04-08 13:45:55 -0400 | [diff] [blame] | 91 | int wSPS = SAMPSPERSYM, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 92 | GSM::Time wStartTime = GSM::Time(0)); |
| 93 | |
| 94 | /** destructor */ |
| 95 | ~RadioInterface(); |
| 96 | |
| 97 | void setSamplesPerSymbol(int wSamplesPerSymbol) {if (!mOn) samplesPerSymbol = wSamplesPerSymbol;} |
| 98 | |
| 99 | int getSamplesPerSymbol() { return samplesPerSymbol;} |
| 100 | |
| 101 | /** check for underrun, resets underrun value */ |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 102 | bool isUnderrun(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 103 | |
| 104 | /** attach an existing USRP to this interface */ |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 105 | void attach(RadioDevice *wRadio, int wRadioOversampling); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 106 | |
| 107 | /** return the receive FIFO */ |
| 108 | VectorFIFO* receiveFIFO() { return &mReceiveFIFO;} |
| 109 | |
| 110 | /** return the basestation clock */ |
| 111 | RadioClock* getClock(void) { return &mClock;}; |
| 112 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 113 | /** set transmit frequency */ |
| 114 | bool tuneTx(double freq); |
| 115 | |
| 116 | /** set receive frequency */ |
| 117 | bool tuneRx(double freq); |
| 118 | |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 119 | /** set receive gain */ |
| 120 | double setRxGain(double dB); |
| 121 | |
| 122 | /** get receive gain */ |
| 123 | double getRxGain(void); |
| 124 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 125 | /** drive transmission of GSM bursts */ |
| 126 | void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst); |
| 127 | |
| 128 | /** drive reception of GSM bursts */ |
| 129 | void driveReceiveRadio(); |
| 130 | |
| 131 | void setPowerAttenuation(double atten); |
| 132 | |
| 133 | /** returns the full-scale transmit amplitude **/ |
| 134 | double fullScaleInputValue(); |
| 135 | |
| 136 | /** returns the full-scale receive amplitude **/ |
| 137 | double fullScaleOutputValue(); |
| 138 | |
kurtis.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 139 | /** set thread priority on current thread */ |
| 140 | void setPriority() { mRadio->setPriority(); } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 141 | |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 142 | /** get transport window type of attached device */ |
| 143 | enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); } |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 144 | |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 145 | #if USRP1 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 146 | protected: |
| 147 | |
| 148 | /** drive synchronization of Tx/Rx of USRP */ |
| 149 | void alignRadio(); |
| 150 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 151 | friend void *AlignRadioServiceLoopAdapter(RadioInterface*); |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 152 | #endif |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 155 | #if USRP1 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 156 | /** synchronization thread loop */ |
| 157 | void *AlignRadioServiceLoopAdapter(RadioInterface*); |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 158 | #endif |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 159 | |
| 160 | class RadioInterfaceResamp : public RadioInterface { |
| 161 | |
| 162 | private: |
| 163 | |
| 164 | void pushBuffer(); |
| 165 | void pullBuffer(); |
| 166 | |
| 167 | public: |
| 168 | |
| 169 | RadioInterfaceResamp(RadioDevice* wRadio = NULL, |
| 170 | int receiveOffset = 3, |
| 171 | int wSPS = SAMPSPERSYM, |
| 172 | GSM::Time wStartTime = GSM::Time(0)); |
| 173 | }; |