blob: 44da6382838143853774dae261d7068a3576e2be [file] [log] [blame]
Thomas Tsou85b179d2013-11-15 21:14:33 -05001/*
2 * Copyright (C) 2013 Thomas Tsou <tom@tsou.cc>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library 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. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include "Transceiver.h"
24#include "radioDevice.h"
25
26#include <time.h>
27#include <signal.h>
28#include <stdlib.h>
29#include <unistd.h>
Harald Welte81486e02017-06-29 15:35:22 +020030#include <sched.h>
Thomas Tsou85b179d2013-11-15 21:14:33 -050031
32#include <GSMCommon.h>
33#include <Logger.h>
Thomas Tsou85b179d2013-11-15 21:14:33 -050034
Philipp Maier7e07cf22017-03-15 18:09:35 +010035extern "C" {
36#include "convolve.h"
37#include "convert.h"
38}
39
Thomas Tsou85b179d2013-11-15 21:14:33 -050040/* Samples-per-symbol for downlink path
41 * 4 - Uses precision modulator (more computation, less distortion)
42 * 1 - Uses minimized modulator (less computation, more distortion)
43 *
44 * Other values are invalid. Receive path (uplink) is always
Tom Tsou0fe41a52016-05-03 15:14:45 -070045 * downsampled to 1 sps. Default to 4 sps for all cases.
Thomas Tsou85b179d2013-11-15 21:14:33 -050046 */
Tom Tsou5cd70dc2016-03-06 01:28:40 -080047#define DEFAULT_TX_SPS 4
Thomas Tsou85b179d2013-11-15 21:14:33 -050048
Tom Tsou5cd70dc2016-03-06 01:28:40 -080049/*
50 * Samples-per-symbol for uplink (receiver) path
51 * Do not modify this value. EDGE configures 4 sps automatically on
52 * B200/B210 devices only. Use of 4 sps on the receive path for other
53 * configurations is not supported.
54 */
55#define DEFAULT_RX_SPS 1
56
Tom Tsoude116e92017-03-30 17:00:42 -070057/* Default configuration parameters */
Thomas Tsou85b179d2013-11-15 21:14:33 -050058#define DEFAULT_TRX_PORT 5700
59#define DEFAULT_TRX_IP "127.0.0.1"
Thomas Tsou85b179d2013-11-15 21:14:33 -050060#define DEFAULT_CHANS 1
61
62struct trx_config {
63 std::string log_level;
Pau Espin Pedrol8c800952017-08-16 16:53:23 +020064 std::string local_addr;
65 std::string remote_addr;
Thomas Tsou85b179d2013-11-15 21:14:33 -050066 std::string dev_args;
67 unsigned port;
Tom Tsou5cd70dc2016-03-06 01:28:40 -080068 unsigned tx_sps;
69 unsigned rx_sps;
Thomas Tsou85b179d2013-11-15 21:14:33 -050070 unsigned chans;
Tom Tsou64ad7122015-05-19 18:26:31 -070071 unsigned rtsc;
Alexander Chemeris37c52c72016-03-25 18:28:34 +030072 unsigned rach_delay;
Thomas Tsou85b179d2013-11-15 21:14:33 -050073 bool extref;
Tom Tsou2f3e60b2016-07-17 19:29:08 -070074 bool gpsref;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -040075 Transceiver::FillerType filler;
Tom Tsou76764272016-06-24 14:25:39 -070076 bool mcbts;
Thomas Tsou8e17df72014-03-06 14:16:11 -050077 double offset;
Alexander Chemerise8905a02015-06-03 23:47:56 -040078 double rssi_offset;
Alexander Chemeris50747dc2015-06-07 01:07:45 -040079 bool swap_channels;
Tom Tsoub0aefcb2016-03-06 03:44:34 -080080 bool edge;
Harald Welte81486e02017-06-29 15:35:22 +020081 int sched_rr;
Thomas Tsou85b179d2013-11-15 21:14:33 -050082};
83
Thomas Tsou85b179d2013-11-15 21:14:33 -050084volatile bool gshutdown = false;
85
Thomas Tsou85b179d2013-11-15 21:14:33 -050086/* Setup configuration values
87 * Don't query the existence of the Log.Level because it's a
88 * mandatory value. That is, if it doesn't exist, the configuration
Thomas Tsou4de70be2013-11-17 18:54:52 -050089 * table will crash or will have already crashed. Everything else we
90 * can survive without and use default values if the database entries
Thomas Tsou85b179d2013-11-15 21:14:33 -050091 * are empty.
92 */
93bool trx_setup_config(struct trx_config *config)
94{
Tom Tsou76764272016-06-24 14:25:39 -070095 std::string refstr, fillstr, divstr, mcstr, edgestr;
Thomas Tsou85b179d2013-11-15 21:14:33 -050096
Tom Tsou60317342017-03-30 19:36:41 -070097 if (config->mcbts && config->chans > 5) {
Tom Tsou76764272016-06-24 14:25:39 -070098 std::cout << "Unsupported number of channels" << std::endl;
99 return false;
100 }
101
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800102 edgestr = config->edge ? "Enabled" : "Disabled";
Tom Tsou76764272016-06-24 14:25:39 -0700103 mcstr = config->mcbts ? "Enabled" : "Disabled";
104
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700105 if (config->extref)
106 refstr = "External";
107 else if (config->gpsref)
108 refstr = "GPS";
109 else
110 refstr = "Internal";
111
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400112 switch (config->filler) {
113 case Transceiver::FILLER_DUMMY:
114 fillstr = "Dummy bursts";
115 break;
116 case Transceiver::FILLER_ZERO:
117 fillstr = "Disabled";
118 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800119 case Transceiver::FILLER_NORM_RAND:
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400120 fillstr = "Normal busrts with random payload";
121 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800122 case Transceiver::FILLER_EDGE_RAND:
123 fillstr = "EDGE busrts with random payload";
124 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300125 case Transceiver::FILLER_ACCESS_RAND:
126 fillstr = "Access busrts with random payload";
127 break;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400128 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500129
130 std::ostringstream ost("");
131 ost << "Config Settings" << std::endl;
132 ost << " Log Level............... " << config->log_level << std::endl;
133 ost << " Device args............. " << config->dev_args << std::endl;
134 ost << " TRX Base Port........... " << config->port << std::endl;
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200135 ost << " TRX Address............. " << config->local_addr << std::endl;
136 ost << " GSM Core Address........." << config->remote_addr << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500137 ost << " Channels................ " << config->chans << std::endl;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800138 ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
Alexander Chemeris1ab5e7f2016-04-20 08:44:55 +0300139 ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800140 ost << " EDGE support............ " << edgestr << std::endl;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700141 ost << " Reference............... " << refstr << std::endl;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500142 ost << " C0 Filler Table......... " << fillstr << std::endl;
Tom Tsou76764272016-06-24 14:25:39 -0700143 ost << " Multi-Carrier........... " << mcstr << std::endl;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500144 ost << " Tuning offset........... " << config->offset << std::endl;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400145 ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400146 ost << " Swap channels........... " << config->swap_channels << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500147 std::cout << ost << std::endl;
148
149 return true;
150}
151
152/* Create radio interface
153 * The interface consists of sample rate changes, frequency shifts,
154 * channel multiplexing, and other conversions. The transceiver core
155 * accepts input vectors sampled at multiples of the GSM symbol rate.
156 * The radio interface connects the main transceiver with the device
157 * object, which may be operating some other rate.
158 */
159RadioInterface *makeRadioInterface(struct trx_config *config,
160 RadioDevice *usrp, int type)
161{
162 RadioInterface *radio = NULL;
163
164 switch (type) {
165 case RadioDevice::NORMAL:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800166 radio = new RadioInterface(usrp, config->tx_sps,
167 config->rx_sps, config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500168 break;
169 case RadioDevice::RESAMP_64M:
170 case RadioDevice::RESAMP_100M:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800171 radio = new RadioInterfaceResamp(usrp, config->tx_sps,
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700172 config->rx_sps);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500173 break;
Tom Tsou76764272016-06-24 14:25:39 -0700174 case RadioDevice::MULTI_ARFCN:
175 radio = new RadioInterfaceMulti(usrp, config->tx_sps,
176 config->rx_sps, config->chans);
177 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500178 default:
179 LOG(ALERT) << "Unsupported radio interface configuration";
180 return NULL;
181 }
182
183 if (!radio->init(type)) {
184 LOG(ALERT) << "Failed to initialize radio interface";
185 return NULL;
186 }
187
188 return radio;
189}
190
191/* Create transceiver core
192 * The multi-threaded modem core operates at multiples of the GSM rate of
193 * 270.8333 ksps and consists of GSM specific modulation, demodulation,
194 * and decoding schemes. Also included are the socket interfaces for
195 * connecting to the upper layer stack.
196 */
197Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio)
198{
199 Transceiver *trx;
200 VectorFIFO *fifo;
201
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200202 trx = new Transceiver(config->port, config->local_addr.c_str(),
203 config->remote_addr.c_str(), config->tx_sps,
204 config->rx_sps, config->chans, GSM::Time(3,0),
205 radio, config->rssi_offset);
Tom Tsou64464e62016-07-01 03:46:46 -0700206 if (!trx->init(config->filler, config->rtsc,
207 config->rach_delay, config->edge)) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500208 LOG(ALERT) << "Failed to initialize transceiver";
209 delete trx;
210 return NULL;
211 }
212
213 for (size_t i = 0; i < config->chans; i++) {
214 fifo = radio->receiveFIFO(i);
215 if (fifo && trx->receiveFIFO(fifo, i))
216 continue;
217
218 LOG(ALERT) << "Could not attach FIFO to channel " << i;
219 delete trx;
220 return NULL;
221 }
222
223 return trx;
224}
225
226static void sig_handler(int signo)
227{
228 fprintf(stdout, "Received shutdown signal");
229 gshutdown = true;
230}
231
232static void setup_signal_handlers()
233{
234 if (signal(SIGINT, sig_handler) == SIG_ERR) {
235 fprintf(stderr, "Failed to install SIGINT signal handler\n");
236 exit(EXIT_FAILURE);
237 }
238 if (signal(SIGTERM, sig_handler) == SIG_ERR) {
239 fprintf(stderr, "Couldn't install SIGTERM signal handler\n");
240 exit( EXIT_FAILURE);
241 }
242}
243
244static void print_help()
245{
246 fprintf(stdout, "Options:\n"
247 " -h This text\n"
248 " -a UHD device args\n"
249 " -l Logging level (%s)\n"
250 " -i IP address of GSM core\n"
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200251 " -j IP address of osmo-trx\n"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500252 " -p Base port number\n"
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800253 " -e Enable EDGE receiver\n"
Tom Tsou76764272016-06-24 14:25:39 -0700254 " -m Enable multi-ARFCN transceiver (default=disabled)\n"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500255 " -x Enable external 10 MHz reference\n"
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700256 " -g Enable GPSDO reference\n"
Tom Tsou2e4ed102016-06-27 15:39:16 -0700257 " -s Tx samples-per-symbol (1 or 4)\n"
258 " -b Rx samples-per-symbol (1 or 4)\n"
Thomas Tsou15d743e2014-01-25 02:34:03 -0500259 " -c Number of ARFCN channels (default=1)\n"
Thomas Tsou8e17df72014-03-06 14:16:11 -0500260 " -f Enable C0 filler table\n"
Tom Tsou64ad7122015-05-19 18:26:31 -0700261 " -o Set baseband frequency offset (default=auto)\n"
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300262 " -r Random Normal Burst test mode with TSC\n"
263 " -A Random Access Burst test mode with delay\n"
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400264 " -R RSSI to dBm offset in dB (default=0)\n"
Harald Welte81486e02017-06-29 15:35:22 +0200265 " -S Swap channels (UmTRX only)\n"
266 " -t SCHED_RR real-time priority (1..32)\n",
Thomas Tsou85b179d2013-11-15 21:14:33 -0500267 "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
268}
269
270static void handle_options(int argc, char **argv, struct trx_config *config)
271{
272 int option;
273
Tom Tsoude116e92017-03-30 17:00:42 -0700274 config->log_level = "NOTICE";
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200275 config->local_addr = DEFAULT_TRX_IP;
276 config->remote_addr = DEFAULT_TRX_IP;
Tom Tsoude116e92017-03-30 17:00:42 -0700277 config->port = DEFAULT_TRX_PORT;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800278 config->tx_sps = DEFAULT_TX_SPS;
279 config->rx_sps = DEFAULT_RX_SPS;
Tom Tsou64ad7122015-05-19 18:26:31 -0700280 config->chans = DEFAULT_CHANS;
281 config->rtsc = 0;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300282 config->rach_delay = 0;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500283 config->extref = false;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700284 config->gpsref = false;
Tom Tsou64ad7122015-05-19 18:26:31 -0700285 config->filler = Transceiver::FILLER_ZERO;
Tom Tsou76764272016-06-24 14:25:39 -0700286 config->mcbts = false;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500287 config->offset = 0.0;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400288 config->rssi_offset = 0.0;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400289 config->swap_channels = false;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800290 config->edge = false;
Harald Welte81486e02017-06-29 15:35:22 +0200291 config->sched_rr = -1;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500292
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200293 while ((option = getopt(argc, argv, "ha:l:i:j:p:c:dmxgfo:s:b:r:A:R:Set:")) != -1) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500294 switch (option) {
295 case 'h':
296 print_help();
297 exit(0);
298 break;
299 case 'a':
300 config->dev_args = optarg;
301 break;
302 case 'l':
303 config->log_level = optarg;
304 break;
305 case 'i':
Pau Espin Pedrol8c800952017-08-16 16:53:23 +0200306 config->remote_addr = optarg;
307 break;
308 case 'j':
309 config->local_addr = optarg;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500310 break;
311 case 'p':
312 config->port = atoi(optarg);
313 break;
314 case 'c':
315 config->chans = atoi(optarg);
316 break;
Tom Tsou76764272016-06-24 14:25:39 -0700317 case 'm':
318 config->mcbts = true;
319 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500320 case 'x':
321 config->extref = true;
322 break;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700323 case 'g':
324 config->gpsref = true;
325 break;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500326 case 'f':
Tom Tsou64ad7122015-05-19 18:26:31 -0700327 config->filler = Transceiver::FILLER_DUMMY;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500328 break;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500329 case 'o':
330 config->offset = atof(optarg);
331 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500332 case 's':
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800333 config->tx_sps = atoi(optarg);
Tom Tsou64ad7122015-05-19 18:26:31 -0700334 break;
Tom Tsou2e4ed102016-06-27 15:39:16 -0700335 case 'b':
336 config->rx_sps = atoi(optarg);
337 break;
Tom Tsou64ad7122015-05-19 18:26:31 -0700338 case 'r':
339 config->rtsc = atoi(optarg);
Tom Tsouaf717b22016-03-06 22:19:15 -0800340 config->filler = Transceiver::FILLER_NORM_RAND;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500341 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300342 case 'A':
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300343 config->rach_delay = atoi(optarg);
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300344 config->filler = Transceiver::FILLER_ACCESS_RAND;
345 break;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400346 case 'R':
347 config->rssi_offset = atof(optarg);
348 break;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400349 case 'S':
350 config->swap_channels = true;
351 break;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800352 case 'e':
353 config->edge = true;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800354 break;
Harald Welte81486e02017-06-29 15:35:22 +0200355 case 't':
356 config->sched_rr = atoi(optarg);
357 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500358 default:
359 print_help();
360 exit(0);
361 }
362 }
Tom Tsou64ad7122015-05-19 18:26:31 -0700363
Tom Tsou76764272016-06-24 14:25:39 -0700364 /* Force 4 SPS for EDGE or multi-ARFCN configurations */
365 if ((config->edge) || (config->mcbts)) {
Tom Tsou2e4ed102016-06-27 15:39:16 -0700366 config->tx_sps = 4;
367 config->rx_sps = 4;
368 }
369
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700370 if (config->gpsref && config->extref) {
371 printf("External and GPSDO references unavailable at the same time\n\n");
372 goto bad_config;
373 }
374
Tom Tsouaf717b22016-03-06 22:19:15 -0800375 if (config->edge && (config->filler == Transceiver::FILLER_NORM_RAND))
376 config->filler = Transceiver::FILLER_EDGE_RAND;
377
Tom Tsou76764272016-06-24 14:25:39 -0700378 if ((config->tx_sps != 1) && (config->tx_sps != 4) &&
379 (config->rx_sps != 1) && (config->rx_sps != 4)) {
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800380 printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700381 goto bad_config;
Tom Tsou64ad7122015-05-19 18:26:31 -0700382 }
383
384 if (config->rtsc > 7) {
385 printf("Invalid training sequence %i\n\n", config->rtsc);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700386 goto bad_config;
Tom Tsou64ad7122015-05-19 18:26:31 -0700387 }
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300388
389 if (config->rach_delay > 68) {
390 printf("RACH delay is too big %i\n\n", config->rach_delay);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700391 goto bad_config;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300392 }
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700393
394 return;
395
396bad_config:
397 print_help();
398 exit(0);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500399}
400
Harald Welte81486e02017-06-29 15:35:22 +0200401static int set_sched_rr(int prio)
402{
403 struct sched_param param;
404 int rc;
405 memset(&param, 0, sizeof(param));
406 param.sched_priority = prio;
407 printf("Setting SCHED_RR priority(%d)\n", param.sched_priority);
408 rc = sched_setscheduler(getpid(), SCHED_RR, &param);
409 if (rc != 0) {
410 std::cerr << "Config: Setting SCHED_RR failed" << std::endl;
411 return -1;
412 }
413 return 0;
414}
415
Thomas Tsou85b179d2013-11-15 21:14:33 -0500416int main(int argc, char *argv[])
417{
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700418 int type, chans, ref;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500419 RadioDevice *usrp;
420 RadioInterface *radio = NULL;
421 Transceiver *trx = NULL;
Tom Tsou05c6feb2016-06-22 16:09:44 -0700422 RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500423 struct trx_config config;
424
Philipp Maiere51a8f02017-03-16 12:09:34 +0100425#ifdef HAVE_SSE3
426 printf("Info: SSE3 support compiled in");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300427#ifdef HAVE___BUILTIN_CPU_SUPPORTS
Philipp Maiere51a8f02017-03-16 12:09:34 +0100428 if (__builtin_cpu_supports("sse3"))
429 printf(" and supported by CPU\n");
430 else
431 printf(", but not supported by CPU\n");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300432#else
433 printf(", but runtime SIMD detection disabled\n");
434#endif
Philipp Maiere51a8f02017-03-16 12:09:34 +0100435#endif
436
437#ifdef HAVE_SSE4_1
438 printf("Info: SSE4.1 support compiled in");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300439#ifdef HAVE___BUILTIN_CPU_SUPPORTS
Philipp Maiere51a8f02017-03-16 12:09:34 +0100440 if (__builtin_cpu_supports("sse4.1"))
441 printf(" and supported by CPU\n");
442 else
443 printf(", but not supported by CPU\n");
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +0300444#else
445 printf(", but runtime SIMD detection disabled\n");
446#endif
Philipp Maiere51a8f02017-03-16 12:09:34 +0100447#endif
448
Philipp Maier7e07cf22017-03-15 18:09:35 +0100449 convolve_init();
450 convert_init();
451
Thomas Tsou85b179d2013-11-15 21:14:33 -0500452 handle_options(argc, argv, &config);
453
Harald Welte81486e02017-06-29 15:35:22 +0200454 if (config.sched_rr != -1) {
455 if (set_sched_rr(config.sched_rr) < 0)
456 return EXIT_FAILURE;
457 }
458
Thomas Tsou85b179d2013-11-15 21:14:33 -0500459 setup_signal_handlers();
460
461 /* Check database sanity */
462 if (!trx_setup_config(&config)) {
463 std::cerr << "Config: Database failure - exiting" << std::endl;
464 return EXIT_FAILURE;
465 }
466
467 gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
468
469 srandom(time(NULL));
470
471 /* Create the low level device object */
Tom Tsou76764272016-06-24 14:25:39 -0700472 if (config.mcbts)
473 iface = RadioDevice::MULTI_ARFCN;
474
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700475 if (config.extref)
476 ref = RadioDevice::REF_EXTERNAL;
477 else if (config.gpsref)
478 ref = RadioDevice::REF_GPS;
479 else
480 ref = RadioDevice::REF_INTERNAL;
481
Tom Tsou05c6feb2016-06-22 16:09:44 -0700482 usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
483 config.chans, config.offset);
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700484 type = usrp->open(config.dev_args, ref, config.swap_channels);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500485 if (type < 0) {
486 LOG(ALERT) << "Failed to create radio device" << std::endl;
487 goto shutdown;
488 }
489
490 /* Setup the appropriate device interface */
491 radio = makeRadioInterface(&config, usrp, type);
492 if (!radio)
493 goto shutdown;
494
495 /* Create the transceiver core */
496 trx = makeTransceiver(&config, radio);
497 if (!trx)
498 goto shutdown;
499
Thomas Tsou85b179d2013-11-15 21:14:33 -0500500 chans = trx->numChans();
501 std::cout << "-- Transceiver active with "
502 << chans << " channel(s)" << std::endl;
503
504 while (!gshutdown)
505 sleep(1);
506
507shutdown:
508 std::cout << "Shutting down transceiver..." << std::endl;
509
510 delete trx;
511 delete radio;
512 delete usrp;
513
514 return 0;
515}