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 | |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 42 | signalVector *sendBuffer; |
| 43 | signalVector *recvBuffer; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 44 | unsigned sendCursor; |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 45 | unsigned recvCursor; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 46 | |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 47 | short *convertRecvBuffer; |
| 48 | short *convertSendBuffer; |
| 49 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 50 | 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 Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 57 | int sps; ///< samples per GSM symbol |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 58 | int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 59 | |
| 60 | bool mOn; ///< indicates radio is on |
| 61 | |
| 62 | double powerScaling; |
| 63 | |
| 64 | bool loadTest; |
| 65 | int mNumARFCNs; |
| 66 | signalVector *finalVec, *finalVec9; |
| 67 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 68 | private: |
| 69 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 70 | /** format samples to USRP */ |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 71 | int radioifyVector(signalVector &wVector, |
| 72 | float *floatVector, |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 73 | bool zero); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 74 | |
| 75 | /** format samples from USRP */ |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 76 | int unRadioifyVector(float *floatVector, signalVector &wVector); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 77 | |
| 78 | /** push GSM bursts into the transmit buffer */ |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 79 | virtual void pushBuffer(void); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 80 | |
| 81 | /** pull GSM bursts from the receive buffer */ |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 82 | virtual void pullBuffer(void); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 83 | |
| 84 | public: |
| 85 | |
| 86 | /** start the interface */ |
| 87 | void start(); |
| 88 | |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 89 | /** intialization */ |
| 90 | virtual bool init(); |
| 91 | virtual void close(); |
| 92 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 93 | /** constructor */ |
| 94 | RadioInterface(RadioDevice* wRadio = NULL, |
| 95 | int receiveOffset = 3, |
Thomas Tsou | 312e387 | 2013-04-08 13:45:55 -0400 | [diff] [blame] | 96 | int wSPS = SAMPSPERSYM, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 97 | GSM::Time wStartTime = GSM::Time(0)); |
| 98 | |
| 99 | /** destructor */ |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 100 | virtual ~RadioInterface(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 101 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 102 | /** check for underrun, resets underrun value */ |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 103 | bool isUnderrun(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 104 | |
| 105 | /** attach an existing USRP to this interface */ |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 106 | void attach(RadioDevice *wRadio, int wRadioOversampling); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 107 | |
| 108 | /** return the receive FIFO */ |
| 109 | VectorFIFO* receiveFIFO() { return &mReceiveFIFO;} |
| 110 | |
| 111 | /** return the basestation clock */ |
| 112 | RadioClock* getClock(void) { return &mClock;}; |
| 113 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 114 | /** set transmit frequency */ |
| 115 | bool tuneTx(double freq); |
| 116 | |
| 117 | /** set receive frequency */ |
| 118 | bool tuneRx(double freq); |
| 119 | |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame] | 120 | /** set receive gain */ |
| 121 | double setRxGain(double dB); |
| 122 | |
| 123 | /** get receive gain */ |
| 124 | double getRxGain(void); |
| 125 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 126 | /** 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.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 140 | /** set thread priority on current thread */ |
| 141 | void setPriority() { mRadio->setPriority(); } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 142 | |
Thomas Tsou | 02d88d1 | 2013-04-05 15:36:30 -0400 | [diff] [blame] | 143 | /** get transport window type of attached device */ |
| 144 | enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); } |
kurtis.heimerl | e380af3 | 2011-11-26 03:18:55 +0000 | [diff] [blame] | 145 | |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 146 | #if USRP1 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 147 | protected: |
| 148 | |
| 149 | /** drive synchronization of Tx/Rx of USRP */ |
| 150 | void alignRadio(); |
| 151 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 152 | friend void *AlignRadioServiceLoopAdapter(RadioInterface*); |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 153 | #endif |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 154 | }; |
| 155 | |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 156 | #if USRP1 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 157 | /** synchronization thread loop */ |
| 158 | void *AlignRadioServiceLoopAdapter(RadioInterface*); |
Thomas Tsou | f2293b8 | 2013-04-08 13:35:36 -0400 | [diff] [blame] | 159 | #endif |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 160 | |
| 161 | class RadioInterfaceResamp : public RadioInterface { |
| 162 | |
| 163 | private: |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 164 | signalVector *innerSendBuffer; |
| 165 | signalVector *outerSendBuffer; |
| 166 | signalVector *innerRecvBuffer; |
| 167 | signalVector *outerRecvBuffer; |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 168 | |
| 169 | void pushBuffer(); |
| 170 | void pullBuffer(); |
| 171 | |
| 172 | public: |
| 173 | |
| 174 | RadioInterfaceResamp(RadioDevice* wRadio = NULL, |
| 175 | int receiveOffset = 3, |
| 176 | int wSPS = SAMPSPERSYM, |
| 177 | GSM::Time wStartTime = GSM::Time(0)); |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 178 | |
| 179 | ~RadioInterfaceResamp(); |
| 180 | |
| 181 | bool init(); |
| 182 | void close(); |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 183 | }; |