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 the terms of the GNU Public License. |
| 5 | * See the COPYING file in the main directory for details. |
| 6 | * |
| 7 | * This use of this software may be subject to additional restrictions. |
| 8 | * See the LEGAL file in the main directory for details. |
| 9 | |
| 10 | This program is free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation, either version 3 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | |
| 23 | */ |
| 24 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 25 | #include "radioInterface.h" |
| 26 | #include "Interthread.h" |
| 27 | #include "GSMCommon.h" |
| 28 | #include "Sockets.h" |
| 29 | |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/socket.h> |
| 32 | |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 33 | class Transceiver; |
| 34 | |
| 35 | /** Channel descriptor for transceiver object and channel number pair */ |
| 36 | struct TransceiverChannel { |
| 37 | TransceiverChannel(Transceiver *trx, int num) |
| 38 | { |
| 39 | this->trx = trx; |
| 40 | this->num = num; |
| 41 | } |
| 42 | |
| 43 | ~TransceiverChannel() |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | Transceiver *trx; |
| 48 | size_t num; |
| 49 | }; |
| 50 | |
| 51 | /** Internal transceiver state variables */ |
| 52 | struct TransceiverState { |
| 53 | TransceiverState(); |
| 54 | ~TransceiverState(); |
| 55 | |
| 56 | /* Initialize a multiframe slot in the filler table */ |
| 57 | void init(size_t slot, signalVector *burst); |
| 58 | |
| 59 | int chanType[8]; |
| 60 | |
| 61 | /* Last timestamp of each timeslot's channel estimate */ |
| 62 | GSM::Time chanEstimateTime[8]; |
| 63 | |
| 64 | /* The filler table */ |
| 65 | signalVector *fillerTable[102][8]; |
| 66 | int fillerModulus[8]; |
| 67 | |
| 68 | /* Most recent channel estimate of all timeslots */ |
| 69 | signalVector *chanResponse[8]; |
| 70 | |
| 71 | /* Most recent DFE feedback filter of all timeslots */ |
| 72 | signalVector *DFEForward[8]; |
| 73 | signalVector *DFEFeedback[8]; |
| 74 | |
| 75 | /* Most recent SNR, timing, and channel amplitude estimates */ |
| 76 | float SNRestimate[8]; |
| 77 | float chanRespOffset[8]; |
| 78 | complex chanRespAmplitude[8]; |
| 79 | }; |
| 80 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 81 | /** The Transceiver class, responsible for physical layer of basestation */ |
| 82 | class Transceiver { |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 83 | private: |
Thomas Tsou | d647ec5 | 2013-10-29 15:17:34 -0400 | [diff] [blame] | 84 | int mBasePort; |
| 85 | std::string mAddr; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 86 | GSM::Time mTransmitLatency; ///< latency between basestation clock and transmit deadline clock |
| 87 | GSM::Time mLatencyUpdateTime; ///< last time latency was updated |
| 88 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 89 | std::vector<UDPSocket *> mDataSockets; ///< socket for writing to/reading from GSM core |
| 90 | std::vector<UDPSocket *> mCtrlSockets; ///< socket for writing/reading control commands from GSM core |
| 91 | UDPSocket *mClockSocket; ///< socket for writing clock updates to GSM core |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 92 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 93 | std::vector<VectorQueue> mTxPriorityQueues; ///< priority queue of transmit bursts received from GSM core |
| 94 | std::vector<VectorFIFO *> mReceiveFIFO; ///< radioInterface FIFO of receive bursts |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 95 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 96 | std::vector<Thread *> mRxServiceLoopThreads; ///< thread to pull bursts into receive FIFO |
| 97 | Thread *mRxLowerLoopThread; ///< thread to pull bursts into receive FIFO |
| 98 | Thread *mTxLowerLoopThread; ///< thread to push bursts into transmit FIFO |
| 99 | std::vector<Thread *> mControlServiceLoopThreads; ///< thread to process control messages from GSM core |
| 100 | std::vector<Thread *> mTxPriorityQueueServiceLoopThreads; ///< thread to process transmit bursts from GSM core |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 101 | |
| 102 | GSM::Time mTransmitDeadlineClock; ///< deadline for pushing bursts into transmit FIFO |
| 103 | GSM::Time mLastClockUpdateTime; ///< last time clock update was sent up to core |
| 104 | |
| 105 | RadioInterface *mRadioInterface; ///< associated radioInterface object |
| 106 | double txFullScale; ///< full scale input to radio |
| 107 | double rxFullScale; ///< full scale output to radio |
| 108 | |
| 109 | /** Codes for burst types of received bursts*/ |
| 110 | typedef enum { |
| 111 | OFF, ///< timeslot is off |
| 112 | TSC, ///< timeslot should contain a normal burst |
| 113 | RACH, ///< timeslot should contain an access burst |
| 114 | IDLE ///< timeslot is an idle (or dummy) burst |
| 115 | } CorrType; |
| 116 | |
Thomas Tsou | fa3a787 | 2013-10-17 21:23:34 -0400 | [diff] [blame] | 117 | float mNoiseLev; ///< Average noise level |
| 118 | noiseVector mNoises; ///< Vector holding running noise measurements |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 119 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 120 | /** modulate and add a burst to the transmit queue */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 121 | void addRadioVector(size_t chan, BitVector &burst, |
| 122 | int RSSI, GSM::Time &wTime); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 123 | |
| 124 | /** Push modulated burst into transmit FIFO corresponding to a particular timestamp */ |
| 125 | void pushRadioVector(GSM::Time &nowTime); |
| 126 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 127 | /** Pull and demodulate a burst from the receive FIFO */ |
| 128 | SoftVector *pullRadioVector(GSM::Time &wTime, int &RSSI, |
| 129 | int &timingOffset, size_t chan = 0); |
| 130 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 131 | /** Set modulus for specific timeslot */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 132 | void setModulus(size_t timeslot, size_t chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 133 | |
| 134 | /** return the expected burst type for the specified timestamp */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 135 | CorrType expectedCorrType(GSM::Time currTime, size_t chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 136 | |
| 137 | /** send messages over the clock socket */ |
| 138 | void writeClockInterface(void); |
| 139 | |
Thomas Tsou | c1f7c42 | 2013-10-11 13:49:55 -0400 | [diff] [blame] | 140 | int mSPSTx; ///< number of samples per Tx symbol |
| 141 | int mSPSRx; ///< number of samples per Rx symbol |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 142 | size_t mChans; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 143 | |
| 144 | bool mOn; ///< flag to indicate that transceiver is powered on |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 145 | double mTxFreq; ///< the transmit frequency |
| 146 | double mRxFreq; ///< the receive frequency |
| 147 | int mPower; ///< the transmit power in dB |
| 148 | unsigned mTSC; ///< the midamble sequence code |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 149 | unsigned mMaxExpectedDelay; ///< maximum expected time-of-arrival offset in GSM symbols |
| 150 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 151 | std::vector<TransceiverState> mStates; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 152 | |
| 153 | public: |
| 154 | |
| 155 | /** Transceiver constructor |
| 156 | @param wBasePort base port number of UDP sockets |
| 157 | @param TRXAddress IP address of the TRX manager, as a string |
Thomas Tsou | d24cc2c | 2013-08-20 15:41:45 -0400 | [diff] [blame] | 158 | @param wSPS number of samples per GSM symbol |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 159 | @param wTransmitLatency initial setting of transmit latency |
| 160 | @param radioInterface associated radioInterface object |
| 161 | */ |
| 162 | Transceiver(int wBasePort, |
| 163 | const char *TRXAddress, |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 164 | size_t wSPS, size_t chans, |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 165 | GSM::Time wTransmitLatency, |
| 166 | RadioInterface *wRadioInterface); |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 167 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 168 | /** Destructor */ |
| 169 | ~Transceiver(); |
| 170 | |
| 171 | /** start the Transceiver */ |
| 172 | void start(); |
Thomas Tsou | 83e0689 | 2013-08-20 16:10:01 -0400 | [diff] [blame] | 173 | bool init(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 174 | |
| 175 | /** attach the radioInterface receive FIFO */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 176 | bool receiveFIFO(VectorFIFO *wFIFO, size_t chan) |
| 177 | { |
| 178 | if (chan >= mReceiveFIFO.size()) |
| 179 | return false; |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 180 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 181 | mReceiveFIFO[chan] = wFIFO; |
| 182 | return true; |
| 183 | } |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 184 | |
Thomas Tsou | f078273 | 2013-10-29 15:55:47 -0400 | [diff] [blame] | 185 | /** Codes for channel combinations */ |
| 186 | typedef enum { |
| 187 | FILL, ///< Channel is transmitted, but unused |
| 188 | I, ///< TCH/FS |
| 189 | II, ///< TCH/HS, idle every other slot |
| 190 | III, ///< TCH/HS |
| 191 | IV, ///< FCCH+SCH+CCCH+BCCH, uplink RACH |
| 192 | V, ///< FCCH+SCH+CCCH+BCCH+SDCCH/4+SACCH/4, uplink RACH+SDCCH/4 |
| 193 | VI, ///< CCCH+BCCH, uplink RACH |
| 194 | VII, ///< SDCCH/8 + SACCH/8 |
| 195 | VIII, ///< TCH/F + FACCH/F + SACCH/M |
| 196 | IX, ///< TCH/F + SACCH/M |
| 197 | X, ///< TCH/FD + SACCH/MD |
| 198 | XI, ///< PBCCH+PCCCH+PDTCH+PACCH+PTCCH |
| 199 | XII, ///< PCCCH+PDTCH+PACCH+PTCCH |
| 200 | XIII, ///< PDTCH+PACCH+PTCCH |
| 201 | NONE, ///< Channel is inactive, default |
| 202 | LOOPBACK ///< similar go VII, used in loopback testing |
| 203 | } ChannelCombination; |
| 204 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 205 | protected: |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 206 | /** drive lower receive I/O and burst generation */ |
| 207 | void driveReceiveRadio(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 208 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 209 | /** drive demodulation of GSM bursts */ |
| 210 | void driveReceiveFIFO(size_t chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 211 | |
| 212 | /** drive transmission of GSM bursts */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 213 | void driveTxFIFO(); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 214 | |
| 215 | /** drive handling of control messages from GSM core */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 216 | void driveControl(size_t chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | drive modulation and sorting of GSM bursts from GSM core |
| 220 | @return true if a burst was transferred successfully |
| 221 | */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 222 | bool driveTxPriorityQueue(size_t chan); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 223 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 224 | friend void *RxUpperLoopAdapter(TransceiverChannel *); |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 225 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 226 | friend void *TxUpperLoopAdapter(TransceiverChannel *); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 227 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 228 | friend void *RxLowerLoopAdapter(Transceiver *); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 229 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 230 | friend void *TxLowerLoopAdapter(Transceiver *); |
| 231 | |
| 232 | friend void *ControlServiceLoopAdapter(TransceiverChannel *); |
| 233 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 234 | |
| 235 | void reset(); |
kurtis.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 236 | |
| 237 | /** set priority on current thread */ |
Thomas Tsou | 7553aa9 | 2013-11-08 12:50:03 -0500 | [diff] [blame^] | 238 | void setPriority(float prio = 0.5) { mRadioInterface->setPriority(prio); } |
kurtis.heimerl | 6b495a5 | 2011-11-26 03:17:21 +0000 | [diff] [blame] | 239 | |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 240 | }; |
| 241 | |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 242 | void *RxUpperLoopAdapter(TransceiverChannel *); |
| 243 | |
Thomas Tsou | 92c16df | 2013-09-28 18:04:19 -0400 | [diff] [blame] | 244 | /** Main drive threads */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 245 | void *RxLowerLoopAdapter(Transceiver *); |
| 246 | void *TxLowerLoopAdapter(Transceiver *); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 247 | |
| 248 | /** control message handler thread loop */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 249 | void *ControlServiceLoopAdapter(TransceiverChannel *); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 250 | |
| 251 | /** transmit queueing thread loop */ |
Thomas Tsou | 204a9f1 | 2013-10-29 18:34:16 -0400 | [diff] [blame] | 252 | void *TxUpperLoopAdapter(TransceiverChannel *); |
dburgess | b3a0ca4 | 2011-10-12 07:44:40 +0000 | [diff] [blame] | 253 | |