2 # Copyright 2005,2006,2007 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.
23 from usrpm import usrp_prims
24 from usrpm.usrp_fpga_regs import *
26 class db_base(object):
28 Abstract base class for all daughterboards.
30 This defines the required operations and interfaces for all d'boards.
32 def __init__(self, usrp, which):
34 Initialize daughterboard interface.
36 @param usrp: instance of usrp
37 @param which: which daughterboard side: A = 0, B = 1
41 if not (which in (0, 1)):
42 raise ValueError, "Invalid value of which: %s" % (which,)
44 self._u = weakref.proxy(usrp)
47 if hasattr(self._u, 'tx_freq'): # is this a tx or rx daughterboard?
49 self._slot = which * 2
52 self._slot = which * 2 + 1
54 self._refclk_reg = (FR_TX_A_REFCLK,FR_RX_A_REFCLK,FR_TX_B_REFCLK,FR_RX_B_REFCLK)[self._slot]
57 return self._u.daughterboard_id(self._which)
60 return usrp_prims.usrp_dbid_to_string(self.dbid())
62 def side_and_name(self):
63 return "AB"[self._which] + ': ' + self.name()
65 # Function to bypass ADC buffers. Any board which is DC-coupled should bypass the buffers
66 def bypass_adc_buffers(self,bypass):
68 raise RuntimeError, "TX Board has no adc buffers"
70 self._u.set_adc_buffer_bypass(0, bypass)
71 self._u.set_adc_buffer_bypass(1, bypass)
73 self._u.set_adc_buffer_bypass(2, bypass)
74 self._u.set_adc_buffer_bypass(3, bypass)
76 # ------------------------------------------------------------------------
77 # Reference Clock section
79 # Control whether a reference clock is sent to the daughterboards,
82 # Bit 7 -- 1 turns on refclk, 0 allows IO use
83 # Bits 6:0 Divider value
86 def _refclk_freq(self):
87 return self._u.fpga_master_clock_freq()/self._refclk_divisor()
89 def _enable_refclk(self,enable):
90 CLOCK_OUT = 1 # Clock is on lowest bit
92 REFCLK_DIVISOR_MASK = 0x7f
94 self._u._write_oe(self._which, CLOCK_OUT, CLOCK_OUT) # output enable
95 self._u._write_fpga_reg(self._refclk_reg,
96 ((self._refclk_divisor() & REFCLK_DIVISOR_MASK)
99 self._u._write_fpga_reg(self._refclk_reg, 0)
101 def _refclk_divisor(self):
103 Return value to stick in REFCLK_DIVISOR register
105 raise NotImplementedError
107 # ------------------------------------------------------------------------
108 # Automatic Transmit/Receive switching
110 # The presence or absence of data in the FPGA transmit fifo
111 # selects between two sets of values for each of the 4 banks of
112 # daughterboard i/o pins.
114 # Each daughterboard slot has 3 16-bit registers associated with it:
115 # FR_ATR_MASK_*, FR_ATR_TXVAL_* and FR_ATR_RXVAL_*
117 # FR_ATR_MASK_{0,1,2,3}:
119 # These registers determine which of the daugherboard i/o pins are
120 # affected by ATR switching. If a bit in the mask is set, the
121 # corresponding i/o bit is controlled by ATR, else it's output
122 # value comes from the normal i/o pin output register:
125 # FR_ATR_TXVAL_{0,1,2,3}:
126 # FR_ATR_RXVAL_{0,1,2,3}:
128 # If the Tx fifo contains data, then the bits from TXVAL that are
129 # selected by MASK are output. Otherwise, the bits from RXVAL that
130 # are selected by MASK are output.
132 def set_atr_mask(self, v):
136 return self._u._write_fpga_reg(FR_ATR_MASK_0 + 3 * self._slot, v)
138 def set_atr_txval(self, v):
140 Set Auto T/R register value to be used when transmitting.
142 return self._u._write_fpga_reg(FR_ATR_TXVAL_0 + 3 * self._slot, v)
144 def set_atr_rxval(self, v):
146 Set Auto T/R register value to be used when receiving.
148 return self._u._write_fpga_reg(FR_ATR_RXVAL_0 + 3 * self._slot, v)
150 def set_atr_tx_delay(self, v):
152 Set Auto T/R delay (in clock ticks) from when Tx fifo gets data to
155 return self._u._write_fpga_reg(FR_ATR_TX_DELAY, v)
157 def set_atr_rx_delay(self, v):
159 Set Auto T/R delay (in clock ticks) from when Tx fifo goes empty to
162 return self._u._write_fpga_reg(FR_ATR_RX_DELAY, v)
164 # derived classes should override the following methods
166 def freq_range(self):
168 Return range of frequencies in Hz that can be tuned by this d'board.
170 @returns (min_freq, max_freq, step_size)
173 raise NotImplementedError
175 def set_freq(self, target_freq):
179 @param freq: target RF frequency in Hz
182 @returns (ok, actual_baseband_freq) where:
183 ok is True or False and indicates success or failure,
184 actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
186 raise NotImplementedError
188 def gain_range(self):
190 Return range of gain that can be set by this d'board.
192 @returns (min_gain, max_gain, step_size)
193 Where gains are expressed in decibels (your mileage may vary)
195 raise NotImplementedError
197 def set_gain(self, gain):
201 @param gain: gain in decibels
204 raise NotImplementedError
206 def is_quadrature(self):
208 Return True if this daughterboard does quadrature up or down conversion.
209 That is, return True if this board requires both I & Q analog channels.
211 This bit of info is useful when setting up the USRP Rx mux register.
213 raise NotImplementedError
215 def i_and_q_swapped(self):
217 Return True if this is a quadrature device and ADC 0 is Q.
221 def spectrum_inverted(self):
223 Return True if the dboard gives an inverted spectrum
227 def set_enable(self, on):
229 For tx daughterboards, this controls the transmitter enable.
233 def set_auto_tr(self,on):
235 Enable automatic Transmit/Receive switching (ATR).
237 Should be overridden in subclasses that care. This will typically
238 set the atr_mask, txval and rxval.
242 def set_lo_offset(self, offset):
244 Set how much LO is offset from requested frequency
246 Should be overriden by daughterboards that care.
250 def lo_offset(self, offset):
252 Get how much LO is offset from requested frequency
254 Should be overriden by daughterboards that care.
258 def select_rx_antenna(self, which_antenna):
260 Specify which antenna port to use for reception.
261 Should be overriden by daughterboards that care.