Imported Upstream version 3.0
[debian/gnuradio] / gr-usrp / src / db_basic.py
1 #
2 # Copyright 2005 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
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 2, or (at your option)
9 # any later version.
10
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.
15
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.
20
21
22 import sys
23 import usrp_dbid
24 import db_base
25 import db_instantiator
26
27 class db_basic_tx(db_base.db_base):
28     def __init__(self, usrp, which):
29         """
30         Handler for Basic Tx daughterboards.
31         
32         @param usrp: instance of usrp.source_c
33         @param which: which side: 0 or 1 corresponding to TX_A or TX_B respectively
34         """
35         # sets _u and _which
36         db_base.db_base.__init__(self, usrp, which)
37
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)
41
42
43     def freq_range(self):
44         """
45         Return range of frequencies in Hz that can be tuned by this d'board.
46
47         @returns (min_freq, max_freq, step_size)
48         @rtype tuple
49
50         We say we can do pretty much anything...
51         """
52         return (-90e9, 90e9, 1e-6)
53
54     def set_freq(self, target_freq):
55         """
56         Set the frequency.
57
58         @param freq:  target RF frequency in Hz
59         @type freq:   float
60
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.
64         """
65         return (True, 0)
66
67     def gain_range(self):
68         """
69         Return range of gain that can be set by this d'board.
70
71         @returns (min_gain, max_gain, step_size)
72         Where gains are expressed in decibels (your mileage may vary)
73         """
74         return (self._u.pga_min(), self._u.pga_max(), self._u.pga_db_per_step())
75
76     def set_gain(self, gain):
77         """
78         Set the gain.
79
80         @param gain:  gain in decibels
81         @returns True/False
82         """
83         ok = self._u.set_pga(self._which * 2 + 0, gain)
84         ok = ok and self._u.set_pga(self._which * 2 + 1, gain)
85         return ok
86
87     def is_quadrature(self):
88         """
89         Return True if this board requires both I & Q analog channels.
90         """
91         return True
92     
93
94 class db_basic_rx(db_base.db_base):
95     def __init__(self, usrp, which, subdev):
96         """
97         Handler for Basic Rx daughterboards.
98         
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
102         @type subdev: int
103         """
104         # sets _u and _which
105         db_base.db_base.__init__(self, usrp, which)
106         self._subdev = subdev
107
108         self.bypass_adc_buffers(True)
109
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)
113
114
115     def freq_range(self):
116         """
117         Return range of frequencies in Hz that can be tuned by this d'board.
118
119         @returns (min_freq, max_freq, step_size)
120         @rtype tuple
121
122         We say we can do pretty much anything...
123         """
124         return (0, 90e9, 1e-6)
125
126     def set_freq(self, target_freq):
127         """
128         Set the frequency.
129
130         @param freq:  target RF frequency in Hz
131         @type freq:   float
132
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.
136         """
137         return (True, 0)
138         
139
140     def gain_range(self):
141         """
142         Return range of gain that can be set by this d'board.
143
144         @returns (min_gain, max_gain, step_size)
145         Where gains are expressed in decibels (your mileage may vary)
146         """
147         return (self._u.pga_min(), self._u.pga_max(), self._u.pga_db_per_step())
148
149     def set_gain(self, gain):
150         """
151         Set the gain.
152
153         @param gain:  gain in decibels
154         @returns True/False
155         """
156         return self._u.set_pga(self._which * 2 + self._subdev, gain)
157
158     def is_quadrature(self):
159         """
160         Return True if this board requires both I & Q analog channels.
161
162         This bit of info is useful when setting up the USRP Rx mux register.
163         """
164         return False
165     
166 class db_lf_rx(db_basic_rx):
167     def __init__(self, usrp, which, subdev):
168         """
169         Handler for Low Freq Rx daughterboards.
170         
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
174         @type subdev: int
175         """
176         # sets _u and _which
177         db_basic_rx.__init__(self, usrp, which, subdev)
178
179     def freq_range(self):
180         """
181         Return range of frequencies in Hz that can be tuned by this d'board.
182
183         @returns (min_freq, max_freq, step_size)
184         @rtype tuple
185
186         We cover the first nyquist zone only
187         """
188         return (0, 32e6, 1e-6)
189
190 class db_lf_tx(db_basic_tx):
191     def __init__(self, usrp, which):
192         """
193         Handler for Low Freq Tx daughterboards.
194         
195         @param usrp: instance of usrp.source_c
196         @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
197         """
198         # sets _u and _which
199         db_basic_tx.__init__(self, usrp, which)
200
201     def freq_range(self):
202         """
203         Return range of frequencies in Hz that can be tuned by this d'board.
204
205         @returns (min_freq, max_freq, step_size)
206         @rtype tuple
207
208         We cover the first nyquist zone only
209         """
210         return (-32e6, 32e6, 1e-6)
211
212
213 # hook these daughterboard classes into the auto-instantiation framework
214
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))
218
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))
222
223 def _basic_tx_instantiator(usrp, which):
224     # one quadrature subdevice
225     return (db_basic_tx(usrp, which),)
226
227 def _lf_tx_instantiator(usrp, which):
228     # one quadrature subdevice
229     return (db_lf_tx(usrp, which),)
230
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))
234     else:
235         return (_basic_rx_instantiator(usrp, which))
236     
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)
242     else:
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)
246
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)