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 */ |
Thomas Tsou | a57bc8a | 2013-09-05 08:16:47 +0800 | [diff] [blame] | 25 | #define SAMPSPERSYM 4 |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 26 | |
Alexander Chemeris | d734e2d | 2013-06-16 14:30:58 +0400 | [diff] [blame] | 27 | static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods |
| 28 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 29 | /** class to interface the transceiver with the USRP */ |
| 30 | class RadioInterface { |
| 31 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 32 | protected: |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 33 | |
| 34 | Thread mAlignRadioServiceLoopThread; ///< thread that synchronizes transmit and receive sections |
| 35 | |
| 36 | VectorFIFO mReceiveFIFO; ///< FIFO that holds receive bursts |
| 37 | |
| 38 | RadioDevice *mRadio; ///< the USRP object |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame^] | 39 | |
| 40 | int mSPSTx; |
| 41 | int mSPSRx; |
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 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 57 | int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 58 | |
| 59 | bool mOn; ///< indicates radio is on |
| 60 | |
| 61 | double powerScaling; |
| 62 | |
| 63 | bool loadTest; |
| 64 | int mNumARFCNs; |
| 65 | signalVector *finalVec, *finalVec9; |
| 66 | |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 67 | private: |
| 68 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 69 | /** format samples to USRP */ |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 70 | int radioifyVector(signalVector &wVector, |
| 71 | float *floatVector, |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 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 | |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 88 | /** intialization */ |
| 89 | virtual bool init(); |
| 90 | virtual void close(); |
| 91 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 92 | /** constructor */ |
| 93 | RadioInterface(RadioDevice* wRadio = NULL, |
| 94 | int receiveOffset = 3, |
Thomas Tsou | 312e387 | 2013-04-08 13:45:55 -0400 | [diff] [blame] | 95 | int wSPS = SAMPSPERSYM, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 96 | GSM::Time wStartTime = GSM::Time(0)); |
| 97 | |
| 98 | /** destructor */ |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 99 | virtual ~RadioInterface(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 100 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 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: |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 163 | signalVector *innerSendBuffer; |
| 164 | signalVector *outerSendBuffer; |
| 165 | signalVector *innerRecvBuffer; |
| 166 | signalVector *outerRecvBuffer; |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 167 | |
| 168 | void pushBuffer(); |
| 169 | void pullBuffer(); |
| 170 | |
| 171 | public: |
| 172 | |
| 173 | RadioInterfaceResamp(RadioDevice* wRadio = NULL, |
| 174 | int receiveOffset = 3, |
| 175 | int wSPS = SAMPSPERSYM, |
| 176 | GSM::Time wStartTime = GSM::Time(0)); |
Thomas Tsou | 03e6ecf | 2013-08-20 20:54:54 -0400 | [diff] [blame] | 177 | |
| 178 | ~RadioInterfaceResamp(); |
| 179 | |
| 180 | bool init(); |
| 181 | void close(); |
Thomas Tsou | cb69f08 | 2013-04-08 14:18:26 -0400 | [diff] [blame] | 182 | }; |