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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
|
//
// Copyright 2010-2016 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include <uhd/property_tree.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/usrp/gpio_defs.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/utils/math.hpp>
#include <uhd/utils/gain_group.hpp>
#include <uhd/usrp/dboard_id.hpp>
#include <uhd/usrp/mboard_eeprom.hpp>
#include <uhd/usrp/dboard_eeprom.hpp>
#include <uhd/convert.hpp>
#include <uhd/utils/soft_register.hpp>
#include <uhdlib/usrp/gpio_defs.hpp>
#include <uhdlib/rfnoc/legacy_compat.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/thread.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace uhd;
using namespace uhd::usrp;
const std::string multi_usrp::ALL_GAINS = "";
const std::string multi_usrp::ALL_LOS = "all";
UHD_INLINE std::string string_vector_to_string(std::vector<std::string> values, std::string delimiter = std::string(" "))
{
std::string out = "";
for (std::vector<std::string>::iterator iter = values.begin(); iter != values.end(); iter++)
{
out += (iter != values.begin() ? delimiter : "") + *iter;
}
return out;
}
#define THROW_GAIN_NAME_ERROR(name,chan,dir) throw uhd::exception::runtime_error( \
(boost::format("%s: gain \"%s\" not found for channel %d.\nAvailable gains: %s\n") % \
__FUNCTION__ % name % chan % string_vector_to_string(get_##dir##_gain_names(chan))).str());
/***********************************************************************
* Helper methods
**********************************************************************/
static void do_samp_rate_warning_message(
double target_rate,
double actual_rate,
const std::string &xx
){
static const double max_allowed_error = 1.0; //Sps
if (std::abs(target_rate - actual_rate) > max_allowed_error){
UHD_LOGGER_WARNING("MULTI_USRP") << boost::format(
"The hardware does not support the requested %s sample rate:\n"
"Target sample rate: %f MSps\n"
"Actual sample rate: %f MSps\n"
) % xx % (target_rate/1e6) % (actual_rate/1e6);
}
}
/*static void do_tune_freq_results_message(
const tune_request_t &tune_req,
const tune_result_t &tune_result,
double actual_freq,
const std::string &xx
){
const double target_freq = tune_req.target_freq;
const double clipped_target_freq = tune_result.clipped_rf_freq;
const double target_rf_freq = tune_result.target_rf_freq;
const double actual_rf_freq = tune_result.actual_rf_freq;
const double target_dsp_freq = tune_result.target_dsp_freq;
const double actual_dsp_freq = tune_result.actual_dsp_freq;
if (tune_req.rf_freq_policy == tune_request_t::POLICY_MANUAL) return;
if (tune_req.dsp_freq_policy == tune_request_t::POLICY_MANUAL) return;
bool requested_freq_success = uhd::math::frequencies_are_equal(target_freq, clipped_target_freq);
bool target_freq_success = uhd::math::frequencies_are_equal(clipped_target_freq, actual_freq);
bool rf_lo_tune_success = uhd::math::frequencies_are_equal(target_rf_freq, actual_rf_freq);
bool dsp_tune_success = uhd::math::frequencies_are_equal(target_dsp_freq, actual_dsp_freq);
if(requested_freq_success and target_freq_success and rf_lo_tune_success
and dsp_tune_success) {
UHD_LOGGER_INFO("MULTI_USRP") << boost::format(
"Successfully tuned to %f MHz\n\n")
% (actual_freq / 1e6);
} else {
boost::format base_message ("Tune Request: %f MHz\n");
base_message % (target_freq / 1e6);
std::string results_string = base_message.str();
if(requested_freq_success and (not rf_lo_tune_success)) {
boost::format rf_lo_message(
" The RF LO does not support the requested frequency:\n"
" Requested LO Frequency: %f MHz\n"
" RF LO Result: %f MHz\n"
" Attempted to use the DSP to reach the requested frequency:\n"
" Desired DSP Frequency: %f MHz\n"
" DSP Result: %f MHz\n"
" Successfully tuned to %f MHz\n\n");
rf_lo_message % (target_rf_freq / 1e6) % (actual_rf_freq / 1e6)
% (target_dsp_freq / 1e6) % (actual_dsp_freq / 1e6)
% (actual_freq / 1e6);
results_string += rf_lo_message.str();
UHD_LOGGER_INFO("MULTI_USRP") << results_string;
return;
}
if(not requested_freq_success) {
boost::format failure_message(
" The requested %s frequency is outside of the system range, and has been clipped:\n"
" Target Frequency: %f MHz\n"
" Clipped Target Frequency: %f MHz\n");
failure_message % xx % (target_freq / 1e6) % (clipped_target_freq / 1e6);
results_string += failure_message.str();
}
if(not rf_lo_tune_success) {
boost::format rf_lo_message(
" The RF LO does not support the requested frequency:\n"
" Requested LO Frequency: %f MHz\n"
" RF LO Result: %f MHz\n"
" Attempted to use the DSP to reach the requested frequency:\n"
" Desired DSP Frequency: %f MHz\n"
" DSP Result: %f MHz\n");
rf_lo_message % (target_rf_freq / 1e6) % (actual_rf_freq / 1e6)
% (target_dsp_freq / 1e6) % (actual_dsp_freq / 1e6);
results_string += rf_lo_message.str();
} else if(not dsp_tune_success) {
boost::format dsp_message(
" The DSP does not support the requested frequency:\n"
" Requested DSP Frequency: %f MHz\n"
" DSP Result: %f MHz\n");
dsp_message % (target_dsp_freq / 1e6) % (actual_dsp_freq / 1e6);
results_string += dsp_message.str();
}
if(target_freq_success) {
boost::format success_message(
" Successfully tuned to %f MHz\n\n");
success_message % (actual_freq / 1e6);
results_string += success_message.str();
} else {
boost::format failure_message(
" Failed to tune to target frequency\n"
" Target Frequency: %f MHz\n"
" Actual Frequency: %f MHz\n\n");
failure_message % (clipped_target_freq / 1e6) % (actual_freq / 1e6);
results_string += failure_message.str();
}
UHD_LOGGER_WARNING("MULTI_USRP") << results_string ;
}
}*/
/*! The CORDIC can be used to shift the baseband below / past the tunable
* limits of the actual RF front-end. The baseband filter, located on the
* daughterboard, however, limits the useful instantaneous bandwidth. We
* allow the user to tune to the edge of the filter, where the roll-off
* begins. This prevents the user from tuning past the point where less
* than half of the spectrum would be useful. */
static meta_range_t make_overall_tune_range(
const meta_range_t &fe_range,
const meta_range_t &dsp_range,
const double bw
){
meta_range_t range;
for(const range_t &sub_range: fe_range){
range.push_back(range_t(
sub_range.start() + std::max(dsp_range.start(), -bw/2),
sub_range.stop() + std::min(dsp_range.stop(), bw/2),
dsp_range.step()
));
}
return range;
}
/***********************************************************************
* Gain helper functions
**********************************************************************/
static double get_gain_value(property_tree::sptr subtree){
return subtree->access<double>("value").get();
}
static void set_gain_value(property_tree::sptr subtree, const double gain){
subtree->access<double>("value").set(gain);
}
static meta_range_t get_gain_range(property_tree::sptr subtree){
return subtree->access<meta_range_t>("range").get();
}
static gain_fcns_t make_gain_fcns_from_subtree(property_tree::sptr subtree){
gain_fcns_t gain_fcns;
gain_fcns.get_range = boost::bind(&get_gain_range, subtree);
gain_fcns.get_value = boost::bind(&get_gain_value, subtree);
gain_fcns.set_value = boost::bind(&set_gain_value, subtree, _1);
return gain_fcns;
}
/***********************************************************************
* Tune Helper Functions
**********************************************************************/
static const double RX_SIGN = +1.0;
static const double TX_SIGN = -1.0;
static tune_result_t tune_xx_subdev_and_dsp(
const double xx_sign,
property_tree::sptr dsp_subtree,
property_tree::sptr rf_fe_subtree,
const tune_request_t &tune_request
){
//------------------------------------------------------------------
//-- calculate the tunable frequency ranges of the system
//------------------------------------------------------------------
freq_range_t tune_range = make_overall_tune_range(
rf_fe_subtree->access<meta_range_t>("freq/range").get(),
dsp_subtree->access<meta_range_t>("freq/range").get(),
rf_fe_subtree->access<double>("bandwidth/value").get()
);
freq_range_t dsp_range = dsp_subtree->access<meta_range_t>("freq/range").get();
freq_range_t rf_range = rf_fe_subtree->access<meta_range_t>("freq/range").get();
double clipped_requested_freq = tune_range.clip(tune_request.target_freq);
//------------------------------------------------------------------
//-- If the RF FE requires an LO offset, build it into the tune request
//------------------------------------------------------------------
/*! The automatically calculated LO offset is only used if the
* 'use_lo_offset' field in the daughterboard property tree is set to TRUE,
* and the tune policy is set to AUTO. To use an LO offset normally, the
* user should specify the MANUAL tune policy and lo_offset as part of the
* tune_request. This lo_offset is based on the requirements of the FE, and
* does not reflect a user-requested lo_offset, which is handled later. */
double lo_offset = 0.0;
if (rf_fe_subtree->exists("use_lo_offset") and
rf_fe_subtree->access<bool>("use_lo_offset").get()){
// If the frontend has lo_offset value and range properties, trust it
// for lo_offset
if (rf_fe_subtree->exists("lo_offset/value")) {
lo_offset = rf_fe_subtree->access<double>("lo_offset/value").get();
}
//If the local oscillator will be in the passband, use an offset.
//But constrain the LO offset by the width of the filter bandwidth.
const double rate = dsp_subtree->access<double>("rate/value").get();
const double bw = rf_fe_subtree->access<double>("bandwidth/value").get();
if (bw > rate) lo_offset = std::min((bw - rate)/2, rate/2);
}
//------------------------------------------------------------------
//-- poke the tune request args into the dboard
//------------------------------------------------------------------
if (rf_fe_subtree->exists("tune_args")) {
rf_fe_subtree->access<device_addr_t>("tune_args").set(tune_request.args);
}
//------------------------------------------------------------------
//-- set the RF frequency depending upon the policy
//------------------------------------------------------------------
double target_rf_freq = 0.0;
switch (tune_request.rf_freq_policy){
case tune_request_t::POLICY_AUTO:
target_rf_freq = clipped_requested_freq + lo_offset;
break;
case tune_request_t::POLICY_MANUAL:
// If the rf_fe understands lo_offset settings, infer the desired
// lo_offset and set it. Side effect: In TVRX2 for example, after
// setting the lo_offset (if_freq) with a POLICY_MANUAL, there is no
// way for the user to automatically get back to default if_freq
// without deconstruct/reconstruct the rf_fe objects.
if (rf_fe_subtree->exists("lo_offset/value")) {
rf_fe_subtree->access<double>("lo_offset/value")
.set(tune_request.rf_freq - tune_request.target_freq);
}
target_rf_freq = rf_range.clip(tune_request.rf_freq);
break;
case tune_request_t::POLICY_NONE:
break; //does not set
}
//------------------------------------------------------------------
//-- Tune the RF frontend
//------------------------------------------------------------------
if (tune_request.rf_freq_policy != tune_request_t::POLICY_NONE) {
rf_fe_subtree->access<double>("freq/value").set(target_rf_freq);
}
const double actual_rf_freq = rf_fe_subtree->access<double>("freq/value").get();
//------------------------------------------------------------------
//-- Set the DSP frequency depending upon the DSP frequency policy.
//------------------------------------------------------------------
double target_dsp_freq = 0.0;
switch (tune_request.dsp_freq_policy) {
case tune_request_t::POLICY_AUTO:
/* If we are using the AUTO tuning policy, then we prevent the
* CORDIC from spinning us outside of the range of the baseband
* filter, regardless of what the user requested. This could happen
* if the user requested a center frequency so far outside of the
* tunable range of the FE that the CORDIC would spin outside the
* filtered baseband. */
target_dsp_freq = actual_rf_freq - clipped_requested_freq;
//invert the sign on the dsp freq for transmit (spinning up vs down)
target_dsp_freq *= xx_sign;
break;
case tune_request_t::POLICY_MANUAL:
/* If the user has specified a manual tune policy, we will allow
* tuning outside of the baseband filter, but will still clip the
* target DSP frequency to within the bounds of the CORDIC to
* prevent undefined behavior (likely an overflow). */
target_dsp_freq = dsp_range.clip(tune_request.dsp_freq);
break;
case tune_request_t::POLICY_NONE:
break; //does not set
}
//------------------------------------------------------------------
//-- Tune the DSP
//------------------------------------------------------------------
if (tune_request.dsp_freq_policy != tune_request_t::POLICY_NONE) {
dsp_subtree->access<double>("freq/value").set(target_dsp_freq);
}
const double actual_dsp_freq = dsp_subtree->access<double>("freq/value").get();
//------------------------------------------------------------------
//-- Load and return the tune result
//------------------------------------------------------------------
tune_result_t tune_result;
tune_result.clipped_rf_freq = clipped_requested_freq;
tune_result.target_rf_freq = target_rf_freq;
tune_result.actual_rf_freq = actual_rf_freq;
tune_result.target_dsp_freq = target_dsp_freq;
tune_result.actual_dsp_freq = actual_dsp_freq;
return tune_result;
}
static double derive_freq_from_xx_subdev_and_dsp(
const double xx_sign,
property_tree::sptr dsp_subtree,
property_tree::sptr rf_fe_subtree
){
//extract actual dsp and IF frequencies
const double actual_rf_freq = rf_fe_subtree->access<double>("freq/value").get();
const double actual_dsp_freq = dsp_subtree->access<double>("freq/value").get();
//invert the sign on the dsp freq for transmit
return actual_rf_freq - actual_dsp_freq * xx_sign;
}
/***********************************************************************
* Multi USRP Implementation
**********************************************************************/
class multi_usrp_impl : public multi_usrp{
public:
multi_usrp_impl(const device_addr_t &addr){
_dev = device::make(addr, device::USRP);
_tree = _dev->get_tree();
_is_device3 = bool(boost::dynamic_pointer_cast<uhd::device3>(_dev));
if (is_device3()) {
_legacy_compat = rfnoc::legacy_compat::make(get_device3(), addr);
}
}
device::sptr get_device(void){
return _dev;
}
bool is_device3(void) {
return _is_device3;
}
device3::sptr get_device3(void) {
if (not is_device3()) {
throw uhd::type_error("Cannot call get_device3() on a non-generation 3 device.");
}
return boost::dynamic_pointer_cast<uhd::device3>(_dev);
}
dict<std::string, std::string> get_usrp_rx_info(size_t chan){
mboard_chan_pair mcp = rx_chan_to_mcp(chan);
dict<std::string, std::string> usrp_info;
mboard_eeprom_t mb_eeprom = _tree->access<mboard_eeprom_t>(mb_root(mcp.mboard) / "eeprom").get();
dboard_eeprom_t db_eeprom = _tree->access<dboard_eeprom_t>(rx_rf_fe_root(chan).branch_path().branch_path() / "rx_eeprom").get();
usrp_info["mboard_id"] = _tree->access<std::string>(mb_root(mcp.mboard) / "name").get();
usrp_info["mboard_name"] = mb_eeprom["name"];
usrp_info["mboard_serial"] = mb_eeprom["serial"];
usrp_info["rx_id"] = db_eeprom.id.to_pp_string();
usrp_info["rx_subdev_name"] = _tree->access<std::string>(rx_rf_fe_root(chan) / "name").get();
usrp_info["rx_subdev_spec"] = _tree->access<subdev_spec_t>(mb_root(mcp.mboard) / "rx_subdev_spec").get().to_string();
usrp_info["rx_serial"] = db_eeprom.serial;
usrp_info["rx_antenna"] = _tree->access<std::string>(rx_rf_fe_root(chan) / "antenna" / "value").get();
return usrp_info;
}
dict<std::string, std::string> get_usrp_tx_info(size_t chan){
mboard_chan_pair mcp = tx_chan_to_mcp(chan);
dict<std::string, std::string> usrp_info;
mboard_eeprom_t mb_eeprom = _tree->access<mboard_eeprom_t>(mb_root(mcp.mboard) / "eeprom").get();
dboard_eeprom_t db_eeprom = _tree->access<dboard_eeprom_t>(tx_rf_fe_root(chan).branch_path().branch_path() / "tx_eeprom").get();
usrp_info["mboard_id"] = _tree->access<std::string>(mb_root(mcp.mboard) / "name").get();
usrp_info["mboard_name"] = mb_eeprom["name"];
usrp_info["mboard_serial"] = mb_eeprom["serial"];
usrp_info["tx_id"] = db_eeprom.id.to_pp_string();
usrp_info["tx_subdev_name"] = _tree->access<std::string>(tx_rf_fe_root(chan) / "name").get();
usrp_info["tx_subdev_spec"] = _tree->access<subdev_spec_t>(mb_root(mcp.mboard) / "tx_subdev_spec").get().to_string();
usrp_info["tx_serial"] = db_eeprom.serial;
usrp_info["tx_antenna"] = _tree->access<std::string>(tx_rf_fe_root(chan) / "antenna" / "value").get();
return usrp_info;
}
/*******************************************************************
* Mboard methods
******************************************************************/
void set_master_clock_rate(double rate, size_t mboard){
if (mboard != ALL_MBOARDS){
if (_tree->exists(mb_root(mboard) / "auto_tick_rate")
and _tree->access<bool>(mb_root(mboard) / "auto_tick_rate").get()) {
_tree->access<bool>(mb_root(mboard) / "auto_tick_rate").set(false);
UHD_LOGGER_INFO("MULTI_USRP") << "Setting master clock rate selection to 'manual'.";
}
_tree->access<double>(mb_root(mboard) / "tick_rate").set(rate);
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
set_master_clock_rate(rate, m);
}
}
double get_master_clock_rate(size_t mboard){
return _tree->access<double>(mb_root(mboard) / "tick_rate").get();
}
std::string get_pp_string(void){
std::string buff = str(boost::format(
"%s USRP:\n"
" Device: %s\n"
)
% ((get_num_mboards() > 1)? "Multi" : "Single")
% (_tree->access<std::string>("/name").get())
);
for (size_t m = 0; m < get_num_mboards(); m++){
buff += str(boost::format(
" Mboard %d: %s\n"
) % m
% (_tree->access<std::string>(mb_root(m) / "name").get())
);
}
//----------- rx side of life ----------------------------------
for (size_t m = 0, chan = 0; m < get_num_mboards(); m++){
for (; chan < (m + 1)*get_rx_subdev_spec(m).size(); chan++){
buff += str(boost::format(
" RX Channel: %u\n"
" RX DSP: %s\n"
" RX Dboard: %s\n"
" RX Subdev: %s\n"
) % chan
% rx_dsp_root(chan).leaf()
% rx_rf_fe_root(chan).branch_path().branch_path().leaf()
% (_tree->access<std::string>(rx_rf_fe_root(chan) / "name").get())
);
}
}
//----------- tx side of life ----------------------------------
for (size_t m = 0, chan = 0; m < get_num_mboards(); m++){
for (; chan < (m + 1)*get_tx_subdev_spec(m).size(); chan++){
buff += str(boost::format(
" TX Channel: %u\n"
" TX DSP: %s\n"
" TX Dboard: %s\n"
" TX Subdev: %s\n"
) % chan
% tx_dsp_root(chan).leaf()
% tx_rf_fe_root(chan).branch_path().branch_path().leaf()
% (_tree->access<std::string>(tx_rf_fe_root(chan) / "name").get())
);
}
}
return buff;
}
std::string get_mboard_name(size_t mboard){
return _tree->access<std::string>(mb_root(mboard) / "name").get();
}
time_spec_t get_time_now(size_t mboard = 0){
return _tree->access<time_spec_t>(mb_root(mboard) / "time/now").get();
}
time_spec_t get_time_last_pps(size_t mboard = 0){
return _tree->access<time_spec_t>(mb_root(mboard) / "time/pps").get();
}
void set_time_now(const time_spec_t &time_spec, size_t mboard){
if (mboard != ALL_MBOARDS){
_tree->access<time_spec_t>(mb_root(mboard) / "time/now").set(time_spec);
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
set_time_now(time_spec, m);
}
}
void set_time_next_pps(const time_spec_t &time_spec, size_t mboard){
if (mboard != ALL_MBOARDS){
_tree->access<time_spec_t>(mb_root(mboard) / "time/pps").set(time_spec);
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
set_time_next_pps(time_spec, m);
}
}
void set_time_unknown_pps(const time_spec_t &time_spec){
UHD_LOGGER_INFO("MULTI_USRP") << " 1) catch time transition at pps edge";
boost::system_time end_time = boost::get_system_time() + boost::posix_time::milliseconds(1100);
time_spec_t time_start_last_pps = get_time_last_pps();
while (time_start_last_pps == get_time_last_pps())
{
if (boost::get_system_time() > end_time)
{
throw uhd::runtime_error(
"Board 0 may not be getting a PPS signal!\n"
"No PPS detected within the time interval.\n"
"See the application notes for your device.\n"
);
}
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
}
UHD_LOGGER_INFO("MULTI_USRP") << " 2) set times next pps (synchronously)";
set_time_next_pps(time_spec, ALL_MBOARDS);
boost::this_thread::sleep(boost::posix_time::seconds(1));
//verify that the time registers are read to be within a few RTT
for (size_t m = 1; m < get_num_mboards(); m++){
time_spec_t time_0 = this->get_time_now(0);
time_spec_t time_i = this->get_time_now(m);
if (time_i < time_0 or (time_i - time_0) > time_spec_t(0.01)){ //10 ms: greater than RTT but not too big
UHD_LOGGER_WARNING("MULTI_USRP") << boost::format(
"Detected time deviation between board %d and board 0.\n"
"Board 0 time is %f seconds.\n"
"Board %d time is %f seconds.\n"
) % m % time_0.get_real_secs() % m % time_i.get_real_secs();
}
}
}
bool get_time_synchronized(void){
for (size_t m = 1; m < get_num_mboards(); m++){
time_spec_t time_0 = this->get_time_now(0);
time_spec_t time_i = this->get_time_now(m);
if (time_i < time_0 or (time_i - time_0) > time_spec_t(0.01)) return false;
}
return true;
}
void set_command_time(const time_spec_t &time_spec, size_t mboard){
if (mboard != ALL_MBOARDS){
if (not _tree->exists(mb_root(mboard) / "time/cmd")){
throw uhd::not_implemented_error("timed command feature not implemented on this hardware");
}
_tree->access<time_spec_t>(mb_root(mboard) / "time/cmd").set(time_spec);
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
set_command_time(time_spec, m);
}
}
void clear_command_time(size_t mboard){
if (mboard != ALL_MBOARDS){
_tree->access<time_spec_t>(mb_root(mboard) / "time/cmd").set(time_spec_t(0.0));
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
clear_command_time(m);
}
}
void issue_stream_cmd(const stream_cmd_t &stream_cmd, size_t chan){
if (chan != ALL_CHANS){
if (is_device3()) {
mboard_chan_pair mcp = rx_chan_to_mcp(chan);
_legacy_compat->issue_stream_cmd(stream_cmd, mcp.mboard, mcp.chan);
} else {
_tree->access<stream_cmd_t>(rx_dsp_root(chan) / "stream_cmd").set(stream_cmd);
}
return;
}
for (size_t c = 0; c < get_rx_num_channels(); c++){
issue_stream_cmd(stream_cmd, c);
}
}
void set_clock_config(const clock_config_t &clock_config, size_t mboard){
//set the reference source...
std::string clock_source;
switch(clock_config.ref_source){
case clock_config_t::REF_INT: clock_source = "internal"; break;
case clock_config_t::REF_SMA: clock_source = "external"; break;
case clock_config_t::REF_MIMO: clock_source = "mimo"; break;
default: clock_source = "unknown";
}
this->set_clock_source(clock_source, mboard);
//set the time source
std::string time_source;
switch(clock_config.pps_source){
case clock_config_t::PPS_INT: time_source = "internal"; break;
case clock_config_t::PPS_SMA: time_source = "external"; break;
case clock_config_t::PPS_MIMO: time_source = "mimo"; break;
default: time_source = "unknown";
}
if (time_source == "external" and clock_config.pps_polarity == clock_config_t::PPS_NEG) time_source = "_external_";
this->set_time_source(time_source, mboard);
}
void set_time_source(const std::string &source, const size_t mboard){
if (mboard != ALL_MBOARDS){
_tree->access<std::string>(mb_root(mboard) / "time_source" / "value").set(source);
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
this->set_time_source(source, m);
}
}
std::string get_time_source(const size_t mboard){
return _tree->access<std::string>(mb_root(mboard) / "time_source" / "value").get();
}
std::vector<std::string> get_time_sources(const size_t mboard){
return _tree->access<std::vector<std::string> >(mb_root(mboard) / "time_source" / "options").get();
}
void set_clock_source(const std::string &source, const size_t mboard){
if (mboard != ALL_MBOARDS){
_tree->access<std::string>(mb_root(mboard) / "clock_source" / "value").set(source);
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
this->set_clock_source(source, m);
}
}
std::string get_clock_source(const size_t mboard){
return _tree->access<std::string>(mb_root(mboard) / "clock_source" / "value").get();
}
std::vector<std::string> get_clock_sources(const size_t mboard){
return _tree->access<std::vector<std::string> >(mb_root(mboard) / "clock_source" / "options").get();
}
void set_clock_source_out(const bool enb, const size_t mboard)
{
if (mboard != ALL_MBOARDS)
{
if (_tree->exists(mb_root(mboard) / "clock_source" / "output"))
{
_tree->access<bool>(mb_root(mboard) / "clock_source" / "output").set(enb);
}
else
{
throw uhd::runtime_error("multi_usrp::set_clock_source_out - not supported on this device");
}
return;
}
for (size_t m = 0; m < get_num_mboards(); m++)
{
this->set_clock_source_out(enb, m);
}
}
void set_time_source_out(const bool enb, const size_t mboard)
{
if (mboard != ALL_MBOARDS)
{
if (_tree->exists(mb_root(mboard) / "time_source" / "output"))
{
_tree->access<bool>(mb_root(mboard) / "time_source" / "output").set(enb);
}
else
{
throw uhd::runtime_error("multi_usrp::set_time_source_out - not supported on this device");
}
return;
}
for (size_t m = 0; m < get_num_mboards(); m++)
{
this->set_time_source_out(enb, m);
}
}
size_t get_num_mboards(void){
return _tree->list("/mboards").size();
}
sensor_value_t get_mboard_sensor(const std::string &name, size_t mboard){
return _tree->access<sensor_value_t>(mb_root(mboard) / "sensors" / name).get();
}
std::vector<std::string> get_mboard_sensor_names(size_t mboard){
return _tree->list(mb_root(mboard) / "sensors");
}
void set_user_register(const uint8_t addr, const uint32_t data, size_t mboard){
if (mboard != ALL_MBOARDS){
typedef std::pair<uint8_t, uint32_t> user_reg_t;
_tree->access<user_reg_t>(mb_root(mboard) / "user/regs").set(user_reg_t(addr, data));
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
set_user_register(addr, data, m);
}
}
/*******************************************************************
* RX methods
******************************************************************/
rx_streamer::sptr get_rx_stream(const stream_args_t &args) {
_check_link_rate(args, false);
if (is_device3()) {
return _legacy_compat->get_rx_stream(args);
}
return this->get_device()->get_rx_stream(args);
}
void set_rx_subdev_spec(const subdev_spec_t &spec, size_t mboard){
if (mboard != ALL_MBOARDS){
_tree->access<subdev_spec_t>(mb_root(mboard) / "rx_subdev_spec").set(spec);
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
set_rx_subdev_spec(spec, m);
}
}
subdev_spec_t get_rx_subdev_spec(size_t mboard)
{
subdev_spec_t spec = _tree->access<subdev_spec_t>(mb_root(mboard) / "rx_subdev_spec").get();
if (spec.empty())
{
try
{
const std::string db_name = _tree->list(mb_root(mboard) / "dboards").at(0);
const std::string fe_name = _tree->list(mb_root(mboard) / "dboards" / db_name / "rx_frontends").at(0);
spec.push_back(subdev_spec_pair_t(db_name, fe_name));
_tree->access<subdev_spec_t>(mb_root(mboard) / "rx_subdev_spec").set(spec);
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::get_rx_subdev_spec(%u) failed to make default spec - %s") % mboard % e.what()));
}
UHD_LOGGER_INFO("MULTI_USRP") << "Selecting default RX front end spec: " << spec.to_pp_string();
}
return spec;
}
size_t get_rx_num_channels(void){
size_t sum = 0;
for (size_t m = 0; m < get_num_mboards(); m++){
sum += get_rx_subdev_spec(m).size();
}
return sum;
}
std::string get_rx_subdev_name(size_t chan){
return _tree->access<std::string>(rx_rf_fe_root(chan) / "name").get();
}
void set_rx_rate(double rate, size_t chan){
if (is_device3()) {
_legacy_compat->set_rx_rate(rate, chan);
if (chan == ALL_CHANS) {
for (size_t c = 0; c < get_rx_num_channels(); c++){
do_samp_rate_warning_message(rate, get_rx_rate(c), "RX");
}
} else {
do_samp_rate_warning_message(rate, get_rx_rate(chan), "RX");
}
return;
}
if (chan != ALL_CHANS){
_tree->access<double>(rx_dsp_root(chan) / "rate" / "value").set(rate);
do_samp_rate_warning_message(rate, get_rx_rate(chan), "RX");
return;
}
for (size_t c = 0; c < get_rx_num_channels(); c++){
set_rx_rate(rate, c);
}
}
double get_rx_rate(size_t chan){
return _tree->access<double>(rx_dsp_root(chan) / "rate" / "value").get();
}
meta_range_t get_rx_rates(size_t chan){
return _tree->access<meta_range_t>(rx_dsp_root(chan) / "rate" / "range").get();
}
tune_result_t set_rx_freq(const tune_request_t &tune_request, size_t chan){
tune_result_t result = tune_xx_subdev_and_dsp(RX_SIGN,
_tree->subtree(rx_dsp_root(chan)),
_tree->subtree(rx_rf_fe_root(chan)),
tune_request);
//do_tune_freq_results_message(tune_request, result, get_rx_freq(chan), "RX");
return result;
}
double get_rx_freq(size_t chan){
return derive_freq_from_xx_subdev_and_dsp(RX_SIGN, _tree->subtree(rx_dsp_root(chan)), _tree->subtree(rx_rf_fe_root(chan)));
}
freq_range_t get_rx_freq_range(size_t chan){
return make_overall_tune_range(
_tree->access<meta_range_t>(rx_rf_fe_root(chan) / "freq" / "range").get(),
_tree->access<meta_range_t>(rx_dsp_root(chan) / "freq" / "range").get(),
this->get_rx_bandwidth(chan)
);
}
freq_range_t get_fe_rx_freq_range(size_t chan){
return _tree->access<meta_range_t>(rx_rf_fe_root(chan) / "freq" / "range").get();
}
/**************************************************************************
* LO controls
*************************************************************************/
std::vector<std::string> get_rx_lo_names(size_t chan = 0){
std::vector<std::string> lo_names;
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
for(const std::string &name: _tree->list(rx_rf_fe_root(chan) / "los")) {
lo_names.push_back(name);
}
}
return lo_names;
}
void set_rx_lo_source(const std::string &src, const std::string &name = ALL_LOS, size_t chan = 0){
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
if (_tree->exists(rx_rf_fe_root(chan) / "los" / ALL_LOS)) {
//Special value ALL_LOS support atomically sets the source for all LOs
_tree->access<std::string>(rx_rf_fe_root(chan) / "los" / ALL_LOS / "source" / "value").set(src);
} else {
for(const std::string &n: _tree->list(rx_rf_fe_root(chan) / "los")) {
this->set_rx_lo_source(src, n, chan);
}
}
} else {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
_tree->access<std::string>(rx_rf_fe_root(chan) / "los" / name / "source" / "value").set(src);
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
throw uhd::runtime_error("This device does not support manual configuration of LOs");
}
}
const std::string get_rx_lo_source(const std::string &name = ALL_LOS, size_t chan = 0){
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
//Special value ALL_LOS support atomically sets the source for all LOs
return _tree->access<std::string>(rx_rf_fe_root(chan) / "los" / ALL_LOS / "source" / "value").get();
} else {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
return _tree->access<std::string>(rx_rf_fe_root(chan) / "los" / name / "source" / "value").get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
// If the daughterboard doesn't expose it's LO(s) then it can only be internal
return "internal";
}
}
std::vector<std::string> get_rx_lo_sources(const std::string &name = ALL_LOS, size_t chan = 0) {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
if (_tree->exists(rx_rf_fe_root(chan) / "los" / ALL_LOS)) {
//Special value ALL_LOS support atomically sets the source for all LOs
return _tree->access< std::vector<std::string> >(rx_rf_fe_root(chan) / "los" / ALL_LOS / "source" / "options").get();
} else {
return std::vector<std::string>();
}
} else {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
return _tree->access< std::vector<std::string> >(rx_rf_fe_root(chan) / "los" / name / "source" / "options").get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
// If the daughterboard doesn't expose it's LO(s) then it can only be internal
return std::vector<std::string>(1, "internal");
}
}
void set_rx_lo_export_enabled(bool enabled, const std::string &name = ALL_LOS, size_t chan = 0){
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
if (_tree->exists(rx_rf_fe_root(chan) / "los" / ALL_LOS)) {
//Special value ALL_LOS support atomically sets the source for all LOs
_tree->access<bool>(rx_rf_fe_root(chan) / "los" / ALL_LOS / "export").set(enabled);
} else {
for(const std::string &n: _tree->list(rx_rf_fe_root(chan) / "los")) {
this->set_rx_lo_export_enabled(enabled, n, chan);
}
}
} else {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
_tree->access<bool>(rx_rf_fe_root(chan) / "los" / name / "export").set(enabled);
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
throw uhd::runtime_error("This device does not support manual configuration of LOs");
}
}
bool get_rx_lo_export_enabled(const std::string &name = ALL_LOS, size_t chan = 0){
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
//Special value ALL_LOS support atomically sets the source for all LOs
return _tree->access<bool>(rx_rf_fe_root(chan) / "los" / ALL_LOS / "export").get();
} else {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
return _tree->access<bool>(rx_rf_fe_root(chan) / "los" / name / "export").get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
// If the daughterboard doesn't expose it's LO(s), assume it cannot export
return false;
}
}
double set_rx_lo_freq(double freq, const std::string &name = ALL_LOS, size_t chan = 0){
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
throw uhd::runtime_error("LO frequency must be set for each stage individually");
} else {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
_tree->access<double>(rx_rf_fe_root(chan) / "los" / name / "freq" / "value").set(freq);
return _tree->access<double>(rx_rf_fe_root(chan) / "los" / name / "freq" / "value").get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
throw uhd::runtime_error("This device does not support manual configuration of LOs");
}
}
double get_rx_lo_freq(const std::string &name = ALL_LOS, size_t chan = 0){
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
throw uhd::runtime_error("LO frequency must be retrieved for each stage individually");
} else {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
return _tree->access<double>(rx_rf_fe_root(chan) / "los" / name / "freq" / "value").get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
// Return actual RF frequency if the daughterboard doesn't expose it's LO(s)
return _tree->access<double>(rx_rf_fe_root(chan) / "freq" /" value").get();
}
}
freq_range_t get_rx_lo_freq_range(const std::string &name = ALL_LOS, size_t chan = 0){
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
throw uhd::runtime_error("LO frequency range must be retrieved for each stage individually");
} else {
if (_tree->exists(rx_rf_fe_root(chan) / "los")) {
return _tree->access<freq_range_t>(rx_rf_fe_root(chan) / "los" / name / "freq" / "range").get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
// Return the actual RF range if the daughterboard doesn't expose it's LO(s)
return _tree->access<meta_range_t>(rx_rf_fe_root(chan) / "freq" / "range").get();
}
}
std::vector<std::string> get_tx_lo_names(const size_t chan = 0){
std::vector<std::string> lo_names;
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
for (const std::string &name : _tree->list(tx_rf_fe_root(chan) / "los")) {
lo_names.push_back(name);
}
}
return lo_names;
}
void set_tx_lo_source(
const std::string &src,
const std::string &name = ALL_LOS,
const size_t chan = 0
) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
if (_tree->exists(tx_rf_fe_root(chan) / "los" / ALL_LOS)) {
// Special value ALL_LOS support atomically sets the source
// for all LOs
_tree->access<std::string>(
tx_rf_fe_root(chan) / "los" / ALL_LOS /
"source" / "value"
).set(src);
} else {
for (const auto &n : _tree->list(tx_rf_fe_root(chan) / "los")) {
this->set_tx_lo_source(src, n, chan);
}
}
} else {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
_tree->access<std::string>(
tx_rf_fe_root(chan) / "los" / name / "source" /
"value"
).set(src);
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
throw uhd::runtime_error("This device does not support manual "
"configuration of LOs");
}
}
const std::string get_tx_lo_source(
const std::string &name = ALL_LOS,
const size_t chan = 0
) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
return _tree->access<std::string>(
tx_rf_fe_root(chan) / "los" / name / "source" / "value"
).get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
} else {
// If the daughterboard doesn't expose its LO(s) then it can only
// be internal
return "internal";
}
}
std::vector<std::string> get_tx_lo_sources(
const std::string &name = ALL_LOS,
const size_t chan = 0
) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
if (_tree->exists(tx_rf_fe_root(chan) / "los" / ALL_LOS)) {
// Special value ALL_LOS support atomically sets the source
// for all LOs
return _tree->access<std::vector<std::string>>(
tx_rf_fe_root(chan) / "los" / ALL_LOS /
"source" / "options"
).get();
} else {
return std::vector<std::string>();
}
} else {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
return _tree->access< std::vector<std::string> >(tx_rf_fe_root(chan) / "los" / name / "source" / "options").get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
// If the daughterboard doesn't expose its LO(s) then it can only
// be internal
return std::vector<std::string>(1, "internal");
}
}
void set_tx_lo_export_enabled(
const bool enabled,
const std::string &name = ALL_LOS,
const size_t chan=0
) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
if (_tree->exists(tx_rf_fe_root(chan) / "los" / ALL_LOS)) {
//Special value ALL_LOS support atomically sets the source for all LOs
_tree->access<bool>(tx_rf_fe_root(chan) / "los" / ALL_LOS / "export").set(enabled);
} else {
for(const std::string &n: _tree->list(tx_rf_fe_root(chan) / "los")) {
this->set_tx_lo_export_enabled(enabled, n, chan);
}
}
} else {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
_tree->access<bool>(tx_rf_fe_root(chan) / "los" / name / "export").set(enabled);
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
throw uhd::runtime_error("This device does not support manual configuration of LOs");
}
}
bool get_tx_lo_export_enabled(
const std::string &name = ALL_LOS,
const size_t chan = 0
) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
return _tree->access<bool>(
tx_rf_fe_root(chan) / "los" / name / "export"
).get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
} else {
// If the daughterboard doesn't expose its LO(s), assume it cannot
// export
return false;
}
}
double set_tx_lo_freq(
const double freq,
const std::string &name = ALL_LOS,
const size_t chan = 0
) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
throw uhd::runtime_error("LO frequency must be set for each "
"stage individually");
} else {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
return _tree->access<double>(
tx_rf_fe_root(chan) / "los" / name / "freq" / "value"
).set(freq).get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
throw uhd::runtime_error("This device does not support manual "
"configuration of LOs");
}
}
double get_tx_lo_freq(
const std::string &name = ALL_LOS,
const size_t chan = 0
) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
throw uhd::runtime_error("LO frequency must be retrieved for "
"each stage individually");
} else {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
return _tree->access<double>(tx_rf_fe_root(chan) / "los" / name / "freq" / "value").get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
// Return actual RF frequency if the daughterboard doesn't expose
// its LO(s)
return _tree->access<double>(
tx_rf_fe_root(chan) / "freq" /" value"
).get();
}
}
freq_range_t get_tx_lo_freq_range(
const std::string &name = ALL_LOS,
const size_t chan = 0
) {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
if (name == ALL_LOS) {
throw uhd::runtime_error("LO frequency range must be retrieved "
"for each stage individually");
} else {
if (_tree->exists(tx_rf_fe_root(chan) / "los")) {
return _tree->access<freq_range_t>(
tx_rf_fe_root(chan) / "los" / name / "freq" / "range"
).get();
} else {
throw uhd::runtime_error("Could not find LO stage " + name);
}
}
} else {
// Return the actual RF range if the daughterboard doesn't expose
// its LO(s)
return _tree->access<meta_range_t>(
tx_rf_fe_root(chan) / "freq" / "range"
).get();
}
}
/**************************************************************************
* Gain control
*************************************************************************/
void set_rx_gain(double gain, const std::string &name, size_t chan){
/* Check if any AGC mode is enable and if so warn the user */
if (chan != ALL_CHANS) {
if (_tree->exists(rx_rf_fe_root(chan) / "gain" / "agc")) {
bool agc = _tree->access<bool>(rx_rf_fe_root(chan) / "gain" / "agc" / "enable").get();
if(agc) {
UHD_LOGGER_WARNING("MULTI_USRP") << "AGC enabled for this channel. Setting will be ignored." ;
}
}
} else {
for (size_t c = 0; c < get_rx_num_channels(); c++){
if (_tree->exists(rx_rf_fe_root(c) / "gain" / "agc")) {
bool agc = _tree->access<bool>(rx_rf_fe_root(chan) / "gain" / "agc" / "enable").get();
if(agc) {
UHD_LOGGER_WARNING("MULTI_USRP") << "AGC enabled for this channel. Setting will be ignored." ;
}
}
}
}
/* Apply gain setting.
* If device is in AGC mode it will ignore the setting. */
try {
return rx_gain_group(chan)->set_value(gain, name);
} catch (uhd::key_error &) {
THROW_GAIN_NAME_ERROR(name,chan,rx);
}
}
void set_rx_gain_profile(const std::string& profile, const size_t chan){
if (chan != ALL_CHANS) {
if (_tree->exists(rx_rf_fe_root(chan) / "gains/all/profile/value")) {
_tree->access<std::string>(rx_rf_fe_root(chan) / "gains/all/profile/value").set(profile);
}
} else {
for (size_t c = 0; c < get_rx_num_channels(); c++){
if (_tree->exists(rx_rf_fe_root(c) / "gains/all/profile/value")) {
_tree->access<std::string>(rx_rf_fe_root(chan) / "gains/all/profile/value").set(profile);
}
}
}
}
std::string get_rx_gain_profile(const size_t chan)
{
if (chan != ALL_CHANS) {
if (_tree->exists(rx_rf_fe_root(chan) / "gains/all/profile/value")) {
return _tree->access<std::string>(
rx_rf_fe_root(chan) / "gains/all/profile/value"
).get();
}
} else {
throw uhd::runtime_error("Can't get RX gain profile from "
"all channels at once!");
}
return "";
}
std::vector<std::string> get_rx_gain_profile_names(const size_t chan)
{
if (chan != ALL_CHANS) {
if (_tree->exists(rx_rf_fe_root(chan) / "gains/all/profile/options")) {
return _tree->access<std::vector<std::string>>(
rx_rf_fe_root(chan) / "gains/all/profile/options"
).get();
}
} else {
throw uhd::runtime_error("Can't get RX gain profile names from "
"all channels at once!");
}
return std::vector<std::string>();
}
void set_normalized_rx_gain(double gain, size_t chan = 0)
{
if (gain > 1.0 || gain < 0.0) {
throw uhd::runtime_error("Normalized gain out of range, "
"must be in [0, 1].");
}
const gain_range_t gain_range = get_rx_gain_range(ALL_GAINS, chan);
const double abs_gain =
(gain * (gain_range.stop() - gain_range.start()))
+ gain_range.start();
set_rx_gain(abs_gain, ALL_GAINS, chan);
}
void set_rx_agc(bool enable, size_t chan = 0)
{
if (chan != ALL_CHANS){
if (_tree->exists(rx_rf_fe_root(chan) / "gain" / "agc" / "enable")) {
_tree->access<bool>(rx_rf_fe_root(chan) / "gain" / "agc" / "enable").set(enable);
} else {
UHD_LOGGER_WARNING("MULTI_USRP") << "AGC is not available on this device." ;
}
return;
}
for (size_t c = 0; c < get_rx_num_channels(); c++){
this->set_rx_agc(enable, c);
}
}
double get_rx_gain(const std::string &name, size_t chan){
try {
return rx_gain_group(chan)->get_value(name);
} catch (uhd::key_error &) {
THROW_GAIN_NAME_ERROR(name,chan,rx);
}
}
double get_normalized_rx_gain(size_t chan)
{
gain_range_t gain_range = get_rx_gain_range(ALL_GAINS, chan);
double gain_range_width = gain_range.stop() - gain_range.start();
// In case we have a device without a range of gains:
if (gain_range_width == 0.0) {
return 0;
}
double norm_gain = (get_rx_gain(ALL_GAINS, chan) - gain_range.start()) / gain_range_width;
// Avoid rounding errors:
if (norm_gain > 1.0) return 1.0;
if (norm_gain < 0.0) return 0.0;
return norm_gain;
}
gain_range_t get_rx_gain_range(const std::string &name, size_t chan){
try {
return rx_gain_group(chan)->get_range(name);
} catch (uhd::key_error &) {
THROW_GAIN_NAME_ERROR(name,chan,rx);
}
}
std::vector<std::string> get_rx_gain_names(size_t chan){
return rx_gain_group(chan)->get_names();
}
void set_rx_antenna(const std::string &ant, size_t chan){
_tree->access<std::string>(rx_rf_fe_root(chan) / "antenna" / "value").set(ant);
}
std::string get_rx_antenna(size_t chan){
return _tree->access<std::string>(rx_rf_fe_root(chan) / "antenna" / "value").get();
}
std::vector<std::string> get_rx_antennas(size_t chan){
return _tree->access<std::vector<std::string> >(rx_rf_fe_root(chan) / "antenna" / "options").get();
}
void set_rx_bandwidth(double bandwidth, size_t chan){
_tree->access<double>(rx_rf_fe_root(chan) / "bandwidth" / "value").set(bandwidth);
}
double get_rx_bandwidth(size_t chan){
return _tree->access<double>(rx_rf_fe_root(chan) / "bandwidth" / "value").get();
}
meta_range_t get_rx_bandwidth_range(size_t chan){
return _tree->access<meta_range_t>(rx_rf_fe_root(chan) / "bandwidth" / "range").get();
}
dboard_iface::sptr get_rx_dboard_iface(size_t chan){
return _tree->access<dboard_iface::sptr>(rx_rf_fe_root(chan).branch_path().branch_path() / "iface").get();
}
sensor_value_t get_rx_sensor(const std::string &name, size_t chan){
return _tree->access<sensor_value_t>(rx_rf_fe_root(chan) / "sensors" / name).get();
}
std::vector<std::string> get_rx_sensor_names(size_t chan){
std::vector<std::string> sensor_names;
if (_tree->exists(rx_rf_fe_root(chan) / "sensors")) {
sensor_names = _tree->list(rx_rf_fe_root(chan) / "sensors");
}
return sensor_names;
}
void set_rx_dc_offset(const bool enb, size_t chan){
if (chan != ALL_CHANS){
if (_tree->exists(rx_fe_root(chan) / "dc_offset" / "enable")) {
_tree->access<bool>(rx_fe_root(chan) / "dc_offset" / "enable").set(enb);
} else if (_tree->exists(rx_rf_fe_root(chan) / "dc_offset" / "enable")) {
/*For B2xx devices the dc-offset correction is implemented in the rf front-end*/
_tree->access<bool>(rx_rf_fe_root(chan) / "dc_offset" / "enable").set(enb);
} else {
UHD_LOGGER_WARNING("MULTI_USRP") << "Setting DC offset compensation is not possible on this device." ;
}
return;
}
for (size_t c = 0; c < get_rx_num_channels(); c++){
this->set_rx_dc_offset(enb, c);
}
}
void set_rx_dc_offset(const std::complex<double> &offset, size_t chan){
if (chan != ALL_CHANS){
if (_tree->exists(rx_fe_root(chan) / "dc_offset" / "value")) {
_tree->access<std::complex<double> >(rx_fe_root(chan) / "dc_offset" / "value").set(offset);
} else {
UHD_LOGGER_WARNING("MULTI_USRP") << "Setting DC offset is not possible on this device." ;
}
return;
}
for (size_t c = 0; c < get_rx_num_channels(); c++){
this->set_rx_dc_offset(offset, c);
}
}
void set_rx_iq_balance(const bool enb, size_t chan){
if (chan != ALL_CHANS){
if (_tree->exists(rx_rf_fe_root(chan) / "iq_balance" / "enable")) {
_tree->access<bool>(rx_rf_fe_root(chan) / "iq_balance" / "enable").set(enb);
} else {
UHD_LOGGER_WARNING("MULTI_USRP") << "Setting IQ imbalance compensation is not possible on this device." ;
}
return;
}
for (size_t c = 0; c < get_rx_num_channels(); c++){
this->set_rx_iq_balance(enb, c);
}
}
void set_rx_iq_balance(const std::complex<double> &offset, size_t chan){
if (chan != ALL_CHANS){
if (_tree->exists(rx_fe_root(chan) / "iq_balance" / "value")) {
_tree->access<std::complex<double> >(rx_fe_root(chan) / "iq_balance" / "value").set(offset);
} else {
UHD_LOGGER_WARNING("MULTI_USRP") << "Setting IQ balance is not possible on this device." ;
}
return;
}
for (size_t c = 0; c < get_rx_num_channels(); c++){
this->set_rx_iq_balance(offset, c);
}
}
std::vector<std::string> get_filter_names(const std::string &search_mask)
{
std::vector<std::string> ret;
for (size_t chan = 0; chan < get_rx_num_channels(); chan++){
if (_tree->exists(rx_rf_fe_root(chan) / "filters")) {
std::vector<std::string> names = _tree->list(rx_rf_fe_root(chan) / "filters");
for(size_t i = 0; i < names.size(); i++)
{
std::string name = rx_rf_fe_root(chan) / "filters" / names[i];
if((search_mask.empty()) or boost::contains(name, search_mask)) {
ret.push_back(name);
}
}
}
if (_tree->exists(rx_dsp_root(chan) / "filters")) {
std::vector<std::string> names = _tree->list(rx_dsp_root(chan) / "filters");
for(size_t i = 0; i < names.size(); i++)
{
std::string name = rx_dsp_root(chan) / "filters" / names[i];
if((search_mask.empty()) or (boost::contains(name, search_mask))) {
ret.push_back(name);
}
}
}
}
for (size_t chan = 0; chan < get_tx_num_channels(); chan++){
if (_tree->exists(tx_rf_fe_root(chan) / "filters")) {
std::vector<std::string> names = _tree->list(tx_rf_fe_root(chan) / "filters");
for(size_t i = 0; i < names.size(); i++)
{
std::string name = tx_rf_fe_root(chan) / "filters" / names[i];
if((search_mask.empty()) or (boost::contains(name, search_mask))) {
ret.push_back(name);
}
}
}
if (_tree->exists(rx_dsp_root(chan) / "filters")) {
std::vector<std::string> names = _tree->list(tx_dsp_root(chan) / "filters");
for(size_t i = 0; i < names.size(); i++)
{
std::string name = tx_dsp_root(chan) / "filters" / names[i];
if((search_mask.empty()) or (boost::contains(name, search_mask))) {
ret.push_back(name);
}
}
}
}
return ret;
}
filter_info_base::sptr get_filter(const std::string &path)
{
std::vector<std::string> possible_names = get_filter_names("");
std::vector<std::string>::iterator it;
it = find(possible_names.begin(), possible_names.end(), path);
if (it == possible_names.end()) {
throw uhd::runtime_error("Attempting to get non-existing filter: "+path);
}
return _tree->access<filter_info_base::sptr>(path / "value").get();
}
void set_filter(const std::string &path, filter_info_base::sptr filter)
{
std::vector<std::string> possible_names = get_filter_names("");
std::vector<std::string>::iterator it;
it = find(possible_names.begin(), possible_names.end(), path);
if (it == possible_names.end()) {
throw uhd::runtime_error("Attempting to set non-existing filter: "+path);
}
_tree->access<filter_info_base::sptr>(path / "value").set(filter);
}
/*******************************************************************
* TX methods
******************************************************************/
tx_streamer::sptr get_tx_stream(const stream_args_t &args) {
_check_link_rate(args, true);
if (is_device3()) {
return _legacy_compat->get_tx_stream(args);
}
return this->get_device()->get_tx_stream(args);
}
void set_tx_subdev_spec(const subdev_spec_t &spec, size_t mboard){
if (mboard != ALL_MBOARDS){
_tree->access<subdev_spec_t>(mb_root(mboard) / "tx_subdev_spec").set(spec);
return;
}
for (size_t m = 0; m < get_num_mboards(); m++){
set_tx_subdev_spec(spec, m);
}
}
subdev_spec_t get_tx_subdev_spec(size_t mboard)
{
subdev_spec_t spec = _tree->access<subdev_spec_t>(mb_root(mboard) / "tx_subdev_spec").get();
if (spec.empty())
{
try
{
const std::string db_name = _tree->list(mb_root(mboard) / "dboards").at(0);
const std::string fe_name = _tree->list(mb_root(mboard) / "dboards" / db_name / "tx_frontends").at(0);
spec.push_back(subdev_spec_pair_t(db_name, fe_name));
_tree->access<subdev_spec_t>(mb_root(mboard) / "tx_subdev_spec").set(spec);
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::get_tx_subdev_spec(%u) failed to make default spec - %s") % mboard % e.what()));
}
UHD_LOGGER_INFO("MULTI_USRP") << "Selecting default TX front end spec: " << spec.to_pp_string();
}
return spec;
}
size_t get_tx_num_channels(void){
size_t sum = 0;
for (size_t m = 0; m < get_num_mboards(); m++){
sum += get_tx_subdev_spec(m).size();
}
return sum;
}
std::string get_tx_subdev_name(size_t chan){
return _tree->access<std::string>(tx_rf_fe_root(chan) / "name").get();
}
void set_tx_rate(double rate, size_t chan){
if (is_device3()) {
_legacy_compat->set_tx_rate(rate, chan);
if (chan == ALL_CHANS) {
for (size_t c = 0; c < get_tx_num_channels(); c++){
do_samp_rate_warning_message(rate, get_tx_rate(c), "TX");
}
} else {
do_samp_rate_warning_message(rate, get_tx_rate(chan), "TX");
}
return;
}
if (chan != ALL_CHANS){
_tree->access<double>(tx_dsp_root(chan) / "rate" / "value").set(rate);
do_samp_rate_warning_message(rate, get_tx_rate(chan), "TX");
return;
}
for (size_t c = 0; c < get_tx_num_channels(); c++){
set_tx_rate(rate, c);
}
}
double get_tx_rate(size_t chan){
return _tree->access<double>(tx_dsp_root(chan) / "rate" / "value").get();
}
meta_range_t get_tx_rates(size_t chan){
return _tree->access<meta_range_t>(tx_dsp_root(chan) / "rate" / "range").get();
}
tune_result_t set_tx_freq(const tune_request_t &tune_request, size_t chan){
tune_result_t result = tune_xx_subdev_and_dsp(TX_SIGN,
_tree->subtree(tx_dsp_root(chan)),
_tree->subtree(tx_rf_fe_root(chan)),
tune_request);
//do_tune_freq_results_message(tune_request, result, get_tx_freq(chan), "TX");
return result;
}
double get_tx_freq(size_t chan){
return derive_freq_from_xx_subdev_and_dsp(TX_SIGN, _tree->subtree(tx_dsp_root(chan)), _tree->subtree(tx_rf_fe_root(chan)));
}
freq_range_t get_tx_freq_range(size_t chan){
return make_overall_tune_range(
_tree->access<meta_range_t>(tx_rf_fe_root(chan) / "freq" / "range").get(),
_tree->access<meta_range_t>(tx_dsp_root(chan) / "freq" / "range").get(),
this->get_tx_bandwidth(chan)
);
}
freq_range_t get_fe_tx_freq_range(size_t chan){
return _tree->access<meta_range_t>(tx_rf_fe_root(chan) / "freq" / "range").get();
}
void set_tx_gain(double gain, const std::string &name, size_t chan){
try {
return tx_gain_group(chan)->set_value(gain, name);
} catch (uhd::key_error &) {
THROW_GAIN_NAME_ERROR(name,chan,tx);
}
}
void set_tx_gain_profile(const std::string& profile, const size_t chan){
if (chan != ALL_CHANS) {
if (_tree->exists(tx_rf_fe_root(chan) / "gains/all/profile/value")) {
_tree->access<std::string>(tx_rf_fe_root(chan) / "gains/all/profile/value").set(profile);
}
} else {
for (size_t c = 0; c < get_tx_num_channels(); c++){
if (_tree->exists(tx_rf_fe_root(c) / "gains/all/profile/value")) {
_tree->access<std::string>(tx_rf_fe_root(chan) / "gains/all/profile/value").set(profile);
}
}
}
}
std::string get_tx_gain_profile(const size_t chan)
{
if (chan != ALL_CHANS) {
if (_tree->exists(tx_rf_fe_root(chan) / "gains/all/profile/value")) {
return _tree->access<std::string>(
tx_rf_fe_root(chan) / "gains/all/profile/value"
).get();
}
} else {
throw uhd::runtime_error("Can't get TX gain profile from "
"all channels at once!");
}
return "";
}
std::vector<std::string> get_tx_gain_profile_names(const size_t chan)
{
if (chan != ALL_CHANS) {
if (_tree->exists(tx_rf_fe_root(chan) / "gains/all/profile/options")) {
return _tree->access<std::vector<std::string>>(
tx_rf_fe_root(chan) / "gains/all/profile/options"
).get();
}
} else {
throw uhd::runtime_error("Can't get TX gain profile names from "
"all channels at once!");
}
return std::vector<std::string>();
}
void set_normalized_tx_gain(double gain, size_t chan = 0)
{
if (gain > 1.0 || gain < 0.0) {
throw uhd::runtime_error("Normalized gain out of range, must be in [0, 1].");
}
gain_range_t gain_range = get_tx_gain_range(ALL_GAINS, chan);
double abs_gain = (gain * (gain_range.stop() - gain_range.start())) + gain_range.start();
set_tx_gain(abs_gain, ALL_GAINS, chan);
}
double get_tx_gain(const std::string &name, size_t chan){
try {
return tx_gain_group(chan)->get_value(name);
} catch (uhd::key_error &) {
THROW_GAIN_NAME_ERROR(name,chan,tx);
}
}
double get_normalized_tx_gain(size_t chan)
{
gain_range_t gain_range = get_tx_gain_range(ALL_GAINS, chan);
double gain_range_width = gain_range.stop() - gain_range.start();
// In case we have a device without a range of gains:
if (gain_range_width == 0.0) {
return 0.0;
}
double norm_gain = (get_tx_gain(ALL_GAINS, chan) - gain_range.start()) / gain_range_width;
// Avoid rounding errors:
if (norm_gain > 1.0) return 1.0;
if (norm_gain < 0.0) return 0.0;
return norm_gain;
}
gain_range_t get_tx_gain_range(const std::string &name, size_t chan){
try {
return tx_gain_group(chan)->get_range(name);
} catch (uhd::key_error &) {
THROW_GAIN_NAME_ERROR(name,chan,tx);
}
}
std::vector<std::string> get_tx_gain_names(size_t chan){
return tx_gain_group(chan)->get_names();
}
void set_tx_antenna(const std::string &ant, size_t chan){
_tree->access<std::string>(tx_rf_fe_root(chan) / "antenna" / "value").set(ant);
}
std::string get_tx_antenna(size_t chan){
return _tree->access<std::string>(tx_rf_fe_root(chan) / "antenna" / "value").get();
}
std::vector<std::string> get_tx_antennas(size_t chan){
return _tree->access<std::vector<std::string> >(tx_rf_fe_root(chan) / "antenna" / "options").get();
}
void set_tx_bandwidth(double bandwidth, size_t chan){
_tree->access<double>(tx_rf_fe_root(chan) / "bandwidth" / "value").set(bandwidth);
}
double get_tx_bandwidth(size_t chan){
return _tree->access<double>(tx_rf_fe_root(chan) / "bandwidth" / "value").get();
}
meta_range_t get_tx_bandwidth_range(size_t chan){
return _tree->access<meta_range_t>(tx_rf_fe_root(chan) / "bandwidth" / "range").get();
}
dboard_iface::sptr get_tx_dboard_iface(size_t chan){
return _tree->access<dboard_iface::sptr>(tx_rf_fe_root(chan).branch_path().branch_path() / "iface").get();
}
sensor_value_t get_tx_sensor(const std::string &name, size_t chan){
return _tree->access<sensor_value_t>(tx_rf_fe_root(chan) / "sensors" / name).get();
}
std::vector<std::string> get_tx_sensor_names(size_t chan){
std::vector<std::string> sensor_names;
if (_tree->exists(rx_rf_fe_root(chan) / "sensors")) {
sensor_names = _tree->list(tx_rf_fe_root(chan) / "sensors");
}
return sensor_names;
}
void set_tx_dc_offset(const std::complex<double> &offset, size_t chan){
if (chan != ALL_CHANS){
if (_tree->exists(tx_fe_root(chan) / "dc_offset" / "value")) {
_tree->access<std::complex<double> >(tx_fe_root(chan) / "dc_offset" / "value").set(offset);
} else {
UHD_LOGGER_WARNING("MULTI_USRP") << "Setting DC offset is not possible on this device." ;
}
return;
}
for (size_t c = 0; c < get_tx_num_channels(); c++){
this->set_tx_dc_offset(offset, c);
}
}
void set_tx_iq_balance(const std::complex<double> &offset, size_t chan){
if (chan != ALL_CHANS){
if (_tree->exists(tx_fe_root(chan) / "iq_balance" / "value")) {
_tree->access<std::complex<double> >(tx_fe_root(chan) / "iq_balance" / "value").set(offset);
} else {
UHD_LOGGER_WARNING("MULTI_USRP") << "Setting IQ balance is not possible on this device." ;
}
return;
}
for (size_t c = 0; c < get_tx_num_channels(); c++){
this->set_tx_iq_balance(offset, c);
}
}
/*******************************************************************
* GPIO methods
******************************************************************/
std::vector<std::string> get_gpio_banks(const size_t mboard)
{
std::vector<std::string> banks;
if (_tree->exists(mb_root(mboard) / "gpio"))
{
for(const std::string &name: _tree->list(mb_root(mboard) / "gpio"))
{
banks.push_back(name);
}
}
for(const std::string &name: _tree->list(mb_root(mboard) / "dboards"))
{
banks.push_back("RX"+name);
banks.push_back("TX"+name);
}
return banks;
}
void set_gpio_attr(
const std::string &bank,
const std::string &attr,
const uint32_t value,
const uint32_t mask,
const size_t mboard
) {
std::vector<std::string> attr_value;
if (_tree->exists(mb_root(mboard) / "gpio" / bank)) {
if (_tree->exists(mb_root(mboard) / "gpio" / bank / attr)){
const auto attr_type = gpio_atr::gpio_attr_rev_map.at(attr);
switch (attr_type) {
case gpio_atr::GPIO_SRC:
throw uhd::runtime_error(
"Can't set SRC attribute using integer value!"
);
break;
case gpio_atr::GPIO_CTRL:
case gpio_atr::GPIO_DDR: {
attr_value = _tree->access<std::vector<std::string>>(
mb_root(mboard) / "gpio" / bank / attr
).get();
UHD_ASSERT_THROW(attr_value.size() <= 32);
std::bitset<32> bit_mask = std::bitset<32>(mask);
std::bitset<32> bit_value = std::bitset<32>(value);
for (size_t i = 0; i < bit_mask.size(); i++) {
if (bit_mask[i] == 1) {
attr_value[i] = gpio_atr::attr_value_map.at(attr_type).at(bit_value[i]);
}
}
_tree->access<std::vector<std::string>>(
mb_root(mboard) / "gpio" / bank / attr
).set(attr_value);
}
break;
default:{
const uint32_t current = _tree->access<uint32_t>(
mb_root(mboard) / "gpio" / bank / attr).get();
const uint32_t new_value = (current & ~mask) | (value & mask);
_tree->access<uint32_t>(mb_root(mboard) / "gpio" / bank / attr).set(new_value);
}
break;
}
return;
} else {
throw uhd::runtime_error(str(
boost::format("The hardware has no gpio attribute: `%s':\n")
% attr
));
}
}
if (bank.size() > 2 and bank[1] == 'X') {
const std::string name = bank.substr(2);
const dboard_iface::unit_t unit =
(bank[0] == 'R')
? dboard_iface::UNIT_RX
: dboard_iface::UNIT_TX;
auto iface = _tree->access<dboard_iface::sptr>(
mb_root(mboard) / "dboards" / name / "iface").get();
if (attr == gpio_atr::gpio_attr_map.at(gpio_atr::GPIO_CTRL))
iface->set_pin_ctrl(unit, uint16_t(value), uint16_t(mask));
if (attr == gpio_atr::gpio_attr_map.at(gpio_atr::GPIO_DDR))
iface->set_gpio_ddr(unit, uint16_t(value), uint16_t(mask));
if (attr == gpio_atr::gpio_attr_map.at(gpio_atr::GPIO_OUT))
iface->set_gpio_out(unit, uint16_t(value), uint16_t(mask));
if (attr == gpio_atr::gpio_attr_map.at(gpio_atr::GPIO_ATR_0X))
iface->set_atr_reg(unit, gpio_atr::ATR_REG_IDLE, uint16_t(value), uint16_t(mask));
if (attr == gpio_atr::gpio_attr_map.at(gpio_atr::GPIO_ATR_RX))
iface->set_atr_reg(unit, gpio_atr::ATR_REG_RX_ONLY, uint16_t(value), uint16_t(mask));
if (attr == gpio_atr::gpio_attr_map.at(gpio_atr::GPIO_ATR_TX))
iface->set_atr_reg(unit, gpio_atr::ATR_REG_TX_ONLY, uint16_t(value), uint16_t(mask));
if (attr == gpio_atr::gpio_attr_map.at(gpio_atr::GPIO_ATR_XX))
iface->set_atr_reg(unit, gpio_atr::ATR_REG_FULL_DUPLEX, uint16_t(value), uint16_t(mask));
if (attr == gpio_atr::gpio_attr_map.at(gpio_atr::GPIO_SRC)) {
throw uhd::runtime_error("Setting gpio source does not supported in daughter board.");
}
return;
}
throw uhd::runtime_error(str(
boost::format("The hardware has no GPIO bank `%s'")
% bank
));
}
void set_gpio_attr(
const std::string &bank,
const std::string &attr,
const std::string &str_value,
const uint32_t mask,
const size_t mboard
) {
const auto attr_type = gpio_atr::gpio_attr_rev_map.at(attr);
if (_tree->exists(mb_root(mboard) / "gpio" / bank)) {
if (_tree->exists(mb_root(mboard) / "gpio" / bank / attr)) {
switch (attr_type){
case gpio_atr::GPIO_SRC:
case gpio_atr::GPIO_CTRL:
case gpio_atr::GPIO_DDR:{
auto attr_value =
_tree->access<std::vector<std::string>>(
mb_root(mboard) / "gpio" / bank / attr).get();
UHD_ASSERT_THROW(attr_value.size() <= 32);
std::bitset<32> bit_mask = std::bitset<32>(mask);
for (size_t i = 0 ; i < bit_mask.size(); i++) {
if (bit_mask[i] == 1) {
attr_value[i] = str_value;
}
}
_tree->access<std::vector<std::string>>(
mb_root(mboard) / "gpio" / bank / attr
).set(attr_value);
}
break;
default: {
const uint32_t value =
gpio_atr::gpio_attr_value_pair.at(attr).at(str_value) == 0 ? -1 : 0;
const uint32_t current = _tree->access<uint32_t>(
mb_root(mboard) / "gpio" / bank / attr).get();
const uint32_t new_value =
(current & ~mask) | (value & mask);
_tree->access<uint32_t>(
mb_root(mboard) / "gpio" / bank / attr
).set(new_value);
}
break;
}
return;
} else {
throw uhd::runtime_error(str(
boost::format("The hardware has no gpio attribute `%s'")
% attr
));
}
}
// If the bank is not in the prop tree, convert string value to integer
// value and have it handled by the other set_gpio_attr()
const uint32_t value =
gpio_atr::gpio_attr_value_pair.at(attr).at(str_value) == 0
? -1
: 0;
set_gpio_attr(
bank,
attr,
value,
mask,
mboard
);
}
uint32_t get_gpio_attr(
const std::string &bank,
const std::string &attr,
const size_t mboard
) {
std::vector<std::string> str_val;
if (_tree->exists(mb_root(mboard) / "gpio" / bank)) {
if (_tree->exists(mb_root(mboard) / "gpio" / bank / attr)) {
const auto attr_type = gpio_atr::gpio_attr_rev_map.at(attr);
switch (attr_type){
case gpio_atr::GPIO_SRC:
throw uhd::runtime_error("Can't set SRC attribute using integer value");
case gpio_atr::GPIO_CTRL:
case gpio_atr::GPIO_DDR: {
str_val = _tree->access<std::vector<std::string>>(
mb_root(mboard) / "gpio" / bank / attr).get();
uint32_t val = 0;
for(size_t i = 0 ; i < str_val.size() ; i++) {
val += usrp::gpio_atr::gpio_attr_value_pair.at(attr).at(str_val[i]) << i;
}
return val;
}
default:
return uint32_t(_tree->access<uint64_t>(
mb_root(mboard) / "gpio" / bank / attr).get());
}
return 0;
} else {
throw uhd::runtime_error(str(
boost::format("The hardware has no gpio attribute: `%s'")
% attr
));
}
}
if (bank.size() > 2 and bank[1] == 'X') {
const std::string name = bank.substr(2);
const dboard_iface::unit_t unit = (bank[0] == 'R')? dboard_iface::UNIT_RX : dboard_iface::UNIT_TX;
auto iface = _tree->access<dboard_iface::sptr>(
mb_root(mboard) / "dboards" / name / "iface").get();
if (attr == "CTRL") return iface->get_pin_ctrl(unit);
if (attr == "DDR") return iface->get_gpio_ddr(unit);
if (attr == "OUT") return iface->get_gpio_out(unit);
if (attr == "ATR_0X") return iface->get_atr_reg(unit, gpio_atr::ATR_REG_IDLE);
if (attr == "ATR_RX") return iface->get_atr_reg(unit, gpio_atr::ATR_REG_RX_ONLY);
if (attr == "ATR_TX") return iface->get_atr_reg(unit, gpio_atr::ATR_REG_TX_ONLY);
if (attr == "ATR_XX") return iface->get_atr_reg(unit, gpio_atr::ATR_REG_FULL_DUPLEX);
if (attr == "READBACK") return iface->read_gpio(unit);
}
throw uhd::runtime_error(str(
boost::format("The hardware has no gpio bank `%s'")
% bank
));
}
std::vector<std::string> get_gpio_string_attr(
const std::string &bank,
const std::string &attr,
const size_t mboard
) {
const auto attr_type = gpio_atr::gpio_attr_rev_map.at(attr);
auto str_val = std::vector<std::string>(32, gpio_atr::default_attr_value_map.at(attr_type));
if (_tree->exists(mb_root(mboard) / "gpio" / bank)) {
if (_tree->exists(mb_root(mboard) / "gpio" / bank / attr)) {
const auto attr_type = gpio_atr::gpio_attr_rev_map.at(attr);
switch (attr_type){
case gpio_atr::GPIO_SRC:
case gpio_atr::GPIO_CTRL:
case gpio_atr::GPIO_DDR:
return _tree->access<std::vector<std::string>>(mb_root(mboard) / "gpio" / bank / attr).get();
default: {
uint32_t value = uint32_t(_tree->access<uint32_t>(mb_root(mboard) / "gpio" / bank / attr).get());
std::bitset<32> bit_value = std::bitset<32>(value);
for (size_t i = 0; i < bit_value.size(); i++)
{
str_val[i] = bit_value[i] == 0 ? "LOW" : "HIGH";
}
return str_val;
}
}
}
else {
throw uhd::runtime_error(str(
boost::format("The hardware has no gpio attribute: `%s'")
% attr
));
}
}
throw uhd::runtime_error(str(
boost::format("The hardware has no support for given gpio bank name `%s'")
% bank
));
}
void write_register(const std::string &path, const uint32_t field, const uint64_t value, const size_t mboard)
{
if (_tree->exists(mb_root(mboard) / "registers"))
{
uhd::soft_regmap_accessor_t::sptr accessor =
_tree->access<uhd::soft_regmap_accessor_t::sptr>(mb_root(mboard) / "registers").get();
uhd::soft_register_base& reg = accessor->lookup(path);
if (not reg.is_writable()) {
throw uhd::runtime_error("multi_usrp::write_register - register not writable: " + path);
}
switch (reg.get_bitwidth()) {
case 16:
if (reg.is_readable())
uhd::soft_register_base::cast<uhd::soft_reg16_rw_t>(reg).write(field, static_cast<uint16_t>(value));
else
uhd::soft_register_base::cast<uhd::soft_reg16_wo_t>(reg).write(field, static_cast<uint16_t>(value));
break;
case 32:
if (reg.is_readable())
uhd::soft_register_base::cast<uhd::soft_reg32_rw_t>(reg).write(field, static_cast<uint32_t>(value));
else
uhd::soft_register_base::cast<uhd::soft_reg32_wo_t>(reg).write(field, static_cast<uint32_t>(value));
break;
case 64:
if (reg.is_readable())
uhd::soft_register_base::cast<uhd::soft_reg64_rw_t>(reg).write(field, value);
else
uhd::soft_register_base::cast<uhd::soft_reg64_wo_t>(reg).write(field, value);
break;
default:
throw uhd::assertion_error("multi_usrp::write_register - register has invalid bitwidth");
}
} else {
throw uhd::not_implemented_error("multi_usrp::write_register - register IO not supported for this device");
}
}
uint64_t read_register(const std::string &path, const uint32_t field, const size_t mboard)
{
if (_tree->exists(mb_root(mboard) / "registers"))
{
uhd::soft_regmap_accessor_t::sptr accessor =
_tree->access<uhd::soft_regmap_accessor_t::sptr>(mb_root(mboard) / "registers").get();
uhd::soft_register_base& reg = accessor->lookup(path);
if (not reg.is_readable()) {
throw uhd::runtime_error("multi_usrp::read_register - register not readable: " + path);
}
switch (reg.get_bitwidth()) {
case 16:
if (reg.is_writable())
return static_cast<uint64_t>(uhd::soft_register_base::cast<uhd::soft_reg16_rw_t>(reg).read(field));
else
return static_cast<uint64_t>(uhd::soft_register_base::cast<uhd::soft_reg16_ro_t>(reg).read(field));
break;
case 32:
if (reg.is_writable())
return static_cast<uint64_t>(uhd::soft_register_base::cast<uhd::soft_reg32_rw_t>(reg).read(field));
else
return static_cast<uint64_t>(uhd::soft_register_base::cast<uhd::soft_reg32_ro_t>(reg).read(field));
break;
case 64:
if (reg.is_writable())
return uhd::soft_register_base::cast<uhd::soft_reg64_rw_t>(reg).read(field);
else
return uhd::soft_register_base::cast<uhd::soft_reg64_ro_t>(reg).read(field);
break;
default:
throw uhd::assertion_error("multi_usrp::read_register - register has invalid bitwidth: " + path);
}
}
throw uhd::not_implemented_error("multi_usrp::read_register - register IO not supported for this device");
}
std::vector<std::string> enumerate_registers(const size_t mboard)
{
if (_tree->exists(mb_root(mboard) / "registers"))
{
uhd::soft_regmap_accessor_t::sptr accessor =
_tree->access<uhd::soft_regmap_accessor_t::sptr>(mb_root(mboard) / "registers").get();
return accessor->enumerate();
} else {
return std::vector<std::string>();
}
}
register_info_t get_register_info(const std::string &path, const size_t mboard = 0)
{
if (_tree->exists(mb_root(mboard) / "registers"))
{
uhd::soft_regmap_accessor_t::sptr accessor =
_tree->access<uhd::soft_regmap_accessor_t::sptr>(mb_root(mboard) / "registers").get();
uhd::soft_register_base& reg = accessor->lookup(path);
register_info_t info;
info.bitwidth = reg.get_bitwidth();
info.readable = reg.is_readable();
info.writable = reg.is_writable();
return info;
} else {
throw uhd::not_implemented_error("multi_usrp::read_register - register IO not supported for this device");
}
}
private:
device::sptr _dev;
property_tree::sptr _tree;
bool _is_device3;
uhd::rfnoc::legacy_compat::sptr _legacy_compat;
struct mboard_chan_pair{
size_t mboard, chan;
mboard_chan_pair(void): mboard(0), chan(0){}
};
mboard_chan_pair rx_chan_to_mcp(size_t chan){
mboard_chan_pair mcp;
mcp.chan = chan;
for (mcp.mboard = 0; mcp.mboard < get_num_mboards(); mcp.mboard++){
size_t sss = get_rx_subdev_spec(mcp.mboard).size();
if (mcp.chan < sss) break;
mcp.chan -= sss;
}
if (mcp.mboard >= get_num_mboards())
{
throw uhd::index_error(str(boost::format("multi_usrp: RX channel %u out of range for configured RX frontends") % chan));
}
return mcp;
}
mboard_chan_pair tx_chan_to_mcp(size_t chan){
mboard_chan_pair mcp;
mcp.chan = chan;
for (mcp.mboard = 0; mcp.mboard < get_num_mboards(); mcp.mboard++){
size_t sss = get_tx_subdev_spec(mcp.mboard).size();
if (mcp.chan < sss) break;
mcp.chan -= sss;
}
if (mcp.mboard >= get_num_mboards())
{
throw uhd::index_error(str(boost::format("multi_usrp: TX channel %u out of range for configured TX frontends") % chan));
}
return mcp;
}
fs_path mb_root(const size_t mboard)
{
try
{
const std::string tree_path = "/mboards/" + std::to_string(mboard);
if (_tree->exists(tree_path)) {
return tree_path;
} else {
throw uhd::index_error(str(boost::format("multi_usrp::mb_root(%u) - path not found") % mboard));
}
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::mb_root(%u) - %s") % mboard % e.what()));
}
}
fs_path rx_dsp_root(const size_t chan)
{
mboard_chan_pair mcp = rx_chan_to_mcp(chan);
if (is_device3()) {
return _legacy_compat->rx_dsp_root(mcp.mboard, mcp.chan);
}
if (_tree->exists(mb_root(mcp.mboard) / "rx_chan_dsp_mapping")) {
std::vector<size_t> map = _tree->access<std::vector<size_t> >(mb_root(mcp.mboard) / "rx_chan_dsp_mapping").get();
UHD_ASSERT_THROW(map.size() > mcp.chan);
mcp.chan = map[mcp.chan];
}
try
{
const std::string tree_path = mb_root(mcp.mboard) / "rx_dsps" / mcp.chan;
if (_tree->exists(tree_path)) {
return tree_path;
} else {
throw uhd::index_error(str(boost::format("multi_usrp::rx_dsp_root(%u) - mcp(%u) - path not found") % chan % mcp.chan));
}
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::rx_dsp_root(%u) - mcp(%u) - %s") % chan % mcp.chan % e.what()));
}
}
fs_path tx_dsp_root(const size_t chan)
{
mboard_chan_pair mcp = tx_chan_to_mcp(chan);
if (is_device3()) {
return _legacy_compat->tx_dsp_root(mcp.mboard, mcp.chan);
}
if (_tree->exists(mb_root(mcp.mboard) / "tx_chan_dsp_mapping")) {
std::vector<size_t> map = _tree->access<std::vector<size_t> >(mb_root(mcp.mboard) / "tx_chan_dsp_mapping").get();
UHD_ASSERT_THROW(map.size() > mcp.chan);
mcp.chan = map[mcp.chan];
}
try
{
const std::string tree_path = mb_root(mcp.mboard) / "tx_dsps" / mcp.chan;
if (_tree->exists(tree_path)) {
return tree_path;
} else {
throw uhd::index_error(str(boost::format("multi_usrp::tx_dsp_root(%u) - mcp(%u) - path not found") % chan % mcp.chan));
}
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::tx_dsp_root(%u) - mcp(%u) - %s") % chan % mcp.chan % e.what()));
}
}
fs_path rx_fe_root(const size_t chan)
{
mboard_chan_pair mcp = rx_chan_to_mcp(chan);
if (is_device3()) {
return _legacy_compat->rx_fe_root(mcp.mboard, mcp.chan);
}
try
{
const subdev_spec_pair_t spec = get_rx_subdev_spec(mcp.mboard).at(mcp.chan);
return mb_root(mcp.mboard) / "rx_frontends" / spec.db_name;
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::rx_fe_root(%u) - mcp(%u) - %s") % chan % mcp.chan % e.what()));
}
}
fs_path tx_fe_root(const size_t chan)
{
mboard_chan_pair mcp = tx_chan_to_mcp(chan);
if (is_device3()) {
return _legacy_compat->tx_fe_root(mcp.mboard, mcp.chan);
}
try
{
const subdev_spec_pair_t spec = get_tx_subdev_spec(mcp.mboard).at(mcp.chan);
return mb_root(mcp.mboard) / "tx_frontends" / spec.db_name;
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::tx_fe_root(%u) - mcp(%u) - %s") % chan % mcp.chan % e.what()));
}
}
fs_path rx_rf_fe_root(const size_t chan)
{
mboard_chan_pair mcp = rx_chan_to_mcp(chan);
try
{
const subdev_spec_pair_t spec = get_rx_subdev_spec(mcp.mboard).at(mcp.chan);
return mb_root(mcp.mboard) / "dboards" / spec.db_name / "rx_frontends" / spec.sd_name;
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::rx_rf_fe_root(%u) - mcp(%u) - %s") % chan % mcp.chan % e.what()));
}
}
fs_path tx_rf_fe_root(const size_t chan)
{
mboard_chan_pair mcp = tx_chan_to_mcp(chan);
try
{
const subdev_spec_pair_t spec = get_tx_subdev_spec(mcp.mboard).at(mcp.chan);
return mb_root(mcp.mboard) / "dboards" / spec.db_name / "tx_frontends" / spec.sd_name;
}
catch(const std::exception &e)
{
throw uhd::index_error(str(boost::format("multi_usrp::tx_rf_fe_root(%u) - mcp(%u) - %s") % chan % mcp.chan % e.what()));
}
}
gain_group::sptr rx_gain_group(size_t chan){
mboard_chan_pair mcp = rx_chan_to_mcp(chan);
const subdev_spec_pair_t spec = get_rx_subdev_spec(mcp.mboard).at(mcp.chan);
gain_group::sptr gg = gain_group::make();
for(const std::string &name: _tree->list(mb_root(mcp.mboard) / "rx_codecs" / spec.db_name / "gains")){
gg->register_fcns("ADC-"+name, make_gain_fcns_from_subtree(_tree->subtree(mb_root(mcp.mboard) / "rx_codecs" / spec.db_name / "gains" / name)), 0 /* low prio */);
}
for(const std::string &name: _tree->list(rx_rf_fe_root(chan) / "gains")){
gg->register_fcns(name, make_gain_fcns_from_subtree(_tree->subtree(rx_rf_fe_root(chan) / "gains" / name)), 1 /* high prio */);
}
return gg;
}
gain_group::sptr tx_gain_group(size_t chan){
mboard_chan_pair mcp = tx_chan_to_mcp(chan);
const subdev_spec_pair_t spec = get_tx_subdev_spec(mcp.mboard).at(mcp.chan);
gain_group::sptr gg = gain_group::make();
for(const std::string &name: _tree->list(mb_root(mcp.mboard) / "tx_codecs" / spec.db_name / "gains")){
gg->register_fcns("DAC-"+name, make_gain_fcns_from_subtree(_tree->subtree(mb_root(mcp.mboard) / "tx_codecs" / spec.db_name / "gains" / name)), 1 /* high prio */);
}
for(const std::string &name: _tree->list(tx_rf_fe_root(chan) / "gains")){
gg->register_fcns(name, make_gain_fcns_from_subtree(_tree->subtree(tx_rf_fe_root(chan) / "gains" / name)), 0 /* low prio */);
}
return gg;
}
//! \param is_tx True for tx
// Assumption is that all mboards use the same link
// and that the rate sum is evenly distributed among the mboards
bool _check_link_rate(const stream_args_t &args, bool is_tx) {
bool link_rate_is_ok = true;
size_t bytes_per_sample = convert::get_bytes_per_item(args.otw_format.empty() ? "sc16" : args.otw_format);
double max_link_rate = 0;
double sum_rate = 0;
for(const size_t chan: args.channels) {
mboard_chan_pair mcp = is_tx ? tx_chan_to_mcp(chan) : rx_chan_to_mcp(chan);
if (_tree->exists(mb_root(mcp.mboard) / "link_max_rate")) {
max_link_rate = std::max(
max_link_rate,
_tree->access<double>(mb_root(mcp.mboard) / "link_max_rate").get()
);
}
sum_rate += is_tx ? get_tx_rate(chan) : get_rx_rate(chan);
}
sum_rate /= get_num_mboards();
if (max_link_rate > 0 and (max_link_rate / bytes_per_sample) < sum_rate) {
UHD_LOGGER_WARNING("MULTI_USRP") << boost::format(
"The total sum of rates (%f MSps on %u channels) exceeds the maximum capacity of the connection.\n"
"This can cause %s."
) % (sum_rate/1e6) % args.channels.size() % (is_tx ? "underruns (U)" : "overflows (O)") ;
link_rate_is_ok = false;
}
return link_rate_is_ok;
}
};
multi_usrp::~multi_usrp(void){
/* NOP */
}
/***********************************************************************
* The Make Function
**********************************************************************/
multi_usrp::sptr multi_usrp::make(const device_addr_t &dev_addr){
UHD_LOGGER_TRACE("MULTI_USRP") << "multi_usrp::make with args " << dev_addr.to_pp_string() ;
return sptr(new multi_usrp_impl(dev_addr));
}
|