blob: 317521304ae4cc93a5035ea62c0688d13369846e [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
59 Thread *mFIFOServiceLoopThread; ///< thread to push/pull bursts into transmit/receive FIFO
60 Thread *mControlServiceLoopThread; ///< thread to process control messages from GSM core
61 Thread *mTransmitPriorityQueueServiceLoopThread;///< thread to process transmit bursts from GSM core
62
63 GSM::Time mTransmitDeadlineClock; ///< deadline for pushing bursts into transmit FIFO
64 GSM::Time mLastClockUpdateTime; ///< last time clock update was sent up to core
65
66 RadioInterface *mRadioInterface; ///< associated radioInterface object
67 double txFullScale; ///< full scale input to radio
68 double rxFullScale; ///< full scale output to radio
69
70 /** Codes for burst types of received bursts*/
71 typedef enum {
72 OFF, ///< timeslot is off
73 TSC, ///< timeslot should contain a normal burst
74 RACH, ///< timeslot should contain an access burst
75 IDLE ///< timeslot is an idle (or dummy) burst
76 } CorrType;
77
78
79 /** Codes for channel combinations */
80 typedef enum {
81 FILL, ///< Channel is transmitted, but unused
82 I, ///< TCH/FS
83 II, ///< TCH/HS, idle every other slot
84 III, ///< TCH/HS
85 IV, ///< FCCH+SCH+CCCH+BCCH, uplink RACH
86 V, ///< FCCH+SCH+CCCH+BCCH+SDCCH/4+SACCH/4, uplink RACH+SDCCH/4
87 VI, ///< CCCH+BCCH, uplink RACH
88 VII, ///< SDCCH/8 + SACCH/8
ttsoufc40a842013-06-09 22:38:18 +000089 VIII, ///< TCH/F + FACCH/F + SACCH/M
90 IX, ///< TCH/F + SACCH/M
91 X, ///< TCH/FD + SACCH/MD
92 XI, ///< PBCCH+PCCCH+PDTCH+PACCH+PTCCH
93 XII, ///< PCCCH+PDTCH+PACCH+PTCCH
94 XIII, ///< PDTCH+PACCH+PTCCH
dburgessb3a0ca42011-10-12 07:44:40 +000095 NONE, ///< Channel is inactive, default
ttsoufc40a842013-06-09 22:38:18 +000096 LOOPBACK ///< similar go VII, used in loopback testing
dburgessb3a0ca42011-10-12 07:44:40 +000097 } ChannelCombination;
98
99
100 /** unmodulate a modulated burst */
101#ifdef TRANSMIT_LOGGING
102 void unModulateVector(signalVector wVector);
103#endif
104
105 /** modulate and add a burst to the transmit queue */
106 void addRadioVector(BitVector &burst,
107 int RSSI,
108 GSM::Time &wTime);
109
110 /** Push modulated burst into transmit FIFO corresponding to a particular timestamp */
111 void pushRadioVector(GSM::Time &nowTime);
112
113 /** Pull and demodulate a burst from the receive FIFO */
114 SoftVector *pullRadioVector(GSM::Time &wTime,
115 int &RSSI,
116 int &timingOffset);
117
118 /** Set modulus for specific timeslot */
119 void setModulus(int timeslot);
120
121 /** return the expected burst type for the specified timestamp */
122 CorrType expectedCorrType(GSM::Time currTime);
123
124 /** send messages over the clock socket */
125 void writeClockInterface(void);
126
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400127 int mSPS; ///< number of samples per GSM symbol
dburgessb3a0ca42011-10-12 07:44:40 +0000128
129 bool mOn; ///< flag to indicate that transceiver is powered on
130 ChannelCombination mChanType[8]; ///< channel types for all timeslots
131 double mTxFreq; ///< the transmit frequency
132 double mRxFreq; ///< the receive frequency
133 int mPower; ///< the transmit power in dB
134 unsigned mTSC; ///< the midamble sequence code
135 double mEnergyThreshold; ///< threshold to determine if received data is potentially a GSM burst
136 GSM::Time prevFalseDetectionTime; ///< last timestamp of a false energy detection
137 int fillerModulus[8]; ///< modulus values of all timeslots, in frames
138 signalVector *fillerTable[102][8]; ///< table of modulated filler waveforms for all timeslots
139 unsigned mMaxExpectedDelay; ///< maximum expected time-of-arrival offset in GSM symbols
140
141 GSM::Time channelEstimateTime[8]; ///< last timestamp of each timeslot's channel estimate
142 signalVector *channelResponse[8]; ///< most recent channel estimate of all timeslots
143 float SNRestimate[8]; ///< most recent SNR estimate of all timeslots
144 signalVector *DFEForward[8]; ///< most recent DFE feedforward filter of all timeslots
145 signalVector *DFEFeedback[8]; ///< most recent DFE feedback filter of all timeslots
146 float chanRespOffset[8]; ///< most recent timing offset, e.g. TOA, of all timeslots
147 complex chanRespAmplitude[8]; ///< most recent channel amplitude of all timeslots
148
149public:
150
151 /** Transceiver constructor
152 @param wBasePort base port number of UDP sockets
153 @param TRXAddress IP address of the TRX manager, as a string
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400154 @param wSPS number of samples per GSM symbol
dburgessb3a0ca42011-10-12 07:44:40 +0000155 @param wTransmitLatency initial setting of transmit latency
156 @param radioInterface associated radioInterface object
157 */
158 Transceiver(int wBasePort,
159 const char *TRXAddress,
Thomas Tsoud24cc2c2013-08-20 15:41:45 -0400160 int wSPS,
dburgessb3a0ca42011-10-12 07:44:40 +0000161 GSM::Time wTransmitLatency,
162 RadioInterface *wRadioInterface);
163
164 /** Destructor */
165 ~Transceiver();
166
167 /** start the Transceiver */
168 void start();
Thomas Tsou83e06892013-08-20 16:10:01 -0400169 bool init();
dburgessb3a0ca42011-10-12 07:44:40 +0000170
171 /** attach the radioInterface receive FIFO */
172 void receiveFIFO(VectorFIFO *wFIFO) { mReceiveFIFO = wFIFO;}
173
174 /** attach the radioInterface transmit FIFO */
175 void transmitFIFO(VectorFIFO *wFIFO) { mTransmitFIFO = wFIFO;}
176
dburgessb3a0ca42011-10-12 07:44:40 +0000177protected:
178
179 /** drive reception and demodulation of GSM bursts */
180 void driveReceiveFIFO();
181
182 /** drive transmission of GSM bursts */
183 void driveTransmitFIFO();
184
185 /** drive handling of control messages from GSM core */
186 void driveControl();
187
188 /**
189 drive modulation and sorting of GSM bursts from GSM core
190 @return true if a burst was transferred successfully
191 */
192 bool driveTransmitPriorityQueue();
193
194 friend void *FIFOServiceLoopAdapter(Transceiver *);
195
196 friend void *ControlServiceLoopAdapter(Transceiver *);
197
198 friend void *TransmitPriorityQueueServiceLoopAdapter(Transceiver *);
199
200 void reset();
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000201
202 /** set priority on current thread */
203 void setPriority() { mRadioInterface->setPriority(); }
204
dburgessb3a0ca42011-10-12 07:44:40 +0000205};
206
207/** FIFO thread loop */
208void *FIFOServiceLoopAdapter(Transceiver *);
209
210/** control message handler thread loop */
211void *ControlServiceLoopAdapter(Transceiver *);
212
213/** transmit queueing thread loop */
214void *TransmitPriorityQueueServiceLoopAdapter(Transceiver *);
215