1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
//
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include "rhodium_radio_ctrl_impl.hpp"
#include "rhodium_cpld_ctrl.hpp"
#include "rhodium_constants.hpp"
#include <uhd/utils/log.hpp>
using namespace uhd;
using namespace uhd::usrp;
using namespace uhd::rfnoc;
namespace {
const char* rx_band_to_log(rhodium_radio_ctrl_impl::rx_band rx_band)
{
switch (rx_band)
{
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_0:
return "0";
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_1:
return "1";
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_2:
return "2";
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_3:
return "3";
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_4:
return "4";
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_5:
return "5";
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_6:
return "6";
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_7:
return "7";
case rhodium_radio_ctrl_impl::rx_band::RX_BAND_INVALID:
return "INVALID";
default:
UHD_THROW_INVALID_CODE_PATH();
}
}
const char* tx_band_to_log(rhodium_radio_ctrl_impl::tx_band tx_band)
{
switch (tx_band)
{
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_0:
return "0";
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_1:
return "1";
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_2:
return "2";
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_3:
return "3";
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_4:
return "4";
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_5:
return "5";
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_6:
return "6";
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_7:
return "7";
case rhodium_radio_ctrl_impl::tx_band::TX_BAND_INVALID:
return "INVALID";
default:
UHD_THROW_INVALID_CODE_PATH();
}
}
}
void rhodium_radio_ctrl_impl::_update_rx_freq_switches(
const double freq
) {
UHD_LOG_TRACE(unique_id(),
"Update all RX freq related switches. f=" << freq << " Hz, "
);
const auto band = _map_freq_to_rx_band(freq);
UHD_LOG_TRACE(unique_id(),
"Selected band " << rx_band_to_log(band));
// select values for lowband/highband switches
const bool is_lowband = (band == rx_band::RX_BAND_0);
auto rx_sw2_sw7 = is_lowband ?
rhodium_cpld_ctrl::RX_SW2_SW7_LOWBANDFILTERBANK :
rhodium_cpld_ctrl::RX_SW2_SW7_HIGHBANDFILTERBANK;
auto rx_hb_lb_sel = is_lowband ?
rhodium_cpld_ctrl::RX_HB_LB_SEL_LOWBAND :
rhodium_cpld_ctrl::RX_HB_LB_SEL_HIGHBAND;
// select values for filter bank switches
rhodium_cpld_ctrl::rx_sw3_t rx_sw3;
rhodium_cpld_ctrl::rx_sw4_sw5_t rx_sw4_sw5;
rhodium_cpld_ctrl::rx_sw6_t rx_sw6;
switch (band)
{
case rx_band::RX_BAND_0:
// Low band doesn't use the filter banks, use configuration for band 1
case rx_band::RX_BAND_1:
rx_sw3 = rhodium_cpld_ctrl::RX_SW3_TOSWITCH4;
rx_sw4_sw5 = rhodium_cpld_ctrl::RX_SW4_SW5_FILTER0450X0760MHZ;
rx_sw6 = rhodium_cpld_ctrl::RX_SW6_FROMSWITCH5;
break;
case rx_band::RX_BAND_2:
rx_sw3 = rhodium_cpld_ctrl::RX_SW3_TOSWITCH4;
rx_sw4_sw5 = rhodium_cpld_ctrl::RX_SW4_SW5_FILTER0760X1100MHZ;
rx_sw6 = rhodium_cpld_ctrl::RX_SW6_FROMSWITCH5;
break;
case rx_band::RX_BAND_3:
rx_sw3 = rhodium_cpld_ctrl::RX_SW3_TOSWITCH4;
rx_sw4_sw5 = rhodium_cpld_ctrl::RX_SW4_SW5_FILTER1100X1410MHZ;
rx_sw6 = rhodium_cpld_ctrl::RX_SW6_FROMSWITCH5;
break;
case rx_band::RX_BAND_4:
rx_sw3 = rhodium_cpld_ctrl::RX_SW3_TOSWITCH4;
rx_sw4_sw5 = rhodium_cpld_ctrl::RX_SW4_SW5_FILTER1410X2050MHZ;
rx_sw6 = rhodium_cpld_ctrl::RX_SW6_FROMSWITCH5;
break;
case rx_band::RX_BAND_5:
rx_sw3 = rhodium_cpld_ctrl::RX_SW3_TOFILTER2050X3000MHZ;
rx_sw4_sw5 = rhodium_cpld_ctrl::RX_SW4_SW5_FILTER0450X0760MHZ;
rx_sw6 = rhodium_cpld_ctrl::RX_SW6_FROMFILTER2050X3000MHZ;
break;
case rx_band::RX_BAND_6:
rx_sw3 = rhodium_cpld_ctrl::RX_SW3_TOFILTER3000X4500MHZ;
rx_sw4_sw5 = rhodium_cpld_ctrl::RX_SW4_SW5_FILTER0450X0760MHZ;
rx_sw6 = rhodium_cpld_ctrl::RX_SW6_FROMFILTER3000X4500MHZ;
break;
case rx_band::RX_BAND_7:
rx_sw3 = rhodium_cpld_ctrl::RX_SW3_TOFILTER4500X6000MHZ;
rx_sw4_sw5 = rhodium_cpld_ctrl::RX_SW4_SW5_FILTER0450X0760MHZ;
rx_sw6 = rhodium_cpld_ctrl::RX_SW6_FROMFILTER4500X6000MHZ;
break;
case rx_band::RX_BAND_INVALID:
throw uhd::runtime_error(str(boost::format(
"Cannot map RX frequency to band: %f") % freq));
default:
UHD_THROW_INVALID_CODE_PATH();
}
// commit settings to cpld
_cpld->set_rx_switches(
rx_sw2_sw7,
rx_sw3,
rx_sw4_sw5,
rx_sw6,
rx_hb_lb_sel
);
}
void rhodium_radio_ctrl_impl::_update_tx_freq_switches(
const double freq
){
UHD_LOG_TRACE(unique_id(),
"Update all TX freq related switches. f=" << freq << " Hz, "
);
const auto band = _map_freq_to_tx_band(freq);
UHD_LOG_TRACE(unique_id(),
"Selected band " << tx_band_to_log(band));
// select values for lowband/highband switches
const bool is_lowband = (band == tx_band::TX_BAND_0);
auto tx_hb_lb_sel = is_lowband ?
rhodium_cpld_ctrl::TX_HB_LB_SEL_LOWBAND :
rhodium_cpld_ctrl::TX_HB_LB_SEL_HIGHBAND;
// select values for filter bank switches
rhodium_cpld_ctrl::tx_sw2_t tx_sw2;
rhodium_cpld_ctrl::tx_sw3_sw4_t tx_sw3_sw4;
rhodium_cpld_ctrl::tx_sw5_t tx_sw5;
switch (band)
{
case tx_band::TX_BAND_0:
// Low band doesn't use the filter banks, use configuration for band 1
case tx_band::TX_BAND_1:
tx_sw2 = rhodium_cpld_ctrl::TX_SW2_FROMSWITCH3;
tx_sw3_sw4 = rhodium_cpld_ctrl::TX_SW3_SW4_FROMTXFILTERLP0650MHZ;
tx_sw5 = rhodium_cpld_ctrl::TX_SW5_TOSWITCH4;
break;
case tx_band::TX_BAND_2:
tx_sw2 = rhodium_cpld_ctrl::TX_SW2_FROMSWITCH3;
tx_sw3_sw4 = rhodium_cpld_ctrl::TX_SW3_SW4_FROMTXFILTERLP1000MHZ;
tx_sw5 = rhodium_cpld_ctrl::TX_SW5_TOSWITCH4;
break;
case tx_band::TX_BAND_3:
tx_sw2 = rhodium_cpld_ctrl::TX_SW2_FROMSWITCH3;
tx_sw3_sw4 = rhodium_cpld_ctrl::TX_SW3_SW4_FROMTXFILTERLP1350MHZ;
tx_sw5 = rhodium_cpld_ctrl::TX_SW5_TOSWITCH4;
break;
case tx_band::TX_BAND_4:
tx_sw2 = rhodium_cpld_ctrl::TX_SW2_FROMSWITCH3;
tx_sw3_sw4 = rhodium_cpld_ctrl::TX_SW3_SW4_FROMTXFILTERLP1900MHZ;
tx_sw5 = rhodium_cpld_ctrl::TX_SW5_TOSWITCH4;
break;
case tx_band::TX_BAND_5:
tx_sw2 = rhodium_cpld_ctrl::TX_SW2_FROMTXFILTERLP3000MHZ;
tx_sw3_sw4 = rhodium_cpld_ctrl::TX_SW3_SW4_FROMTXFILTERLP0650MHZ;
tx_sw5 = rhodium_cpld_ctrl::TX_SW5_TOTXFILTERLP3000MHZ;
break;
case tx_band::TX_BAND_6:
tx_sw2 = rhodium_cpld_ctrl::TX_SW2_FROMTXFILTERLP4100MHZ;
tx_sw3_sw4 = rhodium_cpld_ctrl::TX_SW3_SW4_FROMTXFILTERLP0650MHZ;
tx_sw5 = rhodium_cpld_ctrl::TX_SW5_TOTXFILTERLP4100MHZ;
break;
case tx_band::TX_BAND_7:
tx_sw2 = rhodium_cpld_ctrl::TX_SW2_FROMTXFILTERLP6000MHZ;
tx_sw3_sw4 = rhodium_cpld_ctrl::TX_SW3_SW4_FROMTXFILTERLP0650MHZ;
tx_sw5 = rhodium_cpld_ctrl::TX_SW5_TOTXFILTERLP6000MHZ;
break;
case tx_band::TX_BAND_INVALID:
throw uhd::runtime_error(str(boost::format(
"Cannot map TX frequency to band: %f") % freq));
default:
UHD_THROW_INVALID_CODE_PATH();
}
// commit settings to cpld
_cpld->set_tx_switches(
tx_sw2,
tx_sw3_sw4,
tx_sw5,
tx_hb_lb_sel
);
// If TX lowband/highband changes, SW10 needs to be updated
_update_tx_output_switches(get_tx_antenna(0));
}
void rhodium_radio_ctrl_impl::_update_rx_input_switches(
const std::string &input
) {
UHD_LOG_TRACE(unique_id(),
"Update all RX input related switches. input=" << input
);
const sw10_t sw10 = (input == "TX/RX") ?
SW10_TORX :
SW10_ISOLATION;
const rhodium_cpld_ctrl::cal_iso_sw_t cal_iso = (input == "CAL") ?
rhodium_cpld_ctrl::CAL_ISO_CALLOOPBACK :
rhodium_cpld_ctrl::CAL_ISO_ISOLATION;
const rhodium_cpld_ctrl::rx_sw1_t sw1 = [input]{
if (input == "TX/RX")
{
return rhodium_cpld_ctrl::RX_SW1_FROMTXRXINPUT;
}
else if (input == "RX2") {
return rhodium_cpld_ctrl::RX_SW1_FROMRX2INPUT;
}
else if (input == "CAL") {
return rhodium_cpld_ctrl::RX_SW1_FROMCALLOOPBACK;
}
else if (input == "TERM") {
return rhodium_cpld_ctrl::RX_SW1_ISOLATION;
}
else {
throw uhd::runtime_error("Invalid antenna in _update_rx_input_switches: " + input);
}
}();
UHD_LOG_TRACE(unique_id(),
"Selected switch values:"
" sw10=" << sw10 <<
" sw1=" << sw1 <<
" cal_iso=" << cal_iso
);
// the TX path may be using TX/RX already, in which case only override sw10 if
// we are attempting to use TX/RX
if (get_tx_antenna(0) == "TX/RX")
{
if (input == "TX/RX")
{
UHD_LOG_TRACE(unique_id(),
"Overriding TX antenna to TERM"
);
// TODO: setting antenna here could cause race conditions
set_tx_antenna("TERM", 0);
UHD_LOG_TRACE(unique_id(),
"Setting switch values: sw10=" << sw10
);
_gpio->set_gpio_out(sw10, SW10_GPIO_MASK);
}
else {
// skip setting sw10, allowing TX to continue using TX/RX
UHD_LOG_TRACE(unique_id(),
"sw10 setting was not applied because TX antenna is set to TX/RX"
);
}
}
else {
// TX/RX is not in use, fire away
UHD_LOG_TRACE(unique_id(),
"Setting switch values: sw10=" << sw10
);
_gpio->set_gpio_out(sw10, SW10_GPIO_MASK);
}
_cpld->set_rx_input_switches(sw1, cal_iso);
}
void rhodium_radio_ctrl_impl::_update_tx_output_switches(
const std::string &output
) {
UHD_LOG_TRACE(unique_id(),
"Update all TX output related switches. output=" << output
);
sw10_t sw10;
rhodium_cpld_ctrl::tx_sw1_t sw1;
if (output == "TX/RX")
{
//Both sw1 and sw10 need to select low/high band
if (_map_freq_to_tx_band(get_tx_frequency(0)) == tx_band::TX_BAND_0)
{
sw1 = rhodium_cpld_ctrl::TX_SW1_TOLOWBAND;
sw10 = SW10_FROMTXLOWBAND;
}
else {
sw1 = rhodium_cpld_ctrl::TX_SW1_TOSWITCH2;
sw10 = SW10_FROMTXHIGHBAND;
}
}
else if (output == "CAL") {
sw1 = rhodium_cpld_ctrl::TX_SW1_TOCALLOOPBACK;
sw10 = SW10_ISOLATION;
}
else if (output == "TERM") {
sw1 = rhodium_cpld_ctrl::TX_SW1_ISOLATION;
sw10 = SW10_ISOLATION;
}
else {
throw uhd::runtime_error("Invalid antenna in _update_tx_output_switches: " + output);
}
UHD_LOG_TRACE(unique_id(),
"Selected switch values: sw1=" << sw1 << " sw10=" << sw10
);
// If RX is on TX/RX, only set sw10 if TX is requesting TX/RX
// and override the RX antenna value
if (get_rx_antenna(0) == "TX/RX")
{
if (output == "TX/RX")
{
UHD_LOG_TRACE(unique_id(),
"Overriding RX antenna to TERM"
);
// TODO: setting antenna here could cause race conditions
set_rx_antenna("TERM", 0);
UHD_LOG_TRACE(unique_id(),
"Setting switch values: sw10=" << sw10
);
_gpio->set_gpio_out(sw10, SW10_GPIO_MASK);
}
else {
// skip setting sw10, allowing RX to continue using TX/RX
UHD_LOG_TRACE(unique_id(),
"sw10 setting was not applied because RX antenna is set to TX/RX"
);
}
}
// If RX is on any other setting, set sw10 normally
else {
UHD_LOG_TRACE(unique_id(),
"Setting switch values: sw10=" << sw10
);
_gpio->set_gpio_out(sw10, SW10_GPIO_MASK);
}
_cpld->set_tx_output_switches(sw1);
}
|