2 # Copyright 2005 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
25 import db_instantiator
27 class db_basic_tx(db_base.db_base):
28 def __init__(self, usrp, which):
30 Handler for Basic Tx daughterboards.
32 @param usrp: instance of usrp.source_c
33 @param which: which side: 0 or 1 corresponding to TX_A or TX_B respectively
36 db_base.db_base.__init__(self, usrp, which)
38 if 0: # Doing this would give us a different default than the historical values...
39 g = self.gain_range() # initialize gain
40 self.set_gain(float(g[0]+g[1]) / 2)
45 Return range of frequencies in Hz that can be tuned by this d'board.
47 @returns (min_freq, max_freq, step_size)
50 We say we can do pretty much anything...
52 return (-90e9, 90e9, 1e-6)
54 def set_freq(self, target_freq):
58 @param freq: target RF frequency in Hz
61 @returns (ok, actual_baseband_freq) where:
62 ok is True or False and indicates success or failure,
63 actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
69 Return range of gain that can be set by this d'board.
71 @returns (min_gain, max_gain, step_size)
72 Where gains are expressed in decibels (your mileage may vary)
74 return (self._u.pga_min(), self._u.pga_max(), self._u.pga_db_per_step())
76 def set_gain(self, gain):
80 @param gain: gain in decibels
83 ok = self._u.set_pga(self._which * 2 + 0, gain)
84 ok = ok and self._u.set_pga(self._which * 2 + 1, gain)
87 def is_quadrature(self):
89 Return True if this board requires both I & Q analog channels.
94 class db_basic_rx(db_base.db_base):
95 def __init__(self, usrp, which, subdev):
97 Handler for Basic Rx daughterboards.
99 @param usrp: instance of usrp.source_c
100 @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
101 @param subdev: which analog i/o channel: 0 or 1
105 db_base.db_base.__init__(self, usrp, which)
106 self._subdev = subdev
108 self.bypass_adc_buffers(True)
110 if 0: # Doing this would give us a different default than the historical values...
111 g = self.gain_range() # initialize gain
112 self.set_gain(float(g[0]+g[1]) / 2)
115 def freq_range(self):
117 Return range of frequencies in Hz that can be tuned by this d'board.
119 @returns (min_freq, max_freq, step_size)
122 We say we can do pretty much anything...
124 return (0, 90e9, 1e-6)
126 def set_freq(self, target_freq):
130 @param freq: target RF frequency in Hz
133 @returns (ok, actual_baseband_freq) where:
134 ok is True or False and indicates success or failure,
135 actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
140 def gain_range(self):
142 Return range of gain that can be set by this d'board.
144 @returns (min_gain, max_gain, step_size)
145 Where gains are expressed in decibels (your mileage may vary)
147 return (self._u.pga_min(), self._u.pga_max(), self._u.pga_db_per_step())
149 def set_gain(self, gain):
153 @param gain: gain in decibels
156 return self._u.set_pga(self._which * 2 + self._subdev, gain)
158 def is_quadrature(self):
160 Return True if this board requires both I & Q analog channels.
162 This bit of info is useful when setting up the USRP Rx mux register.
166 class db_lf_rx(db_basic_rx):
167 def __init__(self, usrp, which, subdev):
169 Handler for Low Freq Rx daughterboards.
171 @param usrp: instance of usrp.source_c
172 @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
173 @param subdev: which analog i/o channel: 0 or 1
177 db_basic_rx.__init__(self, usrp, which, subdev)
179 def freq_range(self):
181 Return range of frequencies in Hz that can be tuned by this d'board.
183 @returns (min_freq, max_freq, step_size)
186 We cover the first nyquist zone only
188 return (0, 32e6, 1e-6)
190 class db_lf_tx(db_basic_tx):
191 def __init__(self, usrp, which):
193 Handler for Low Freq Tx daughterboards.
195 @param usrp: instance of usrp.source_c
196 @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
199 db_basic_tx.__init__(self, usrp, which)
201 def freq_range(self):
203 Return range of frequencies in Hz that can be tuned by this d'board.
205 @returns (min_freq, max_freq, step_size)
208 We cover the first nyquist zone only
210 return (-32e6, 32e6, 1e-6)
213 # hook these daughterboard classes into the auto-instantiation framework
215 def _basic_rx_instantiator(usrp, which):
216 # two single channel subdevices
217 return (db_basic_rx(usrp, which, 0), db_basic_rx(usrp, which, 1))
219 def _lf_rx_instantiator(usrp, which):
220 # two single channel subdevices
221 return (db_lf_rx(usrp, which, 0), db_lf_rx(usrp, which, 1))
223 def _basic_tx_instantiator(usrp, which):
224 # one quadrature subdevice
225 return (db_basic_tx(usrp, which),)
227 def _lf_tx_instantiator(usrp, which):
228 # one quadrature subdevice
229 return (db_lf_tx(usrp, which),)
231 def _no_db_instantiator(usrp, which):
232 if hasattr(usrp, 'tx_freq'): # is this a tx or rx daughterboard?
233 return (_basic_tx_instantiator(usrp, which))
235 return (_basic_rx_instantiator(usrp, which))
237 def _invalid_instantiator(usrp, which):
238 if hasattr(usrp, 'tx_freq'): # is this a tx or rx daughterboard?
239 sys.stderr.write('\n\aWarning: Treating daughterboard with invalid EEPROM contents as if it were a "Basic Tx."\n')
240 sys.stderr.write('Warning: This is almost certainly wrong... Use appropriate burn-*-eeprom utility.\n\n')
241 return _basic_tx_instantiator(usrp, which)
243 sys.stderr.write('\n\aWarning: Treating daughterboard with invalid EEPROM contents as if it were a "Basic Rx."\n')
244 sys.stderr.write('Warning: This is almost certainly wrong... Use appropriate burn-*-eeprom utility.\n\n')
245 return _basic_rx_instantiator(usrp, which)
247 db_instantiator.add(-1, _no_db_instantiator) # no daughterboard
248 db_instantiator.add(-2, _invalid_instantiator) # invalid eeprom contents
249 db_instantiator.add(usrp_dbid.BASIC_TX, _basic_tx_instantiator)
250 db_instantiator.add(usrp_dbid.BASIC_RX, _basic_rx_instantiator)
251 db_instantiator.add(usrp_dbid.LF_TX, _lf_tx_instantiator)
252 db_instantiator.add(usrp_dbid.LF_RX, _lf_rx_instantiator)