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 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 29 | /** class to interface the transceiver with the USRP */ |
| 30 | class RadioInterface { |
| 31 | |
| 32 | private: |
| 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 |
| 39 | |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 40 | float *sendBuffer; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 41 | unsigned sendCursor; |
| 42 | |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 43 | float *rcvBuffer; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 44 | unsigned rcvCursor; |
| 45 | |
| 46 | bool underrun; ///< indicates writes to USRP are too slow |
| 47 | bool overrun; ///< indicates reads from USRP are too slow |
| 48 | TIMESTAMP writeTimestamp; ///< sample timestamp of next packet written to USRP |
| 49 | TIMESTAMP readTimestamp; ///< sample timestamp of next packet read from USRP |
| 50 | |
| 51 | RadioClock mClock; ///< the basestation clock! |
| 52 | |
| 53 | int samplesPerSymbol; ///< samples per GSM symbol |
| 54 | int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots |
| 55 | int mRadioOversampling; |
| 56 | int mTransceiverOversampling; |
| 57 | |
| 58 | bool mOn; ///< indicates radio is on |
| 59 | |
| 60 | double powerScaling; |
| 61 | |
| 62 | bool loadTest; |
| 63 | int mNumARFCNs; |
| 64 | signalVector *finalVec, *finalVec9; |
| 65 | |
| 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, |
| 69 | float scale, |
| 70 | bool zero); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 71 | |
| 72 | /** format samples from USRP */ |
kurtis.heimerl | 9b55783 | 2011-11-26 03:18:34 +0000 | [diff] [blame] | 73 | int unRadioifyVector(float *floatVector, signalVector &wVector); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 74 | |
| 75 | /** push GSM bursts into the transmit buffer */ |
| 76 | void pushBuffer(void); |
| 77 | |
| 78 | /** pull GSM bursts from the receive buffer */ |
| 79 | void pullBuffer(void); |
| 80 | |
| 81 | public: |
| 82 | |
| 83 | /** start the interface */ |
| 84 | void start(); |
| 85 | |
| 86 | /** constructor */ |
| 87 | RadioInterface(RadioDevice* wRadio = NULL, |
| 88 | int receiveOffset = 3, |
| 89 | int wRadioOversampling = SAMPSPERSYM, |
| 90 | int wTransceiverOversampling = SAMPSPERSYM, |
| 91 | GSM::Time wStartTime = GSM::Time(0)); |
| 92 | |
| 93 | /** destructor */ |
| 94 | ~RadioInterface(); |
| 95 | |
| 96 | void setSamplesPerSymbol(int wSamplesPerSymbol) {if (!mOn) samplesPerSymbol = wSamplesPerSymbol;} |
| 97 | |
| 98 | int getSamplesPerSymbol() { return samplesPerSymbol;} |
| 99 | |
| 100 | /** check for underrun, resets underrun value */ |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame^] | 101 | bool isUnderrun(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 102 | |
| 103 | /** attach an existing USRP to this interface */ |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame^] | 104 | void attach(RadioDevice *wRadio, int wRadioOversampling); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 105 | |
| 106 | /** return the receive FIFO */ |
| 107 | VectorFIFO* receiveFIFO() { return &mReceiveFIFO;} |
| 108 | |
| 109 | /** return the basestation clock */ |
| 110 | RadioClock* getClock(void) { return &mClock;}; |
| 111 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 112 | /** set transmit frequency */ |
| 113 | bool tuneTx(double freq); |
| 114 | |
| 115 | /** set receive frequency */ |
| 116 | bool tuneRx(double freq); |
| 117 | |
kurtis.heimerl | e724d6d | 2011-11-26 03:18:46 +0000 | [diff] [blame^] | 118 | /** set receive gain */ |
| 119 | double setRxGain(double dB); |
| 120 | |
| 121 | /** get receive gain */ |
| 122 | double getRxGain(void); |
| 123 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 124 | /** drive transmission of GSM bursts */ |
| 125 | void driveTransmitRadio(signalVector &radioBurst, bool zeroBurst); |
| 126 | |
| 127 | /** drive reception of GSM bursts */ |
| 128 | void driveReceiveRadio(); |
| 129 | |
| 130 | void setPowerAttenuation(double atten); |
| 131 | |
| 132 | /** returns the full-scale transmit amplitude **/ |
| 133 | double fullScaleInputValue(); |
| 134 | |
| 135 | /** returns the full-scale receive amplitude **/ |
| 136 | double fullScaleOutputValue(); |
| 137 | |
kurtis.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 138 | /** set thread priority on current thread */ |
| 139 | void setPriority() { mRadio->setPriority(); } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 140 | |
| 141 | protected: |
| 142 | |
| 143 | /** drive synchronization of Tx/Rx of USRP */ |
| 144 | void alignRadio(); |
| 145 | |
| 146 | /** reset the interface */ |
| 147 | void reset(); |
| 148 | |
| 149 | friend void *AlignRadioServiceLoopAdapter(RadioInterface*); |
| 150 | |
| 151 | }; |
| 152 | |
| 153 | /** synchronization thread loop */ |
| 154 | void *AlignRadioServiceLoopAdapter(RadioInterface*); |