Statistics
| Branch: | Tag: | Revision:

root / host / lib / ic_reg_maps / gen_ad9862_regs.py @ 1bef3487

History | View | Annotate | Download (11 KB)

1
#!/usr/bin/env python
2
#
3
# Copyright 2010 Ettus Research LLC
4
#
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
#
18

    
19
########################################################################
20
# Template for raw text data describing registers
21
# name addr[bit range inclusive] default optional enums
22
########################################################################
23
REGS_TMPL="""\
24
########################################################################
25
## General
26
########################################################################
27
sdio_bidir         0[7]              0                  sdio_sdo, sdio
28
lsb_first          0[6]              0                  msb, lsb
29
soft_reset         0[5]              0
30
########################################################################
31
## Rx Power Down
32
########################################################################
33
vref_diff_pd       1[7]              0
34
vref_pd            1[6]              0
35
rx_digital_pd      1[5]              0
36
rx_channel_b_pd    1[4]              0
37
rx_channel_a_pd    1[3]              0
38
buffer_b_pd        1[2]              0
39
buffer_a_pd        1[1]              0
40
all_rx_pd          1[0]              0
41
########################################################################
42
## Rx A and B
43
########################################################################
44
#for $x, $i in (('a', 2), ('b', 3))
45
byp_buffer_$x      $(i)[7]           0
46
rx_pga_$x          $(i)[0:4]         0
47
#end for
48
########################################################################
49
## Rx Misc
50
########################################################################
51
hs_duty_cycle      4[2]              0
52
shared_ref         4[1]              0
53
clk_duty           4[0]              0
54
########################################################################
55
## RX I/F (INTERFACE)
56
########################################################################
57
three_state        5[4]              0
58
rx_retime          5[3]              0       clkout1, clkout2
59
rx_twos_comp       5[2]              0
60
inv_rxsync         5[1]              0
61
mux_out            5[0]              0       rx_mux_mode=1, dual_port_mode=0
62
########################################################################
63
## RX Digital
64
########################################################################
65
two_channel        6[3]              1       rx_b_dis, both_enb
66
rx_keep_ve         6[2]              0       pass_pos, pass_neg
67
rx_hilbert         6[1]              0       dis, enb
68
decimate           6[0]              0       dis, enb
69
########################################################################
70
## TX Power Down
71
########################################################################
72
alt_timing_mode    8[5]              0
73
txoff_enable       8[4]              0
74
tx_digital_pd      8[3]              0
75
tx_analog_pd       8[0:2]            0        none=0, txb=4, txa=2, both=7
76
########################################################################
77
## Tx Offset and Gain
78
########################################################################
79
#for $x, $i, $j, $k in (('a', 10, 11, 14), ('b', 12, 13, 15))
80
dac_$(x)_offset_1_0   $(i)[6:7]           0
81
dac_$(x)_offset_dir   $(i)[0]             0        neg_diff, pos_dif
82
dac_$(x)_offset_9_2   $(j)[0:7]           0
83
dac_$(x)_coarse_gain  $(k)[6:7]           0
84
dac_$(x)_fine_gain    $(k)[0:5]           0
85
#end for
86
tx_pga_gain            16[0:7]            0
87
########################################################################
88
## Tx Misc
89
########################################################################
90
tx_slave_enable        17[1]              0
91
tx_pga_mode            17[0]              0        normal, fast
92
########################################################################
93
## Tx IF (INTERFACE)
94
########################################################################
95
tx_retime              18[6]              1        clkout1=1, clkout2=0
96
qi_order               18[5]              0        iq, qi
97
inv_txsync             18[4]              0
98
tx_twos_comp           18[3]              0
99
inverse_samp           18[2]              0        rise, fall
100
edges                  18[1]              0        normal, both
101
interleaved            18[0]              0        single, interleaved
102
########################################################################
103
## TX Digital
104
########################################################################
105
two_data_paths         19[4]              0        single, both
106
tx_keep_ve             19[3]              0        pass_pos, pass_neg
107
tx_hilbert             19[2]              0        dis, enb
108
interp                 19[0:1]            0        1, 2, 4
109
########################################################################
110
## TX Modulator
111
########################################################################
112
neg_fine_tune          20[5]              0        pos_shift, neg_shift
113
fine_mode              20[4]              0        bypass, nco
114
real_mix_mode          20[3]              0        complex, real
115
neg_coarse_tune        20[2]              0        pos_shift, neg_shift
116
coarse_mod             20[0:1]            0        bypass, fdac_4, fdac_8
117
########################################################################
118
## NCO Tuning Word
119
########################################################################
120
ftw_7_0                21[0:7]            0
121
ftw_15_8               22[0:7]            0
122
ftw_23_16              23[0:7]            0
123
########################################################################
124
## DLL
125
########################################################################
126
input_clk_ctrl         24[6]              0       internal, external
127
adc_div2               24[5]              0       normal, div2
128
dll_mult               24[3:4]            0       1, 2, 4
129
dll_pd                 24[2]              0
130
dll_mode               24[0]              0       slow, fast
131
########################################################################
132
## Clock Out
133
########################################################################
134
clkout2_div_factor     25[6:7]            0       1, 2, 4, 8
135
inv2                   25[5]              0       normal, inverted
136
inv1                   25[1]              0       normal, inverted
137
dis2                   25[4]              0       enb, dis
138
dis1                   25[0]              0       enb, dis
139
########################################################################
140
## Aux ADC
141
########################################################################
142
#for $x, $i in (('a2', 26), ('a1', 28), ('b2', 30), ('b1', 32))
143
aux_adc_$(x)_1_0       $(i)[6:7]          0
144
aux_adc_$(x)_9_2       $int(1+$i)[0:7]    0
145
#end for
146
########################################################################
147
## Aux ADC Control
148
########################################################################
149
aux_spi                34[7]              0       dis, enb
150
sel_bnota              34[6]              0       adc_a, adc_b
151
#for $x, $i in (('b', 5), ('a', 2))
152
refsel_$(x)            34[$i]             0       external, internal
153
select_$(x)            34[$int($i-1)]     0       aux_adc2, aux_adc1
154
start_$(x)             34[$int($i-2)]     0
155
#end for
156
########################################################################
157
## Aux ADC Clock
158
########################################################################
159
clk_4                  35[0]              0       1_2, 1_4
160
########################################################################
161
## Aux DAC
162
########################################################################
163
#for $x, $i in (('a', 36), ('b', 37), ('c', 38))
164
aux_dac_$x             $(i)[0:7]          0
165
#end for
166
########################################################################
167
## Aux DAC Update
168
########################################################################
169
aux_dac_slave_enable   39[7]              0
170
aux_dacupdate_c        39[2]              0
171
aux_dacupdate_b        39[1]              0
172
aux_dacupdate_a        39[0]              0
173
########################################################################
174
## AUX DAC Power Down
175
########################################################################
176
aux_dac_pd_a           40[2]              0
177
aux_dac_pd_b           40[1]              0
178
aux_dac_pd_c           40[0]              0
179
########################################################################
180
## AUX DAC Control
181
########################################################################
182
aux_dac_invert_a       41[2]              0
183
aux_dac_invert_b       41[1]              0
184
aux_dac_invert_c       41[0]              0
185
########################################################################
186
## Sig Delt
187
########################################################################
188
sig_delt_3_0           42[4:7]            0
189
sig_delt_11_4          43[0:7]            0
190
########################################################################
191
## ADC Low Power
192
########################################################################
193
rx_low_power_mode_r49 49[0:7]             0
194
rx_low_power_mode_r50 50[0:7]             0
195
########################################################################
196
## Chip ID
197
########################################################################
198
chip_id                63[0:7]            0
199
"""
200

    
201
########################################################################
202
# Header and Source templates below
203
########################################################################
204
BODY_TMPL="""
205
boost::uint8_t get_reg(boost::uint8_t addr){
206
    boost::uint8_t reg = 0;
207
    switch(addr){
208
    #for $addr in range(0, 63+1)
209
    case $addr:
210
        #for $reg in filter(lambda r: r.get_addr() == addr, $regs)
211
        reg |= (boost::uint16_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift();
212
        #end for
213
        break;
214
    #end for
215
    }
216
    return reg;
217
}
218

219
void set_reg(boost::uint8_t addr, boost::uint16_t reg){
220
    switch(addr){
221
    #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs)))
222
    case $addr:
223
        #for $reg in filter(lambda r: r.get_addr() == addr, $regs)
224
        $reg.get_name() = $(reg.get_type())((reg >> $reg.get_shift()) & $reg.get_mask());
225
        #end for
226
        break;
227
    #end for
228
    }
229
}
230

231
boost::uint16_t get_write_reg(boost::uint8_t addr){
232
    return (boost::uint16_t(addr) << 8) | get_reg(addr);
233
}
234

235
boost::uint16_t get_read_reg(boost::uint8_t addr){
236
    return (boost::uint16_t(addr) << 8) | (1 << 15);
237
}
238
"""
239

    
240
if __name__ == '__main__':
241
    import common; common.generate(
242
        name='ad9862_regs',
243
        regs_tmpl=REGS_TMPL,
244
        body_tmpl=BODY_TMPL,
245
        file=__file__,
246
    )