aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/dboard/rhodium/rhodium_radio_control_init.cpp
blob: 850e5aff363bb8f0665cc4e5e73abac33e9a614b (plain)
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
//
// Copyright 2018 Ettus Research, a National Instruments Company
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//

#include "rhodium_constants.hpp"
#include "rhodium_radio_control.hpp"
#include <uhd/types/eeprom.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/utils/algorithm.hpp>
#include <uhd/utils/log.hpp>
#include <uhdlib/rfnoc/reg_iface_adapter.hpp>
#include <uhdlib/usrp/common/mpmd_mb_controller.hpp>
#include <uhdlib/usrp/cores/spi_core_3000.hpp>
#include <string>
#include <vector>

using namespace uhd;
using namespace uhd::usrp;
using namespace uhd::rfnoc;

namespace {
enum slave_select_t {
    SEN_CPLD    = 8,
    SEN_TX_LO   = 1,
    SEN_RX_LO   = 2,
    SEN_LO_DIST = 4 /* Unused */
};

constexpr double RHODIUM_DEFAULT_FREQ = 2.5e9; // Hz
// An invalid default index ensures that set gain will apply settings
// the first time it is called
constexpr double RHODIUM_DEFAULT_INVALID_GAIN = -1; // gain index
constexpr double RHODIUM_DEFAULT_GAIN         = 0; // gain index
constexpr double RHODIUM_DEFAULT_LO_GAIN      = 30; // gain index
constexpr char RHODIUM_DEFAULT_RX_ANTENNA[]   = "RX2";
constexpr char RHODIUM_DEFAULT_TX_ANTENNA[]   = "TX/RX";
constexpr auto RHODIUM_DEFAULT_MASH_ORDER     = lmx2592_iface::mash_order_t::THIRD;

//! Returns the SPI config used by the CPLD
spi_config_t _get_cpld_spi_config()
{
    spi_config_t spi_config;
    spi_config.use_custom_divider = true;
    spi_config.divider            = 10;
    spi_config.mosi_edge          = spi_config_t::EDGE_RISE;
    spi_config.miso_edge          = spi_config_t::EDGE_FALL;

    return spi_config;
}

//! Returns the SPI config used by the TX LO
spi_config_t _get_tx_lo_spi_config()
{
    spi_config_t spi_config;
    spi_config.use_custom_divider = true;
    spi_config.divider            = 10;
    spi_config.mosi_edge          = spi_config_t::EDGE_RISE;
    spi_config.miso_edge          = spi_config_t::EDGE_FALL;

    return spi_config;
}

//! Returns the SPI config used by the RX LO
spi_config_t _get_rx_lo_spi_config()
{
    spi_config_t spi_config;
    spi_config.use_custom_divider = true;
    spi_config.divider            = 10;
    spi_config.mosi_edge          = spi_config_t::EDGE_RISE;
    spi_config.miso_edge          = spi_config_t::EDGE_FALL;

    return spi_config;
}

std::function<void(uint32_t)> _generate_write_spi(
    uhd::spi_iface::sptr spi, slave_select_t slave, spi_config_t config)
{
    return [spi, slave, config](const uint32_t transaction) {
        spi->write_spi(slave, config, transaction, 24);
    };
}

std::function<uint32_t(uint32_t)> _generate_read_spi(
    uhd::spi_iface::sptr spi, slave_select_t slave, spi_config_t config)
{
    return [spi, slave, config](const uint32_t transaction) {
        return spi->read_spi(slave, config, transaction, 24);
    };
}
} // namespace

void rhodium_radio_control_impl::_init_defaults()
{
    RFNOC_LOG_TRACE("Initializing defaults...");
    const size_t num_rx_chans = get_num_output_ports();
    const size_t num_tx_chans = get_num_input_ports();
    UHD_ASSERT_THROW(num_tx_chans == RHODIUM_NUM_CHANS);
    UHD_ASSERT_THROW(num_rx_chans == RHODIUM_NUM_CHANS);

    for (size_t chan = 0; chan < num_rx_chans; chan++) {
        radio_control_impl::set_rx_frequency(RHODIUM_DEFAULT_FREQ, chan);
        radio_control_impl::set_rx_gain(RHODIUM_DEFAULT_INVALID_GAIN, chan);
        radio_control_impl::set_rx_antenna(RHODIUM_DEFAULT_RX_ANTENNA, chan);
        radio_control_impl::set_rx_bandwidth(RHODIUM_DEFAULT_BANDWIDTH, chan);
    }

    for (size_t chan = 0; chan < num_tx_chans; chan++) {
        radio_control_impl::set_tx_frequency(RHODIUM_DEFAULT_FREQ, chan);
        radio_control_impl::set_tx_gain(RHODIUM_DEFAULT_INVALID_GAIN, chan);
        radio_control_impl::set_tx_antenna(RHODIUM_DEFAULT_TX_ANTENNA, chan);
        radio_control_impl::set_tx_bandwidth(RHODIUM_DEFAULT_BANDWIDTH, chan);
    }

    register_property(&_spur_dodging_mode);
    register_property(&_spur_dodging_threshold);
    register_property(&_highband_spur_reduction_mode);

    // Update configurable block arguments from the device arguments provided
    const auto block_args = get_block_args();
    if (block_args.has_key(SPUR_DODGING_PROP_NAME)) {
        _spur_dodging_mode.set(block_args.get(SPUR_DODGING_PROP_NAME));
    }
    if (block_args.has_key(SPUR_DODGING_THRESHOLD_PROP_NAME)) {
        _spur_dodging_threshold.set(block_args.cast<double>(
            SPUR_DODGING_THRESHOLD_PROP_NAME, RHODIUM_DEFAULT_SPUR_DOGING_THRESHOLD));
    }
    if (block_args.has_key(HIGHBAND_SPUR_REDUCTION_PROP_NAME)) {
        _highband_spur_reduction_mode.set(
            block_args.get(HIGHBAND_SPUR_REDUCTION_PROP_NAME));
    }
}

void rhodium_radio_control_impl::_init_peripherals()
{
    RFNOC_LOG_TRACE("Initializing SPI core...");
    _spi = spi_core_3000::make(
        [this](uint32_t addr, uint32_t data) {
            regs().poke32(addr, data, get_command_time(0));
        },
        [this](uint32_t addr) { return regs().peek32(addr, get_command_time(0)); },
        regmap::REG_SPI_W,
        8,
        regmap::REG_SPI_R);
    _wb_iface = RFNOC_MAKE_WB_IFACE(0, 0);

    RFNOC_LOG_TRACE("Initializing CPLD...");
    _cpld = std::make_shared<rhodium_cpld_ctrl>(
        _generate_write_spi(this->_spi, SEN_CPLD, _get_cpld_spi_config()),
        _generate_read_spi(this->_spi, SEN_CPLD, _get_cpld_spi_config()));

    RFNOC_LOG_TRACE("Initializing TX frontend DSP core...")
    _tx_fe_core = tx_frontend_core_200::make(_wb_iface, n320_regs::SR_TX_FE_BASE);
    _tx_fe_core->set_dc_offset(tx_frontend_core_200::DEFAULT_DC_OFFSET_VALUE);
    _tx_fe_core->set_iq_balance(tx_frontend_core_200::DEFAULT_IQ_BALANCE_VALUE);
    _tx_fe_core->populate_subtree(get_tree()->subtree(FE_PATH / "tx_fe_corrections" / 0));

    RFNOC_LOG_TRACE("Initializing RX frontend DSP core...")
    _rx_fe_core = rx_frontend_core_3000::make(_wb_iface, n320_regs::SR_TX_FE_BASE);
    _rx_fe_core->set_adc_rate(_master_clock_rate);
    _rx_fe_core->set_dc_offset(rx_frontend_core_3000::DEFAULT_DC_OFFSET_VALUE);
    _rx_fe_core->set_dc_offset_auto(rx_frontend_core_3000::DEFAULT_DC_OFFSET_ENABLE);
    _rx_fe_core->set_iq_balance(rx_frontend_core_3000::DEFAULT_IQ_BALANCE_VALUE);
    _rx_fe_core->populate_subtree(get_tree()->subtree(FE_PATH / "rx_fe_corrections" / 0));

    RFNOC_LOG_TRACE("Writing initial gain values...");
    set_tx_gain(RHODIUM_DEFAULT_GAIN, 0);
    set_tx_lo_gain(RHODIUM_DEFAULT_LO_GAIN, RHODIUM_LO1, 0);
    set_rx_gain(RHODIUM_DEFAULT_GAIN, 0);
    set_rx_lo_gain(RHODIUM_DEFAULT_LO_GAIN, RHODIUM_LO1, 0);

    RFNOC_LOG_TRACE("Initializing TX LO...");
    _tx_lo = lmx2592_iface::make(
        _generate_write_spi(this->_spi, SEN_TX_LO, _get_tx_lo_spi_config()),
        _generate_read_spi(this->_spi, SEN_TX_LO, _get_tx_lo_spi_config()));

    RFNOC_LOG_TRACE("Writing initial TX LO state...");
    _tx_lo->set_reference_frequency(RHODIUM_LO1_REF_FREQ);
    _tx_lo->set_mash_order(RHODIUM_DEFAULT_MASH_ORDER);

    RFNOC_LOG_TRACE("Initializing RX LO...");
    _rx_lo = lmx2592_iface::make(
        _generate_write_spi(this->_spi, SEN_RX_LO, _get_rx_lo_spi_config()),
        _generate_read_spi(this->_spi, SEN_RX_LO, _get_rx_lo_spi_config()));

    RFNOC_LOG_TRACE("Writing initial RX LO state...");
    _rx_lo->set_reference_frequency(RHODIUM_LO1_REF_FREQ);
    _rx_lo->set_mash_order(RHODIUM_DEFAULT_MASH_ORDER);

    RFNOC_LOG_TRACE("Initializing GPIOs...");
    // DB GPIOs
    _gpio = usrp::gpio_atr::gpio_atr_3000::make(_wb_iface,
        n320_regs::SR_DB_GPIO,
        n320_regs::RB_DB_GPIO,
        n320_regs::PERIPH_REG_OFFSET);
    _gpio->set_atr_mode(usrp::gpio_atr::MODE_ATR, // Enable ATR mode for Rhodium bits
        RHODIUM_GPIO_MASK);
    _gpio->set_atr_mode(usrp::gpio_atr::MODE_GPIO, // Disable ATR mode for unused bits
        ~RHODIUM_GPIO_MASK);
    _gpio->set_gpio_ddr(usrp::gpio_atr::DDR_OUTPUT, // Make all GPIOs outputs
        usrp::gpio_atr::gpio_atr_3000::MASK_SET_ALL);
    _fp_gpio = gpio_atr::gpio_atr_3000::make(_wb_iface,
        n320_regs::SR_FP_GPIO,
        n320_regs::RB_FP_GPIO,
        n320_regs::PERIPH_REG_OFFSET);

    RFNOC_LOG_TRACE("Set initial ATR values...");
    _update_atr(RHODIUM_DEFAULT_TX_ANTENNA, TX_DIRECTION);
    _update_atr(RHODIUM_DEFAULT_RX_ANTENNA, RX_DIRECTION);

    // Updating the TX frequency path may include an update to SW10, which is
    // GPIO controlled, so this must follow CPLD and GPIO initialization
    RFNOC_LOG_TRACE("Writing initial switch values...");
    _update_tx_freq_switches(RHODIUM_DEFAULT_FREQ);
    _update_rx_freq_switches(RHODIUM_DEFAULT_FREQ);

    // Antenna setting requires both CPLD and GPIO control
    RFNOC_LOG_TRACE("Setting initial antenna settings");
    _update_tx_output_switches(RHODIUM_DEFAULT_TX_ANTENNA);
    _update_rx_input_switches(RHODIUM_DEFAULT_RX_ANTENNA);

    RFNOC_LOG_TRACE("Checking for existence of LO Distribution board");
    _lo_dist_present =
        _rpcc->request_with_token<bool>(_rpc_prefix + "is_lo_dist_present");
    RFNOC_LOG_DEBUG(
        "LO distribution board is" << (_lo_dist_present ? "" : " NOT") << " present");

    RFNOC_LOG_TRACE("Reading EEPROM content...");
    const size_t db_idx = get_block_id().get_block_count();
    _db_eeprom = this->_rpcc->request_with_token<eeprom_map_t>("get_db_eeprom", db_idx);
}

// Reminder: The property must not own any properties, it can only interact with
// the API of this block!
void rhodium_radio_control_impl::_init_frontend_subtree(uhd::property_tree::sptr subtree)
{
    const fs_path tx_fe_path = fs_path("tx_frontends") / 0;
    const fs_path rx_fe_path = fs_path("rx_frontends") / 0;
    RFNOC_LOG_TRACE("Adding non-RFNoC block properties for channel 0"
                    << " to prop tree path " << tx_fe_path << " and " << rx_fe_path);
    // TX Standard attributes
    subtree->create<std::string>(tx_fe_path / "name").set(RHODIUM_FE_NAME);
    subtree->create<std::string>(tx_fe_path / "connection")
        .add_coerced_subscriber(
            [this](const std::string& conn) { this->_set_tx_fe_connection(conn); })
        .set_publisher([this]() { return this->_get_tx_fe_connection(); });
    subtree->create<device_addr_t>(tx_fe_path / "tune_args")
        .set(device_addr_t())
        .add_coerced_subscriber(
            [this](const device_addr_t& args) { set_tx_tune_args(args, 0); })
        .set_publisher([this]() { return _tune_args.at(uhd::TX_DIRECTION); });
    // RX Standard attributes
    subtree->create<std::string>(rx_fe_path / "name").set(RHODIUM_FE_NAME);
    subtree->create<std::string>(rx_fe_path / "connection")
        .add_coerced_subscriber(
            [this](const std::string& conn) { this->_set_rx_fe_connection(conn); })
        .set_publisher([this]() { return this->_get_rx_fe_connection(); });
    subtree->create<device_addr_t>(rx_fe_path / "tune_args")
        .set(device_addr_t())
        .add_coerced_subscriber(
            [this](const device_addr_t& args) { set_rx_tune_args(args, 0); })
        .set_publisher([this]() { return _tune_args.at(uhd::RX_DIRECTION); });
    ;
    // TX Antenna
    subtree->create<std::string>(tx_fe_path / "antenna" / "value")
        .add_coerced_subscriber(
            [this](const std::string& ant) { this->set_tx_antenna(ant, 0); })
        .set_publisher([this]() { return this->get_tx_antenna(0); });
    subtree->create<std::vector<std::string>>(tx_fe_path / "antenna" / "options")
        .add_coerced_subscriber([](const std::vector<std::string>&) {
            throw uhd::runtime_error("Attempting to update antenna options!");
        })
        .set_publisher([this]() { return get_tx_antennas(0); });
    // RX Antenna
    subtree->create<std::string>(rx_fe_path / "antenna" / "value")
        .add_coerced_subscriber(
            [this](const std::string& ant) { this->set_rx_antenna(ant, 0); })
        .set_publisher([this]() { return this->get_rx_antenna(0); });
    subtree->create<std::vector<std::string>>(rx_fe_path / "antenna" / "options")
        .add_coerced_subscriber([](const std::vector<std::string>&) {
            throw uhd::runtime_error("Attempting to update antenna options!");
        })
        .set_publisher([this]() { return get_rx_antennas(0); });
    // TX frequency
    subtree->create<double>(tx_fe_path / "freq" / "value")
        .set_coercer(
            [this](const double freq) { return this->set_tx_frequency(freq, 0); })
        .set_publisher([this]() { return this->get_tx_frequency(0); });
    subtree->create<meta_range_t>(tx_fe_path / "freq" / "range")
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update freq range!");
        })
        .set_publisher([this]() { return get_tx_frequency_range(0); });
    // RX frequency
    subtree->create<double>(rx_fe_path / "freq" / "value")
        .set_coercer(
            [this](const double freq) { return this->set_rx_frequency(freq, 0); })
        .set_publisher([this]() { return this->get_rx_frequency(0); });
    subtree->create<meta_range_t>(rx_fe_path / "freq" / "range")
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update freq range!");
        })
        .set_publisher([this]() { return get_rx_frequency_range(0); });
    // TX bandwidth
    subtree->create<double>(tx_fe_path / "bandwidth" / "value")
        .set_coercer([this](const double bw) { return this->set_tx_bandwidth(bw, 0); })
        .set_publisher([this]() { return this->get_tx_bandwidth(0); });
    subtree->create<meta_range_t>(tx_fe_path / "bandwidth" / "range")
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update bandwidth range!");
        })
        .set_publisher([this]() { return get_tx_bandwidth_range(0); });
    // RX bandwidth
    subtree->create<double>(rx_fe_path / "bandwidth" / "value")
        .set_coercer([this](const double bw) { return this->set_rx_bandwidth(bw, 0); })
        .set_publisher([this]() { return this->get_rx_bandwidth(0); });
    subtree->create<meta_range_t>(rx_fe_path / "bandwidth" / "range")
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update bandwidth range!");
        })
        .set_publisher([this]() { return get_rx_bandwidth_range(0); });
    // TX gains
    subtree->create<double>(tx_fe_path / "gains" / "all" / "value")
        .set_coercer([this](const double gain) { return this->set_tx_gain(gain, 0); })
        .set_publisher([this]() { return radio_control_impl::get_tx_gain(0); });
    subtree->create<meta_range_t>(tx_fe_path / "gains" / "all" / "range")
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update gain range!");
        })
        .set_publisher([this]() { return get_tx_gain_range(0); });
    // RX gains
    subtree->create<double>(rx_fe_path / "gains" / "all" / "value")
        .set_coercer([this](const double gain) { return this->set_rx_gain(gain, 0); })
        .set_publisher([this]() { return radio_control_impl::get_rx_gain(0); });
    subtree->create<meta_range_t>(rx_fe_path / "gains" / "all" / "range")
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update gain range!");
        })
        .set_publisher([this]() { return get_rx_gain_range(0); });

    // LO Specific
    // RX LO
    // RX LO1 Frequency
    subtree->create<double>(rx_fe_path / "los" / RHODIUM_LO1 / "freq/value")
        .set_publisher([this]() { return this->get_rx_lo_freq(RHODIUM_LO1, 0); })
        .set_coercer([this](const double freq) {
            return this->set_rx_lo_freq(freq, RHODIUM_LO1, 0);
        });
    subtree->create<meta_range_t>(rx_fe_path / "los" / RHODIUM_LO1 / "freq/range")
        .set_publisher([this]() { return this->get_rx_lo_freq_range(RHODIUM_LO1, 0); });
    // RX LO1 Source
    subtree
        ->create<std::vector<std::string>>(
            rx_fe_path / "los" / RHODIUM_LO1 / "source/options")
        .set_publisher([this]() { return this->get_rx_lo_sources(RHODIUM_LO1, 0); });
    subtree->create<std::string>(rx_fe_path / "los" / RHODIUM_LO1 / "source/value")
        .add_coerced_subscriber([this](const std::string& src) {
            this->set_rx_lo_source(src, RHODIUM_LO1, 0);
        })
        .set_publisher([this]() { return this->get_rx_lo_source(RHODIUM_LO1, 0); });
    // RX LO1 Export
    subtree->create<bool>(rx_fe_path / "los" / RHODIUM_LO1 / "export")
        .add_coerced_subscriber([this](bool enabled) {
            this->set_rx_lo_export_enabled(enabled, RHODIUM_LO1, 0);
        });
    // RX LO1 Gain
    subtree
        ->create<double>(
            rx_fe_path / "los" / RHODIUM_LO1 / "gains" / RHODIUM_LO_GAIN / "value")
        .set_publisher([this]() { return this->get_rx_lo_gain(RHODIUM_LO1, 0); })
        .set_coercer([this](const double gain) {
            return this->set_rx_lo_gain(gain, RHODIUM_LO1, 0);
        });
    subtree
        ->create<meta_range_t>(
            rx_fe_path / "los" / RHODIUM_LO1 / "gains" / RHODIUM_LO_GAIN / "range")
        .set_publisher([]() { return rhodium_radio_control_impl::_get_lo_gain_range(); })
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update LO gain range!");
        });
    // RX LO1 Output Power
    subtree
        ->create<double>(
            rx_fe_path / "los" / RHODIUM_LO1 / "gains" / RHODIUM_LO_POWER / "value")
        .set_publisher([this]() { return this->get_rx_lo_power(RHODIUM_LO1, 0); })
        .set_coercer([this](const double gain) {
            return this->set_rx_lo_power(gain, RHODIUM_LO1, 0);
        });
    subtree
        ->create<meta_range_t>(
            rx_fe_path / "los" / RHODIUM_LO1 / "gains" / RHODIUM_LO_POWER / "range")
        .set_publisher([]() { return rhodium_radio_control_impl::_get_lo_power_range(); })
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update LO output power range!");
        });
    // RX LO2 Frequency
    subtree->create<double>(rx_fe_path / "los" / RHODIUM_LO2 / "freq/value")
        .set_publisher([this]() { return this->get_rx_lo_freq(RHODIUM_LO2, 0); })
        .set_coercer(
            [this](double freq) { return this->set_rx_lo_freq(freq, RHODIUM_LO2, 0); });
    subtree->create<meta_range_t>(rx_fe_path / "los" / RHODIUM_LO2 / "freq/range")
        .set_publisher([this]() { return this->get_rx_lo_freq_range(RHODIUM_LO2, 0); });
    // RX LO2 Source
    subtree
        ->create<std::vector<std::string>>(
            rx_fe_path / "los" / RHODIUM_LO2 / "source/options")
        .set_publisher([this]() { return this->get_rx_lo_sources(RHODIUM_LO2, 0); });
    subtree->create<std::string>(rx_fe_path / "los" / RHODIUM_LO2 / "source/value")
        .add_coerced_subscriber(
            [this](std::string src) { this->set_rx_lo_source(src, RHODIUM_LO2, 0); })
        .set_publisher([this]() { return this->get_rx_lo_source(RHODIUM_LO2, 0); });
    // RX LO2 Export
    subtree->create<bool>(rx_fe_path / "los" / RHODIUM_LO2 / "export")
        .add_coerced_subscriber([this](bool enabled) {
            this->set_rx_lo_export_enabled(enabled, RHODIUM_LO2, 0);
        });
    // RX ALL LOs
    subtree->create<std::string>(rx_fe_path / "los" / ALL_LOS / "source/value")
        .add_coerced_subscriber(
            [this](std::string src) { this->set_rx_lo_source(src, ALL_LOS, 0); })
        .set_publisher([this]() { return this->get_rx_lo_source(ALL_LOS, 0); });
    subtree
        ->create<std::vector<std::string>>(
            rx_fe_path / "los" / ALL_LOS / "source/options")
        .set_publisher([this]() { return this->get_rx_lo_sources(ALL_LOS, 0); });
    subtree->create<bool>(rx_fe_path / "los" / ALL_LOS / "export")
        .add_coerced_subscriber(
            [this](bool enabled) { this->set_rx_lo_export_enabled(enabled, ALL_LOS, 0); })
        .set_publisher([this]() { return this->get_rx_lo_export_enabled(ALL_LOS, 0); });
    // TX LO
    // TX LO1 Frequency
    subtree->create<double>(tx_fe_path / "los" / RHODIUM_LO1 / "freq/value ")
        .set_publisher([this]() { return this->get_tx_lo_freq(RHODIUM_LO1, 0); })
        .set_coercer(
            [this](double freq) { return this->set_tx_lo_freq(freq, RHODIUM_LO1, 0); });
    subtree->create<meta_range_t>(tx_fe_path / "los" / RHODIUM_LO1 / "freq/range")
        .set_publisher([this]() { return this->get_rx_lo_freq_range(RHODIUM_LO1, 0); });
    // TX LO1 Source
    subtree
        ->create<std::vector<std::string>>(
            tx_fe_path / "los" / RHODIUM_LO1 / "source/options")
        .set_publisher([this]() { return this->get_tx_lo_sources(RHODIUM_LO1, 0); });
    subtree->create<std::string>(tx_fe_path / "los" / RHODIUM_LO1 / "source/value")
        .add_coerced_subscriber(
            [this](std::string src) { this->set_tx_lo_source(src, RHODIUM_LO1, 0); })
        .set_publisher([this]() { return this->get_tx_lo_source(RHODIUM_LO1, 0); });
    // TX LO1 Export
    subtree->create<bool>(tx_fe_path / "los" / RHODIUM_LO1 / "export")
        .add_coerced_subscriber([this](bool enabled) {
            this->set_tx_lo_export_enabled(enabled, RHODIUM_LO1, 0);
        });
    // TX LO1 Gain
    subtree
        ->create<double>(
            tx_fe_path / "los" / RHODIUM_LO1 / "gains" / RHODIUM_LO_GAIN / "value")
        .set_publisher([this]() { return this->get_tx_lo_gain(RHODIUM_LO1, 0); })
        .set_coercer([this](const double gain) {
            return this->set_tx_lo_gain(gain, RHODIUM_LO1, 0);
        });
    subtree
        ->create<meta_range_t>(
            tx_fe_path / "los" / RHODIUM_LO1 / "gains" / RHODIUM_LO_GAIN / "range")
        .set_publisher([]() { return rhodium_radio_control_impl::_get_lo_gain_range(); })
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update LO gain range!");
        });
    // TX LO1 Output Power
    subtree
        ->create<double>(
            tx_fe_path / "los" / RHODIUM_LO1 / "gains" / RHODIUM_LO_POWER / "value")
        .set_publisher([this]() { return this->get_tx_lo_power(RHODIUM_LO1, 0); })
        .set_coercer([this](const double gain) {
            return this->set_tx_lo_power(gain, RHODIUM_LO1, 0);
        });
    subtree
        ->create<meta_range_t>(
            tx_fe_path / "los" / RHODIUM_LO1 / "gains" / RHODIUM_LO_POWER / "range")
        .set_publisher([]() { return rhodium_radio_control_impl::_get_lo_power_range(); })
        .add_coerced_subscriber([](const meta_range_t&) {
            throw uhd::runtime_error("Attempting to update LO output power range!");
        });
    // TX LO2 Frequency
    subtree->create<double>(tx_fe_path / "los" / RHODIUM_LO2 / "freq/value")
        .set_publisher([this]() { return this->get_tx_lo_freq(RHODIUM_LO2, 0); })
        .set_coercer(
            [this](double freq) { return this->set_tx_lo_freq(freq, RHODIUM_LO2, 0); });
    subtree->create<meta_range_t>(tx_fe_path / "los" / RHODIUM_LO2 / "freq/range")
        .set_publisher([this]() { return this->get_tx_lo_freq_range(RHODIUM_LO2, 0); });
    // TX LO2 Source
    subtree
        ->create<std::vector<std::string>>(
            tx_fe_path / "los" / RHODIUM_LO2 / "source/options")
        .set_publisher([this]() { return this->get_tx_lo_sources(RHODIUM_LO2, 0); });
    subtree->create<std::string>(tx_fe_path / "los" / RHODIUM_LO2 / "source/value")
        .add_coerced_subscriber(
            [this](std::string src) { this->set_tx_lo_source(src, RHODIUM_LO2, 0); })
        .set_publisher([this]() { return this->get_tx_lo_source(RHODIUM_LO2, 0); });
    // TX LO2 Export
    subtree->create<bool>(tx_fe_path / "los" / RHODIUM_LO2 / "export")
        .add_coerced_subscriber([this](bool enabled) {
            this->set_tx_lo_export_enabled(enabled, RHODIUM_LO2, 0);
        });
    // TX ALL LOs
    subtree->create<std::string>(tx_fe_path / "los" / ALL_LOS / "source/value")
        .add_coerced_subscriber(
            [this](std::string src) { this->set_tx_lo_source(src, ALL_LOS, 0); })
        .set_publisher([this]() { return this->get_tx_lo_source(ALL_LOS, 0); });
    subtree
        ->create<std::vector<std::string>>(
            tx_fe_path / "los" / ALL_LOS / "source/options")
        .set_publisher([this]() { return this->get_tx_lo_sources(ALL_LOS, 0); });
    subtree->create<bool>(tx_fe_path / "los" / ALL_LOS / "export")
        .add_coerced_subscriber(
            [this](bool enabled) { this->set_tx_lo_export_enabled(enabled, ALL_LOS, 0); })
        .set_publisher([this]() { return this->get_tx_lo_export_enabled(ALL_LOS, 0); });

    // LO Distribution Output Ports
    if (_lo_dist_present) {
        for (const auto& port : LO_OUTPUT_PORT_NAMES) {
            subtree
                ->create<bool>(tx_fe_path / "los" / RHODIUM_LO1 / "lo_distribution" / port
                               / "export")
                .add_coerced_subscriber([this, port](bool enabled) {
                    this->set_tx_lo_output_enabled(enabled, port, 0);
                })
                .set_publisher(
                    [this, port]() { return this->get_tx_lo_output_enabled(port, 0); });
            subtree
                ->create<bool>(rx_fe_path / "los" / RHODIUM_LO1 / "lo_distribution" / port
                               / "export")
                .add_coerced_subscriber([this, port](bool enabled) {
                    this->set_rx_lo_output_enabled(enabled, port, 0);
                })
                .set_publisher(
                    [this, port]() { return this->get_rx_lo_output_enabled(port, 0); });
        }
    }

    // Sensors
    auto rx_sensor_names = get_rx_sensor_names(0);
    for (const auto& sensor_name : rx_sensor_names) {
        RFNOC_LOG_TRACE("Adding RX sensor " << sensor_name);
        get_tree()
            ->create<sensor_value_t>(rx_fe_path / "sensors" / sensor_name)
            .add_coerced_subscriber([](const sensor_value_t&) {
                throw uhd::runtime_error("Attempting to write to sensor!");
            })
            .set_publisher(
                [this, sensor_name]() { return get_rx_sensor(sensor_name, 0); });
    }
    auto tx_sensor_names = get_tx_sensor_names(0);
    for (const auto& sensor_name : tx_sensor_names) {
        RFNOC_LOG_TRACE("Adding TX sensor " << sensor_name);
        get_tree()
            ->create<sensor_value_t>(tx_fe_path / "sensors" / sensor_name)
            .add_coerced_subscriber([](const sensor_value_t&) {
                throw uhd::runtime_error("Attempting to write to sensor!");
            })
            .set_publisher(
                [this, sensor_name]() { return get_tx_sensor(sensor_name, 0); });
    }
}

void rhodium_radio_control_impl::_init_prop_tree()
{
    this->_init_frontend_subtree(get_tree()->subtree(DB_PATH));
    get_tree()->create<std::string>(fs_path("rx_codecs") / "name").set("ad9695-625");
    get_tree()->create<std::string>(fs_path("tx_codecs") / "name").set("dac37j82");
}

void rhodium_radio_control_impl::_init_mpm()
{
    auto block_args = get_block_args();
    if (block_args.has_key("identify")) {
        const std::string identify_val = block_args.get("identify");
        int identify_duration          = std::atoi(identify_val.c_str());
        if (identify_duration == 0) {
            identify_duration = 5;
        }
        RFNOC_LOG_INFO("Running LED identification process for " << identify_duration
                                                                 << " seconds.");
        _identify_with_leds(identify_duration);
    }

    // Note: MCR gets set during the init() call (prior to this), which takes
    // in arguments from the device args. So if block_args contains a
    // master_clock_rate key, then it should better be whatever the device is
    // configured to do.
    _master_clock_rate =
        _rpcc->request_with_token<double>(_rpc_prefix + "get_master_clock_rate");
    if (block_args.cast<double>("master_clock_rate", _master_clock_rate)
        != _master_clock_rate) {
        throw uhd::runtime_error(
            std::string("Master clock rate mismatch. Device returns ")
            + std::to_string(_master_clock_rate)
            + " MHz, "
              "but should have been "
            + std::to_string(
                  block_args.cast<double>("master_clock_rate", _master_clock_rate))
            + " MHz.");
    }
    RFNOC_LOG_DEBUG("Master Clock Rate is: " << (_master_clock_rate / 1e6) << " MHz.");
    set_tick_rate(_master_clock_rate);
    _n3xx_timekeeper->update_tick_rate(_master_clock_rate);
    radio_control_impl::set_rate(_master_clock_rate);

    // Unlike N310, N320 does not have any MPM sensors.
}