blob: 3e4f784ca33ff511c04ee434a69061efb8b6c8b8 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
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
25
26
27/*
28 Compilation switches
29 TRANSMIT_LOGGING write every burst on the given slot to a log
30*/
31
32#include "radioInterface.h"
33#include "Interthread.h"
34#include "GSMCommon.h"
35#include "Sockets.h"
36
37#include <sys/types.h>
38#include <sys/socket.h>
39
40/** Define this to be the slot number to be logged. */
41//#define TRANSMIT_LOGGING 1
42
43/** The Transceiver class, responsible for physical layer of basestation */
44class Transceiver {
45
46private:
47
48 GSM::Time mTransmitLatency; ///< latency between basestation clock and transmit deadline clock
49 GSM::Time mLatencyUpdateTime; ///< last time latency was updated
50
51 UDPSocket mDataSocket; ///< socket for writing to/reading from GSM core
52 UDPSocket mControlSocket; ///< socket for writing/reading control commands from GSM core
53 UDPSocket mClockSocket; ///< socket for writing clock updates to GSM core
54
55 VectorQueue mTransmitPriorityQueue; ///< priority queue of transmit bursts received from GSM core
56 VectorFIFO* mTransmitFIFO; ///< radioInterface FIFO of transmit bursts
57 VectorFIFO* mReceiveFIFO; ///< radioInterface FIFO of receive bursts
58
Thomas Tsou92c16df2013-09-28 18:04:19 -040059 Thread *mRxServiceLoopThread; ///< thread to pull bursts into receive FIFO
60 Thread *mTxServiceLoopThread; ///< thread to push bursts into transmit FIFO
dburgessb3a0ca42011-10-12 07:44:40 +000061 Thread *mControlServiceLoopThread; ///< thread to process control messages from GSM core
62 Thread *mTransmitPriorityQueueServiceLoopThread;///< thread to process transmit bursts from GSM core
63
64 GSM::Time mTransmitDeadlineClock; ///< deadline for pushing bursts into transmit FIFO
65 GSM::Time mLastClockUpdateTime; ///< last time clock update was sent up to core
66
67 RadioInterface *mRadioInterface; ///< associated radioInterface object
68 double txFullScale; ///< full scale input to radio
69 double rxFullScale; ///< full scale output to radio
70
71 /** Codes for burst types of received bursts*/
72 typedef enum {
73 OFF, ///< timeslot is off
74 TSC, ///< timeslot should contain a normal burst
75 RACH, ///< timeslot should contain an access burst
76 IDLE ///< timeslot is an idle (or dummy) burst
77 } CorrType;
78
79
80 /** Codes for channel combinations */
81 typedef enum {
82 FILL, ///< Channel is transmitted, but unused
83 I, ///< TCH/FS
84 II, ///< TCH/HS, idle every other slot
85 III, ///< TCH/HS
86 IV, ///< FCCH+SCH+CCCH+BCCH, uplink RACH
87 V, ///< FCCH+SCH+CCCH+BCCH+SDCCH/4+SACCH/4, uplink RACH+SDCCH/4
88 VI, ///< CCCH+BCCH, uplink RACH
89 VII, ///< SDCCH/8 + SACCH/8
ttsoufc40a842013-06-09 22:38:18 +000090 VIII, ///< TCH/F + FACCH/F + SACCH/M
91 IX, ///< TCH/F + SACCH/M
92 X, ///< TCH/FD + SACCH/MD
93 XI, ///< PBCCH+PCCCH+PDTCH+PACCH+PTCCH
94 XII, ///< PCCCH+PDTCH+PACCH+PTCCH
95 XIII, ///< PDTCH+PACCH+PTCCH
dburgessb3a0ca42011-10-12 07:44:40 +000096 NONE, ///< Channel is inactive, default
ttsoufc40a842013-06-09 22:38:18 +000097 LOOPBACK ///< similar go VII, used in loopback testing
dburgessb3a0ca42011-10-12 07:44:40 +000098 } ChannelCombination;
99
100
101 /** unmodulate a modulated burst */
102#ifdef TRANSMIT_LOGGING
103 void unModulateVector(signalVector wVector);
104#endif
105
106 /** modulate and add a burst to the transmit queue */
107 void addRadioVector(BitVector &burst,
108 int RSSI,
109 GSM::Time &wTime);
110
111 /** Push modulated burst into transmit FIFO corresponding to a particular timestamp */
112 void pushRadioVector(GSM::Time &nowTime);
113
114 /** Pull and demodulate a burst from the receive FIFO */
115 SoftVector *pullRadioVector(GSM::Time &wTime,
116 int &RSSI,
117 int &timingOffset);
118
119 /** Set modulus for specific timeslot */
120 void setModulus(int timeslot);
121
122 /** return the expected burst type for the specified timestamp */
123 CorrType expectedCorrType(GSM::Time currTime);
124
125 /** send messages over the clock socket */
126 void writeClockInterface(void);
127
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400128 int mSPS; ///< number of samples per GSM symbol
dburgessb3a0ca42011-10-12 07:44:40 +0000129
130 bool mOn; ///< flag to indicate that transceiver is powered on
131 ChannelCombination mChanType[8]; ///< channel types for all timeslots
132 double mTxFreq; ///< the transmit frequency
133 double mRxFreq; ///< the receive frequency
134 int mPower; ///< the transmit power in dB
135 unsigned mTSC; ///< the midamble sequence code
136 double mEnergyThreshold; ///< threshold to determine if received data is potentially a GSM burst
137 GSM::Time prevFalseDetectionTime; ///< last timestamp of a false energy detection
138 int fillerModulus[8]; ///< modulus values of all timeslots, in frames
139 signalVector *fillerTable[102][8]; ///< table of modulated filler waveforms for all timeslots
140 unsigned mMaxExpectedDelay; ///< maximum expected time-of-arrival offset in GSM symbols
141
142 GSM::Time channelEstimateTime[8]; ///< last timestamp of each timeslot's channel estimate
143 signalVector *channelResponse[8]; ///< most recent channel estimate of all timeslots
144 float SNRestimate[8]; ///< most recent SNR estimate of all timeslots
145 signalVector *DFEForward[8]; ///< most recent DFE feedforward filter of all timeslots
146 signalVector *DFEFeedback[8]; ///< most recent DFE feedback filter of all timeslots
147 float chanRespOffset[8]; ///< most recent timing offset, e.g. TOA, of all timeslots
148 complex chanRespAmplitude[8]; ///< most recent channel amplitude of all timeslots
149
150public:
151
152 /** Transceiver constructor
153 @param wBasePort base port number of UDP sockets
154 @param TRXAddress IP address of the TRX manager, as a string
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400155 @param wSPS number of samples per GSM symbol
dburgessb3a0ca42011-10-12 07:44:40 +0000156 @param wTransmitLatency initial setting of transmit latency
157 @param radioInterface associated radioInterface object
158 */
159 Transceiver(int wBasePort,
160 const char *TRXAddress,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400161 int wSPS,
dburgessb3a0ca42011-10-12 07:44:40 +0000162 GSM::Time wTransmitLatency,
163 RadioInterface *wRadioInterface);
164
165 /** Destructor */
166 ~Transceiver();
167
168 /** start the Transceiver */
169 void start();
Thomas Tsou83e06892013-08-20 16:10:01 -0400170 bool init();
dburgessb3a0ca42011-10-12 07:44:40 +0000171
172 /** attach the radioInterface receive FIFO */
173 void receiveFIFO(VectorFIFO *wFIFO) { mReceiveFIFO = wFIFO;}
174
175 /** attach the radioInterface transmit FIFO */
176 void transmitFIFO(VectorFIFO *wFIFO) { mTransmitFIFO = wFIFO;}
177
dburgessb3a0ca42011-10-12 07:44:40 +0000178protected:
179
180 /** drive reception and demodulation of GSM bursts */
181 void driveReceiveFIFO();
182
183 /** drive transmission of GSM bursts */
184 void driveTransmitFIFO();
185
186 /** drive handling of control messages from GSM core */
187 void driveControl();
188
189 /**
190 drive modulation and sorting of GSM bursts from GSM core
191 @return true if a burst was transferred successfully
192 */
193 bool driveTransmitPriorityQueue();
194
Thomas Tsou92c16df2013-09-28 18:04:19 -0400195 friend void *RxServiceLoopAdapter(Transceiver *);
196
197 friend void *TxServiceLoopAdapter(Transceiver *);
dburgessb3a0ca42011-10-12 07:44:40 +0000198
199 friend void *ControlServiceLoopAdapter(Transceiver *);
200
201 friend void *TransmitPriorityQueueServiceLoopAdapter(Transceiver *);
202
203 void reset();
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000204
205 /** set priority on current thread */
206 void setPriority() { mRadioInterface->setPriority(); }
207
dburgessb3a0ca42011-10-12 07:44:40 +0000208};
209
Thomas Tsou92c16df2013-09-28 18:04:19 -0400210/** Main drive threads */
211void *RxServiceLoopAdapter(Transceiver *);
212void *TxServiceLoopAdapter(Transceiver *);
dburgessb3a0ca42011-10-12 07:44:40 +0000213
214/** control message handler thread loop */
215void *ControlServiceLoopAdapter(Transceiver *);
216
217/** transmit queueing thread loop */
218void *TransmitPriorityQueueServiceLoopAdapter(Transceiver *);
219