blob: 4a84e2798d7d0e12d37deae49de6c8b7e2d33474 [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
89 NONE, ///< Channel is inactive, default
90 LOOPBACK ///< similar go VII, used in loopback testing
91 } ChannelCombination;
92
93
94 /** unmodulate a modulated burst */
95#ifdef TRANSMIT_LOGGING
96 void unModulateVector(signalVector wVector);
97#endif
98
99 /** modulate and add a burst to the transmit queue */
100 void addRadioVector(BitVector &burst,
101 int RSSI,
102 GSM::Time &wTime);
103
104 /** Push modulated burst into transmit FIFO corresponding to a particular timestamp */
105 void pushRadioVector(GSM::Time &nowTime);
106
107 /** Pull and demodulate a burst from the receive FIFO */
108 SoftVector *pullRadioVector(GSM::Time &wTime,
109 int &RSSI,
110 int &timingOffset);
111
112 /** Set modulus for specific timeslot */
113 void setModulus(int timeslot);
114
115 /** return the expected burst type for the specified timestamp */
116 CorrType expectedCorrType(GSM::Time currTime);
117
118 /** send messages over the clock socket */
119 void writeClockInterface(void);
120
121 signalVector *gsmPulse; ///< the GSM shaping pulse for modulation
122
123 int mSamplesPerSymbol; ///< number of samples per GSM symbol
124
125 bool mOn; ///< flag to indicate that transceiver is powered on
126 ChannelCombination mChanType[8]; ///< channel types for all timeslots
127 double mTxFreq; ///< the transmit frequency
128 double mRxFreq; ///< the receive frequency
129 int mPower; ///< the transmit power in dB
130 unsigned mTSC; ///< the midamble sequence code
131 double mEnergyThreshold; ///< threshold to determine if received data is potentially a GSM burst
132 GSM::Time prevFalseDetectionTime; ///< last timestamp of a false energy detection
133 int fillerModulus[8]; ///< modulus values of all timeslots, in frames
134 signalVector *fillerTable[102][8]; ///< table of modulated filler waveforms for all timeslots
135 unsigned mMaxExpectedDelay; ///< maximum expected time-of-arrival offset in GSM symbols
136
137 GSM::Time channelEstimateTime[8]; ///< last timestamp of each timeslot's channel estimate
138 signalVector *channelResponse[8]; ///< most recent channel estimate of all timeslots
139 float SNRestimate[8]; ///< most recent SNR estimate of all timeslots
140 signalVector *DFEForward[8]; ///< most recent DFE feedforward filter of all timeslots
141 signalVector *DFEFeedback[8]; ///< most recent DFE feedback filter of all timeslots
142 float chanRespOffset[8]; ///< most recent timing offset, e.g. TOA, of all timeslots
143 complex chanRespAmplitude[8]; ///< most recent channel amplitude of all timeslots
144
145public:
146
147 /** Transceiver constructor
148 @param wBasePort base port number of UDP sockets
149 @param TRXAddress IP address of the TRX manager, as a string
150 @param wSamplesPerSymbol number of samples per GSM symbol
151 @param wTransmitLatency initial setting of transmit latency
152 @param radioInterface associated radioInterface object
153 */
154 Transceiver(int wBasePort,
155 const char *TRXAddress,
156 int wSamplesPerSymbol,
157 GSM::Time wTransmitLatency,
158 RadioInterface *wRadioInterface);
159
160 /** Destructor */
161 ~Transceiver();
162
163 /** start the Transceiver */
164 void start();
165
166 /** attach the radioInterface receive FIFO */
167 void receiveFIFO(VectorFIFO *wFIFO) { mReceiveFIFO = wFIFO;}
168
169 /** attach the radioInterface transmit FIFO */
170 void transmitFIFO(VectorFIFO *wFIFO) { mTransmitFIFO = wFIFO;}
171
dburgessb3a0ca42011-10-12 07:44:40 +0000172protected:
173
174 /** drive reception and demodulation of GSM bursts */
175 void driveReceiveFIFO();
176
177 /** drive transmission of GSM bursts */
178 void driveTransmitFIFO();
179
180 /** drive handling of control messages from GSM core */
181 void driveControl();
182
183 /**
184 drive modulation and sorting of GSM bursts from GSM core
185 @return true if a burst was transferred successfully
186 */
187 bool driveTransmitPriorityQueue();
188
189 friend void *FIFOServiceLoopAdapter(Transceiver *);
190
191 friend void *ControlServiceLoopAdapter(Transceiver *);
192
193 friend void *TransmitPriorityQueueServiceLoopAdapter(Transceiver *);
194
195 void reset();
kurtis.heimerl6b495a52011-11-26 03:17:21 +0000196
197 /** set priority on current thread */
198 void setPriority() { mRadioInterface->setPriority(); }
199
dburgessb3a0ca42011-10-12 07:44:40 +0000200};
201
202/** FIFO thread loop */
203void *FIFOServiceLoopAdapter(Transceiver *);
204
205/** control message handler thread loop */
206void *ControlServiceLoopAdapter(Transceiver *);
207
208/** transmit queueing thread loop */
209void *TransmitPriorityQueueServiceLoopAdapter(Transceiver *);
210