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
|
//
// Copyright 2008,2009 Free Software Foundation, Inc.
//
// This file is part of GNU Radio
//
// GNU Radio is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either asversion 3, or (at your option)
// any later version.
//
// GNU Radio is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with GNU Radio; see the file COPYING. If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street,
// Boston, MA 02110-1301, USA.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <usrp/db_flexrf.h>
#include <db_base_impl.h>
#ifdef HAVE_TIME_H
#include <ctime>
#endif
// d'board i/o pin defs
// Tx and Rx have shared defs, but different i/o regs
#define AUX_RXAGC (1 << 8)
#define POWER_UP (1 << 7) // enables power supply
#define RX_TXN (1 << 6) // Tx only: T/R antenna switch for TX/RX port
#define RX2_RX1N (1 << 6) // Rx only: antenna switch between RX2 and TX/RX port
#define ENABLE (1 << 5) // enables mixer
#define AUX_SEN (1 << 4)
#define AUX_SCLK (1 << 3)
#define PLL_LOCK_DETECT (1 << 2)
#define AUX_SDO (1 << 1)
#define CLOCK_OUT (1 << 0)
flexrf_base::flexrf_base(usrp_basic_sptr _usrp, int which, int _power_on)
: db_base(_usrp, which), d_power_on(_power_on)
{
/*
@param usrp: instance of usrp.source_c
@param which: which side: 0 or 1 corresponding to side A or B respectively
@type which: int
*/
d_first = true;
d_spi_format = SPI_FMT_MSB | SPI_FMT_HDR_0;
usrp()->_write_oe(d_which, 0, 0xffff); // turn off all outputs
_enable_refclk(false); // disable refclk
set_auto_tr(false);
}
flexrf_base::~flexrf_base()
{
delete d_common;
}
void
flexrf_base::_write_all(int R, int control, int N)
{
/*
Write R counter latch, control latch and N counter latch to VCO.
Adds 10ms delay between writing control and N if this is first call.
This is the required power-up sequence.
@param R: 24-bit R counter latch
@type R: int
@param control: 24-bit control latch
@type control: int
@param N: 24-bit N counter latch
@type N: int
*/
timespec t;
t.tv_sec = 0;
t.tv_nsec = 10000000;
_write_R(R);
_write_control(control);
if(d_first) {
//time.sleep(0.010);
nanosleep(&t, NULL);
d_first = false;
}
_write_N(N);
}
void
flexrf_base::_write_control(int control)
{
_write_it((control & ~0x3) | 0);
}
void
flexrf_base::_write_R(int R)
{
_write_it((R & ~0x3) | 1);
}
void
flexrf_base::_write_N(int N)
{
_write_it((N & ~0x3) | 2);
}
void
flexrf_base::_write_it(int v)
{
char s[3];
s[0] = (char)((v >> 16) & 0xff);
s[1] = (char)((v >> 8) & 0xff);
s[2] = (char)(v & 0xff);
std::string str(s, 3);
usrp()->_write_spi(0, d_spi_enable, d_spi_format, str);
}
bool
flexrf_base::_lock_detect()
{
/*
@returns: the value of the VCO/PLL lock detect bit.
@rtype: 0 or 1
*/
if(usrp()->read_io(d_which) & PLL_LOCK_DETECT) {
return true;
}
else { // Give it a second chance
// FIXME: make portable sleep
timespec t;
t.tv_sec = 0;
t.tv_nsec = 100000000;
nanosleep(&t, NULL);
if(usrp()->read_io(d_which) & PLL_LOCK_DETECT) {
return true;
}
else {
return false;
}
}
}
bool
flexrf_base::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
/*
Determine values of R, control, and N registers, along with actual freq.
@param freq: target frequency in Hz
@type freq: float
@returns: (R, control, N, actual_freq)
@rtype: tuple(int, int, int, float)
Override this in derived classes.
*/
//raise NotImplementedError;
throw std::runtime_error("_compute_regs called from flexrf_base\n");
}
int
flexrf_base::_compute_control_reg()
{
return d_common->_compute_control_reg();
}
int
flexrf_base::_refclk_divisor()
{
return d_common->_refclk_divisor();
}
struct freq_result_t
flexrf_base::set_freq(double freq)
{
/*
@returns (ok, actual_baseband_freq) where:
ok is True or False and indicates success or failure,
actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
*/
struct freq_result_t args = {false, 0};
// Offsetting the LO helps get the Tx carrier leakage out of the way.
// This also ensures that on Rx, we're not getting hosed by the
// FPGA's DC removal loop's time constant. We were seeing a
// problem when running with discontinuous transmission.
// Offsetting the LO made the problem go away.
freq += d_lo_offset;
int R, control, N;
double actual_freq;
_compute_regs(freq, R, control, N, actual_freq);
if(R==0) {
return args;
}
_write_all(R, control, N);
args.ok = _lock_detect();
args.baseband_freq = actual_freq;
return args;
}
bool
flexrf_base::_set_pga(float pga_gain)
{
if(d_which == 0) {
usrp()->set_pga(0, pga_gain);
usrp()->set_pga(1, pga_gain);
}
else {
usrp()->set_pga(2, pga_gain);
usrp()->set_pga(3, pga_gain);
}
return true;
}
bool
flexrf_base::is_quadrature()
{
/*
Return True if this board requires both I & Q analog channels.
This bit of info is useful when setting up the USRP Rx mux register.
*/
return true;
}
double
flexrf_base::freq_min()
{
return d_common->freq_min();
}
double
flexrf_base::freq_max()
{
return d_common->freq_max();
}
// ----------------------------------------------------------------
flexrf_base_tx::flexrf_base_tx(usrp_basic_sptr _usrp, int which, int _power_on)
: flexrf_base(_usrp, which, _power_on)
{
/*
@param usrp: instance of usrp.sink_c
@param which: 0 or 1 corresponding to side TX_A or TX_B respectively.
*/
if(which == 0) {
d_spi_enable = SPI_ENABLE_TX_A;
}
else {
d_spi_enable = SPI_ENABLE_TX_B;
}
// power up the transmit side, but don't enable the mixer
usrp()->_write_oe(d_which,(POWER_UP|RX_TXN|ENABLE), 0xffff);
usrp()->write_io(d_which, (power_on()|RX_TXN), (POWER_UP|RX_TXN|ENABLE));
set_lo_offset(4e6);
set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
}
flexrf_base_tx::~flexrf_base_tx()
{
shutdown();
}
void
flexrf_base_tx::shutdown()
{
// fprintf(stderr, "flexrf_base_tx::shutdown d_is_shutdown = %d\n", d_is_shutdown);
if (!d_is_shutdown){
d_is_shutdown = true;
// do whatever there is to do to shutdown
// Power down and leave the T/R switch in the R position
usrp()->write_io(d_which, (power_off()|RX_TXN), (POWER_UP|RX_TXN|ENABLE));
// Power down VCO/PLL
d_PD = 3;
_write_control(_compute_control_reg());
_enable_refclk(false); // turn off refclk
set_auto_tr(false);
}
}
bool
flexrf_base_tx::set_auto_tr(bool on)
{
bool ok = true;
if(on) {
ok &= set_atr_mask (RX_TXN | ENABLE);
ok &= set_atr_txval(0 | ENABLE);
ok &= set_atr_rxval(RX_TXN | 0);
}
else {
ok &= set_atr_mask (0);
ok &= set_atr_txval(0);
ok &= set_atr_rxval(0);
}
return ok;
}
bool
flexrf_base_tx::set_enable(bool on)
{
/*
Enable transmitter if on is true
*/
int v;
int mask = RX_TXN | ENABLE;
if(on) {
v = ENABLE;
}
else {
v = RX_TXN;
}
return usrp()->write_io(d_which, v, mask);
}
float
flexrf_base_tx::gain_min()
{
return usrp()->pga_max();
}
float
flexrf_base_tx::gain_max()
{
return usrp()->pga_max();
}
float
flexrf_base_tx::gain_db_per_step()
{
return 1;
}
bool
flexrf_base_tx::set_gain(float gain)
{
/*
Set the gain.
@param gain: gain in decibels
@returns True/False
*/
return _set_pga(usrp()->pga_max());
}
/**************************************************************************/
flexrf_base_rx::flexrf_base_rx(usrp_basic_sptr _usrp, int which, int _power_on)
: flexrf_base(_usrp, which, _power_on)
{
/*
@param usrp: instance of usrp.source_c
@param which: 0 or 1 corresponding to side RX_A or RX_B respectively.
*/
if(which == 0) {
d_spi_enable = SPI_ENABLE_RX_A;
}
else {
d_spi_enable = SPI_ENABLE_RX_B;
}
usrp()->_write_oe(d_which, (POWER_UP|RX2_RX1N|ENABLE), 0xffff);
usrp()->write_io(d_which, (power_on()|RX2_RX1N|ENABLE),
(POWER_UP|RX2_RX1N|ENABLE));
// set up for RX on TX/RX port
select_rx_antenna("TX/RX");
bypass_adc_buffers(true);
set_lo_offset(-4e6);
}
flexrf_base_rx::~flexrf_base_rx()
{
shutdown();
}
void
flexrf_base_rx::shutdown()
{
// fprintf(stderr, "flexrf_base_rx::shutdown d_is_shutdown = %d\n", d_is_shutdown);
if (!d_is_shutdown){
d_is_shutdown = true;
// do whatever there is to do to shutdown
// Power down
usrp()->common_write_io(C_RX, d_which, power_off(), (POWER_UP|ENABLE));
// Power down VCO/PLL
d_PD = 3;
// fprintf(stderr, "flexrf_base_rx::shutdown before _write_control\n");
_write_control(_compute_control_reg());
// fprintf(stderr, "flexrf_base_rx::shutdown before _enable_refclk\n");
_enable_refclk(false); // turn off refclk
// fprintf(stderr, "flexrf_base_rx::shutdown before set_auto_tr\n");
set_auto_tr(false);
// fprintf(stderr, "flexrf_base_rx::shutdown after set_auto_tr\n");
}
}
bool
flexrf_base_rx::set_auto_tr(bool on)
{
bool ok = true;
if(on) {
ok &= set_atr_mask (ENABLE);
ok &= set_atr_txval( 0);
ok &= set_atr_rxval(ENABLE);
}
else {
ok &= set_atr_mask (0);
ok &= set_atr_txval(0);
ok &= set_atr_rxval(0);
}
return true;
}
bool
flexrf_base_rx::select_rx_antenna(int which_antenna)
{
/*
Specify which antenna port to use for reception.
@param which_antenna: either 'TX/RX' or 'RX2'
*/
if(which_antenna == 0) {
usrp()->write_io(d_which, 0,RX2_RX1N);
}
else if(which_antenna == 1) {
usrp()->write_io(d_which, RX2_RX1N, RX2_RX1N);
}
else {
return false;
// throw std::invalid_argument("which_antenna must be either 'TX/RX' or 'RX2'\n");
}
return true;
}
bool
flexrf_base_rx::select_rx_antenna(const std::string &which_antenna)
{
/*
Specify which antenna port to use for reception.
@param which_antenna: either 'TX/RX' or 'RX2'
*/
if(which_antenna == "TX/RX") {
usrp()->write_io(d_which, 0, RX2_RX1N);
}
else if(which_antenna == "RX2") {
usrp()->write_io(d_which, RX2_RX1N, RX2_RX1N);
}
else {
// throw std::invalid_argument("which_antenna must be either 'TX/RX' or 'RX2'\n");
return false;
}
return true;
}
bool
flexrf_base_rx::set_gain(float gain)
{
/*
Set the gain.
@param gain: gain in decibels
@returns True/False
*/
// clamp gain
gain = std::max(gain_min(), std::min(gain, gain_max()));
float pga_gain, agc_gain;
float V_maxgain, V_mingain, V_fullscale, dac_value;
float maxgain = gain_max() - usrp()->pga_max();
float mingain = gain_min();
if(gain > maxgain) {
pga_gain = gain-maxgain;
assert(pga_gain <= usrp()->pga_max());
agc_gain = maxgain;
}
else {
pga_gain = 0;
agc_gain = gain;
}
V_maxgain = .2;
V_mingain = 1.2;
V_fullscale = 3.3;
dac_value = (agc_gain*(V_maxgain-V_mingain)/(maxgain-mingain) + V_mingain)*4096/V_fullscale;
assert(dac_value>=0 && dac_value<4096);
return (usrp()->write_aux_dac(d_which, 0, int(dac_value))
&& _set_pga(int(pga_gain)));
}
// ----------------------------------------------------------------
_AD4360_common::_AD4360_common()
{
// R-Register Common Values
d_R_RSV = 0; // bits 23,22
d_BSC = 3; // bits 21,20 Div by 8 to be safe
d_TEST = 0; // bit 19
d_LDP = 1; // bit 18
d_ABP = 0; // bit 17,16 3ns
// N-Register Common Values
d_N_RSV = 0; // bit 7
// Control Register Common Values
d_PD = 0; // bits 21,20 Normal operation
d_PL = 0; // bits 13,12 11mA
d_MTLD = 1; // bit 11 enabled
d_CPG = 0; // bit 10 CP setting 1
d_CP3S = 0; // bit 9 Normal
d_PDP = 1; // bit 8 Positive
d_MUXOUT = 1; // bits 7:5 Digital Lock Detect
d_CR = 0; // bit 4 Normal
d_PC = 1; // bits 3,2 Core power 10mA
}
_AD4360_common::~_AD4360_common()
{
}
bool
_AD4360_common::_compute_regs(double refclk_freq, double freq, int &retR,
int &retcontrol, int &retN, double &retfreq)
{
/*
Determine values of R, control, and N registers, along with actual freq.
@param freq: target frequency in Hz
@type freq: float
@returns: (R, control, N, actual_freq)
@rtype: tuple(int, int, int, float)
*/
// Band-specific N-Register Values
//float phdet_freq = _refclk_freq()/d_R_DIV;
double phdet_freq = refclk_freq/d_R_DIV;
double desired_n = round(freq*d_freq_mult/phdet_freq);
double actual_freq = desired_n * phdet_freq;
int B = floor(desired_n/_prescaler());
int A = desired_n - _prescaler()*B;
d_B_DIV = int(B); // bits 20:8
d_A_DIV = int(A); // bit 6:2
//assert db_B_DIV >= db_A_DIV
if(d_B_DIV < d_A_DIV) {
retR = 0;
retcontrol = 0;
retN = 0;
retfreq = 0;
return false;
}
int R = (d_R_RSV<<22) | (d_BSC<<20) | (d_TEST<<19) |
(d_LDP<<18) | (d_ABP<<16) | (d_R_DIV<<2);
int control = _compute_control_reg();
int N = (d_DIVSEL<<23) | (d_DIV2<<22) | (d_CPGAIN<<21) |
(d_B_DIV<<8) | (d_N_RSV<<7) | (d_A_DIV<<2);
retR = R;
retcontrol = control;
retN = N;
retfreq = actual_freq/d_freq_mult;
return true;
}
int
_AD4360_common::_compute_control_reg()
{
int control = (d_P<<22) | (d_PD<<20) | (d_CP2<<17) | (d_CP1<<14)
| (d_PL<<12) | (d_MTLD<<11) | (d_CPG<<10) | (d_CP3S<<9) | (d_PDP<<8)
| (d_MUXOUT<<5) | (d_CR<<4) | (d_PC<<2);
return control;
}
int
_AD4360_common::_refclk_divisor()
{
/*
Return value to stick in REFCLK_DIVISOR register
*/
return 1;
}
int
_AD4360_common::_prescaler()
{
if(d_P == 0) {
return 8;
}
else if(d_P == 1) {
return 16;
}
else {
return 32;
}
}
//----------------------------------------------------------------------
_2200_common::_2200_common()
: _AD4360_common()
{
// Band-specific R-Register Values
d_R_DIV = 16; // bits 15:2
// Band-specific C-Register values
d_P = 1; // bits 23,22 Div by 16/17
d_CP2 = 7; // bits 19:17
d_CP1 = 7; // bits 16:14
// Band specifc N-Register Values
d_DIVSEL = 0; // bit 23
d_DIV2 = 0; // bit 22
d_CPGAIN = 0; // bit 21
d_freq_mult = 1;
}
double
_2200_common::freq_min()
{
return 2000e6;
}
double
_2200_common::freq_max()
{
return 2400e6;
}
//----------------------------------------------------------------------
_2400_common::_2400_common()
: _AD4360_common()
{
// Band-specific R-Register Values
d_R_DIV = 16; // bits 15:2
// Band-specific C-Register values
d_P = 1; // bits 23,22 Div by 16/17
d_CP2 = 7; // bits 19:17
d_CP1 = 7; // bits 16:14
// Band specifc N-Register Values
d_DIVSEL = 0; // bit 23
d_DIV2 = 0; // bit 22
d_CPGAIN = 0; // bit 21
d_freq_mult = 1;
}
double
_2400_common::freq_min()
{
return 2300e6;
}
double
_2400_common::freq_max()
{
return 2900e6;
}
//----------------------------------------------------------------------
_1200_common::_1200_common()
: _AD4360_common()
{
// Band-specific R-Register Values
d_R_DIV = 16; // bits 15:2 DIV by 16 for a 1 MHz phase detector freq
// Band-specific C-Register values
d_P = 1; // bits 23,22 Div by 16/17
d_CP2 = 7; // bits 19:17 1.25 mA
d_CP1 = 7; // bits 16:14 1.25 mA
// Band specifc N-Register Values
d_DIVSEL = 0; // bit 23
d_DIV2 = 1; // bit 22
d_CPGAIN = 0; // bit 21
d_freq_mult = 2;
}
double
_1200_common::freq_min()
{
return 1150e6;
}
double
_1200_common::freq_max()
{
return 1450e6;
}
//-------------------------------------------------------------------------
_1800_common::_1800_common()
: _AD4360_common()
{
// Band-specific R-Register Values
d_R_DIV = 16; // bits 15:2 DIV by 16 for a 1 MHz phase detector freq
// Band-specific C-Register values
d_P = 1; // bits 23,22 Div by 16/17
d_CP2 = 7; // bits 19:17 1.25 mA
d_CP1 = 7; // bits 16:14 1.25 mA
// Band specifc N-Register Values
d_DIVSEL = 0; // bit 23
d_DIV2 = 0; // bit 22
d_freq_mult = 1;
d_CPGAIN = 0; // bit 21
}
double
_1800_common::freq_min()
{
return 1500e6;
}
double
_1800_common::freq_max()
{
return 2100e6;
}
//-------------------------------------------------------------------------
_900_common::_900_common()
: _AD4360_common()
{
// Band-specific R-Register Values
d_R_DIV = 16; // bits 15:2 DIV by 16 for a 1 MHz phase detector freq
// Band-specific C-Register values
d_P = 1; // bits 23,22 Div by 16/17
d_CP2 = 7; // bits 19:17 1.25 mA
d_CP1 = 7; // bits 16:14 1.25 mA
// Band specifc N-Register Values
d_DIVSEL = 0; // bit 23
d_DIV2 = 1; // bit 22
d_freq_mult = 2;
d_CPGAIN = 0; // bit 21
}
double
_900_common::freq_min()
{
return 750e6;
}
double
_900_common::freq_max()
{
return 1050e6;
}
//-------------------------------------------------------------------------
_400_common::_400_common()
: _AD4360_common()
{
// Band-specific R-Register Values
d_R_DIV = 16; // bits 15:2
// Band-specific C-Register values
d_P = 0; // bits 23,22 Div by 8/9
d_CP2 = 7; // bits 19:17 1.25 mA
d_CP1 = 7; // bits 16:14 1.25 mA
// Band specifc N-Register Values These are different for TX/RX
d_DIVSEL = 0; // bit 23
d_freq_mult = 2;
d_CPGAIN = 0; // bit 21
}
double
_400_common::freq_min()
{
return 400e6;
}
double
_400_common::freq_max()
{
return 500e6;
}
_400_tx::_400_tx()
: _400_common()
{
d_DIV2 = 1; // bit 22
}
_400_rx::_400_rx()
: _400_common()
{
d_DIV2 = 0; // bit 22 // RX side has built-in DIV2 in AD8348
}
//------------------------------------------------------------
db_flexrf_2200_tx::db_flexrf_2200_tx(usrp_basic_sptr usrp, int which)
: flexrf_base_tx(usrp, which)
{
d_common = new _2200_common();
}
db_flexrf_2200_tx::~db_flexrf_2200_tx()
{
}
bool
db_flexrf_2200_tx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
db_flexrf_2200_rx::db_flexrf_2200_rx(usrp_basic_sptr usrp, int which)
: flexrf_base_rx(usrp, which)
{
d_common = new _2200_common();
set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
}
db_flexrf_2200_rx::~db_flexrf_2200_rx()
{
}
float
db_flexrf_2200_rx::gain_min()
{
return usrp()->pga_min();
}
float
db_flexrf_2200_rx::gain_max()
{
return usrp()->pga_max()+70;
}
float
db_flexrf_2200_rx::gain_db_per_step()
{
return 0.05;
}
bool
db_flexrf_2200_rx::i_and_q_swapped()
{
return true;
}
bool
db_flexrf_2200_rx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
//------------------------------------------------------------
db_flexrf_2400_tx::db_flexrf_2400_tx(usrp_basic_sptr usrp, int which)
: flexrf_base_tx(usrp, which)
{
d_common = new _2400_common();
}
db_flexrf_2400_tx::~db_flexrf_2400_tx()
{
}
bool
db_flexrf_2400_tx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
db_flexrf_2400_rx::db_flexrf_2400_rx(usrp_basic_sptr usrp, int which)
: flexrf_base_rx(usrp, which)
{
d_common = new _2400_common();
set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
}
db_flexrf_2400_rx::~db_flexrf_2400_rx()
{
}
float
db_flexrf_2400_rx::gain_min()
{
return usrp()->pga_min();
}
float
db_flexrf_2400_rx::gain_max()
{
return usrp()->pga_max()+70;
}
float
db_flexrf_2400_rx::gain_db_per_step()
{
return 0.05;
}
bool
db_flexrf_2400_rx::i_and_q_swapped()
{
return true;
}
bool
db_flexrf_2400_rx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
//------------------------------------------------------------
db_flexrf_1200_tx::db_flexrf_1200_tx(usrp_basic_sptr usrp, int which)
: flexrf_base_tx(usrp, which)
{
d_common = new _1200_common();
}
db_flexrf_1200_tx::~db_flexrf_1200_tx()
{
}
bool
db_flexrf_1200_tx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
db_flexrf_1200_rx::db_flexrf_1200_rx(usrp_basic_sptr usrp, int which)
: flexrf_base_rx(usrp, which)
{
d_common = new _1200_common();
set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
}
db_flexrf_1200_rx::~db_flexrf_1200_rx()
{
}
float
db_flexrf_1200_rx::gain_min()
{
return usrp()->pga_min();
}
float
db_flexrf_1200_rx::gain_max()
{
return usrp()->pga_max()+70;
}
float
db_flexrf_1200_rx::gain_db_per_step()
{
return 0.05;
}
bool
db_flexrf_1200_rx::i_and_q_swapped()
{
return true;
}
bool
db_flexrf_1200_rx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
//------------------------------------------------------------
db_flexrf_1800_tx::db_flexrf_1800_tx(usrp_basic_sptr usrp, int which)
: flexrf_base_tx(usrp, which)
{
d_common = new _1800_common();
}
db_flexrf_1800_tx::~db_flexrf_1800_tx()
{
}
bool
db_flexrf_1800_tx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
db_flexrf_1800_rx::db_flexrf_1800_rx(usrp_basic_sptr usrp, int which)
: flexrf_base_rx(usrp, which)
{
d_common = new _1800_common();
set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
}
db_flexrf_1800_rx::~db_flexrf_1800_rx()
{
}
float
db_flexrf_1800_rx::gain_min()
{
return usrp()->pga_min();
}
float
db_flexrf_1800_rx::gain_max()
{
return usrp()->pga_max()+70;
}
float
db_flexrf_1800_rx::gain_db_per_step()
{
return 0.05;
}
bool
db_flexrf_1800_rx::i_and_q_swapped()
{
return true;
}
bool
db_flexrf_1800_rx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
//------------------------------------------------------------
db_flexrf_900_tx::db_flexrf_900_tx(usrp_basic_sptr usrp, int which)
: flexrf_base_tx(usrp, which)
{
d_common = new _900_common();
}
db_flexrf_900_tx::~db_flexrf_900_tx()
{
}
bool
db_flexrf_900_tx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
db_flexrf_900_rx::db_flexrf_900_rx(usrp_basic_sptr usrp, int which)
: flexrf_base_rx(usrp, which)
{
d_common = new _900_common();
set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
}
db_flexrf_900_rx::~db_flexrf_900_rx()
{
}
float
db_flexrf_900_rx::gain_min()
{
return usrp()->pga_min();
}
float
db_flexrf_900_rx::gain_max()
{
return usrp()->pga_max()+70;
}
float
db_flexrf_900_rx::gain_db_per_step()
{
return 0.05;
}
bool
db_flexrf_900_rx::i_and_q_swapped()
{
return true;
}
bool
db_flexrf_900_rx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
//------------------------------------------------------------
db_flexrf_400_tx::db_flexrf_400_tx(usrp_basic_sptr usrp, int which)
: flexrf_base_tx(usrp, which, POWER_UP)
{
d_common = new _400_tx();
}
db_flexrf_400_tx::~db_flexrf_400_tx()
{
}
bool
db_flexrf_400_tx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
db_flexrf_400_rx::db_flexrf_400_rx(usrp_basic_sptr usrp, int which)
: flexrf_base_rx(usrp, which, POWER_UP)
{
d_common = new _400_rx();
set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
}
db_flexrf_400_rx::~db_flexrf_400_rx()
{
}
float
db_flexrf_400_rx::gain_min()
{
return usrp()->pga_min();
}
float
db_flexrf_400_rx::gain_max()
{
return usrp()->pga_max()+45;
}
float
db_flexrf_400_rx::gain_db_per_step()
{
return 0.035;
}
bool
db_flexrf_400_rx::i_and_q_swapped()
{
return true;
}
bool
db_flexrf_400_rx::_compute_regs(double freq, int &retR, int &retcontrol,
int &retN, double &retfreq)
{
return d_common->_compute_regs(_refclk_freq(), freq, retR,
retcontrol, retN, retfreq);
}
|