Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gruimpl / sdr_1000.py
1 #
2 # Copyright 2003,2004 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 from gnuradio import gr
23
24 class sdr_1000 (gr.sdr_1000_base):
25     "Control the DDS on the SDR-1000"
26     def __init__(self, pport = 0):
27         gr.sdr_1000_base.__init__(self, pport)
28         self.write_latch (3, 0x00, 0xC0) # Reset low, WRS/ low
29         self.write_reg (0x20, 0x40)
30
31     def write_reg(self, addr, data):
32         self.write_latch (3, addr & 0x3f, 0x3f)
33         self.write_latch (2, data, 0xff)
34         self.write_latch (3, 0x40, 0x40)
35         self.write_latch (3, 0x00, 0x40)
36     
37     def set_freq(self, freq):
38         self.set_band (freq)
39         ftw = freq / 200e6;
40         for i in xrange(6):
41             word = int(ftw * 256)
42             ftw = ftw*256 - word
43             # print (('%d [%02x]') % (i, word))
44             self.write_reg (4+i, word)
45
46     def set_band (self, freq):
47         if freq <= 2.25e6:
48             band = 0
49         elif freq <= 5.5e6:
50             band = 1
51         elif freq <= 11e6:
52             band = 3    # due to wiring mistake on board
53         elif freq <= 22e6:
54             band = 2    # due to wiring mistake on board
55         elif freq <= 37.5e6:
56             band = 4
57         else:
58             band = 5
59         
60         self.write_latch (1, 1 << band, 0x3f)
61
62     def set_bit (self, reg, bit, state):
63         val = 0x00
64         if state: val = 1<<bit
65         self.write_latch (reg, val, 1<<bit)
66         
67     def set_tx (self, on = 1):
68         self.set_bit(1, 6, on)
69
70     def set_rx (self):
71         self.set_bit(1, 6, 0)
72     
73     def set_gain (self, high):
74         self.set_bit(0, 7, high)
75       
76     def set_mute (self, mute = 1):
77         self.set_bit(1, 7, mute)
78
79     def set_unmute (self):
80         self.set_bit(1, 7, 0)
81
82     def set_external_pin (self, pin, on = 1):
83         assert (pin < 8 and pin > 0), "Out of range 1..7"
84         self.set_bit(0, pin-1, on)