diff options
author | jcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5> | 2008-02-08 23:48:25 +0000 |
---|---|---|
committer | jcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5> | 2008-02-08 23:48:25 +0000 |
commit | 48fefc9b6e294c0ecb3cdd826b5a2f4b008fa829 (patch) | |
tree | 4c90381bca55f2f02c859dbedad3fffbf235fc33 /gr-gpio/src/python | |
parent | 42d9c6f495503d3d9d2db47a9979036c9233f976 (diff) |
Merged r7611:7614 from jcorgan/gpio into trunk. Adds custom
FPGA build for streaming digital I/O to/from GPIO pins through LSB of I and Q
datastreams, with example programs of use.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7618 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gr-gpio/src/python')
-rw-r--r-- | gr-gpio/src/python/Makefile.am | 50 | ||||
-rw-r--r-- | gr-gpio/src/python/__init__.py | 34 | ||||
-rw-r--r-- | gr-gpio/src/python/gpio.py | 3 | ||||
-rwxr-xr-x | gr-gpio/src/python/gpio_rx_sfile.py | 121 | ||||
-rwxr-xr-x | gr-gpio/src/python/gpio_usrp_fft.py | 333 | ||||
-rwxr-xr-x | gr-gpio/src/python/gpio_usrp_siggen.py | 209 | ||||
-rwxr-xr-x | gr-gpio/src/python/qa_gpio.py | 36 | ||||
-rw-r--r-- | gr-gpio/src/python/run_tests.in | 10 |
8 files changed, 796 insertions, 0 deletions
diff --git a/gr-gpio/src/python/Makefile.am b/gr-gpio/src/python/Makefile.am new file mode 100644 index 0000000000..ea1a986693 --- /dev/null +++ b/gr-gpio/src/python/Makefile.am @@ -0,0 +1,50 @@ +# +# Copyright 2007,2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +# Installation locations +ourpythondir = $(grpythondir)/gpio +ourlibdir = $(grpyexecdir)/gpio + +# List of Python files that will get installed into site-packages +ourpython_PYTHON = \ + __init__.py \ + gpio.py + +# List of python files that will be installed onto $prefix/bin +bin_SCRIPTS = \ + gpio_rx_sfile.py \ + gpio_usrp_siggen.py \ + gpio_usrp_fft.py + +# List of python files that will get distributed in tarball +# but not installed anywhere on system +noinst_PYTHON = \ + qa_gpio.py + +# Programs that get run by 'make check' +TESTS = run_tests + +# Files to go into tarball not otherwise mentioned (except bin_SCRIPTS!) +EXTRA_DIST = run_tests.in $(bin_SCRIPTS) + +MOSTLYCLEANFILES = *.pyo *.pyc *~ diff --git a/gr-gpio/src/python/__init__.py b/gr-gpio/src/python/__init__.py new file mode 100644 index 0000000000..b1f69b7eac --- /dev/null +++ b/gr-gpio/src/python/__init__.py @@ -0,0 +1,34 @@ +# +# Copyright 2007,2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import glob +import os.path + +# This automatically imports all top-level objects from .py files +# in our directory into the package name space +for _p in __path__: + _filenames = glob.glob (os.path.join (_p, "*.py")) + for _f in _filenames: + _f = os.path.basename(_f).lower() + _f = _f[:-3] + if _f == '__init__': + continue + exec "from %s import *" % (_f,) diff --git a/gr-gpio/src/python/gpio.py b/gr-gpio/src/python/gpio.py new file mode 100644 index 0000000000..cd94a27c50 --- /dev/null +++ b/gr-gpio/src/python/gpio.py @@ -0,0 +1,3 @@ +from gpio_swig import * + +fpga_filename = 'usrp_gpio.rbf' diff --git a/gr-gpio/src/python/gpio_rx_sfile.py b/gr-gpio/src/python/gpio_rx_sfile.py new file mode 100755 index 0000000000..ac4d608bf6 --- /dev/null +++ b/gr-gpio/src/python/gpio_rx_sfile.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, eng_notation +from gnuradio import usrp +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import sys + +from gnuradio import gpio + +class my_top_block(gr.top_block): + + def __init__(self, options): + gr.top_block.__init__(self) + + # Create a USRP source with GPIO FPGA build, then configure + u = usrp.source_s(decim_rate=options.decim,fpga_filename=gpio.fpga_filename) + + if options.force_complex_RXA: + # This is a dirty hack to force complex mode (receive both I and Q) on basicRX or LFRX + # This forces the receive board in RXA (side A) to be used + # FIXME: This has as a side effect that the gain for Q is not set. So only use with gain 0 (--gain 0) + options.rx_subdev_spec=(0,0) + u.set_mux(0x10) + if not (0==options.gain): + print "WARNING, you should set the gain to 0 with --gain 0 when using --force-complex-RXA" + print "The gain for Q will now still be zero while the gain for I is not" + #options.gain=0 + else: + if options.rx_subdev_spec is None: + options.rx_subdev_spec = usrp.pick_rx_subdevice(u) + u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec)) + + subdev = usrp.selected_subdev(u, options.rx_subdev_spec) + print "Using RX d'board %s" % (subdev.side_and_name(),) + input_rate = u.adc_freq()/u.decim_rate() + print "USB sample rate %s" % (eng_notation.num_to_str(input_rate)) + + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = subdev.gain_range() + options.gain = float(g[0]+g[1])/2 + + + #TODO setting gain on basicRX only sets the I channel, use a second subdev to set gain of Q channel + #see gnuradio-examples/multi-antenna for possible solutions + subdev.set_gain(options.gain) + + #TODO check if freq has same problem as gain when trying to use complex mode on basicRX + r = u.tune(0, subdev, options.freq) + if not r: + sys.stderr.write('Failed to set frequency\n') + raise SystemExit, 1 + + # Connect pipeline + src = u + if options.nsamples is not None: + head = gr.head(gr.sizeof_short, int(options.nsamples)*2) + self.connect(u, head) + src = head + + ana_strip = gpio.and_const_ss(0xFFFE) + dig_strip = gpio.and_const_ss(0x0001) + ana_sink = gr.file_sink(gr.sizeof_short, options.ana_filename) + dig_sink = gr.file_sink(gr.sizeof_short, options.dig_filename) + + self.connect(src, ana_strip, ana_sink) + self.connect(src, dig_strip, dig_sink) + +if __name__ == '__main__': + usage="%prog: [options] analog_filename digital_filename" + parser = OptionParser(option_class=eng_option, usage=usage) + parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), + help="select USRP Rx side A or B (default=A)") + parser.add_option("-d", "--decim", type="int", default=16, + help="set fgpa decimation rate to DECIM [default=%default]") + parser.add_option("-f", "--freq", type="eng_float", default=None, + help="set frequency to FREQ", metavar="FREQ") + parser.add_option("-g", "--gain", type="eng_float", default=None, + help="set gain in dB (default is midpoint)") + parser.add_option("-N", "--nsamples", type="eng_float", default=None, + help="number of samples to collect [default=+inf]") + parser.add_option("-F", "--force-complex-RXA", action="store_true", default=False, + help="enable basicRX hack to force complex mode on basicRX and LFRX. Only works on side A. Only use with --gain 0") + (options, args) = parser.parse_args () + if len(args) != 2: + parser.print_help() + raise SystemExit, 1 + options.ana_filename = args[0] + options.dig_filename = args[1] + + if options.freq is None: + parser.print_help() + sys.stderr.write('You must specify the frequency with -f FREQ\n'); + raise SystemExit, 1 + + try: + tb = my_top_block(options) + tb.run() + except KeyboardInterrupt: + pass diff --git a/gr-gpio/src/python/gpio_usrp_fft.py b/gr-gpio/src/python/gpio_usrp_fft.py new file mode 100755 index 0000000000..cde0de05ae --- /dev/null +++ b/gr-gpio/src/python/gpio_usrp_fft.py @@ -0,0 +1,333 @@ +#!/usr/bin/env python +# +# Copyright 2004,2005,2007,2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gru +from gnuradio import usrp +from gnuradio import eng_notation +from gnuradio.eng_option import eng_option +from gnuradio.wxgui import stdgui2, fftsink2, waterfallsink2, scopesink2, form, slider +from optparse import OptionParser +import wx +import sys +import numpy + +from gnuradio import gpio + +def pick_subdevice(u): + """ + The user didn't specify a subdevice on the command line. + If there's a daughterboard on A, select A. + If there's a daughterboard on B, select B. + Otherwise, select A. + """ + if u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem + return (0, 0) + #if u.db[1][0].dbid() >= 0: #disable the use of RXB + # return (1, 0) + return (0, 0) + + +class app_top_block(stdgui2.std_top_block): + def __init__(self, frame, panel, vbox, argv): + stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) + + self.frame = frame + self.panel = panel + + parser = OptionParser(option_class=eng_option) + parser.add_option("-w", "--which", type="int", default=0, + help="select which USRP (0, 1, ...) default is %default", + metavar="NUM") +# parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, +# help="select USRP Rx side A or B (default=first one with a daughterboard)") + parser.add_option("-A", "--antenna", default=None, + help="select Rx Antenna (only on RFX-series boards)") + parser.add_option("-d", "--decim", type="int", default=32, + help="set fgpa decimation rate to DECIM [default=%default]") + parser.add_option("-f", "--freq", type="eng_float", default=0.0, + help="set frequency to FREQ", metavar="FREQ") + parser.add_option("-g", "--gain", type="eng_float", default=None, + help="set gain in dB (default is midpoint)") + parser.add_option("-W", "--waterfall", action="store_true", default=False, + help="Enable waterfall display") + parser.add_option("-8", "--width-8", action="store_true", default=False, + help="Enable 8-bit samples across USB") +# parser.add_option( "--no-hb", action="store_true", default=False, +# help="don't use halfband filter in usrp") + parser.add_option("-S", "--oscilloscope", action="store_true", default=False, + help="Enable oscilloscope display (default)") + parser.add_option("-F", "--fft", action="store_true", default=False, + help="Enable FFT display") + parser.add_option("-n", "--frame-decim", type="int", default=1, + help="set oscope frame decimation factor to n [default=1]") + parser.add_option("-v", "--v-scale", type="eng_float", default=1, + help="set oscope initial V/div to SCALE [default=%default]") + parser.add_option("-t", "--t-scale", type="eng_float", default=10e-6, + help="set oscope initial s/div to SCALE [default=10us]") + parser.add_option ("--digital", action="store_true", default=False, + help="show (only) the digital wave on lsb (will be input from gpio pins with special usrp firmware)") + parser.add_option ("--analog", action="store_true", default=False, + help="show (only) the analog wave on msbs (will be input from analog inputs)") + parser.add_option ("--file", default=None, + help="input from file FILE in stead of USRP (will be input from raw file in interleaved short format)") + (options, args) = parser.parse_args() + if len(args) != 0: + parser.print_help() + sys.exit(1) + self.options = options + self.show_debug_info = True + + self.u = usrp.source_s(which=options.which, decim_rate=options.decim, fpga_filename=gpio.fpga_filename) + + print "Warning: This script only supports boards on RXA, change the script if you want otherwise" + #options.rx_subdev_spec=(0, 0)#force the use of RXA + options.rx_subdev_spec=None #force the use of RXA + + if options.rx_subdev_spec is None: + options.rx_subdev_spec = pick_subdevice(self.u) + + #This hardcoded mux setting is why this script only supports RXA + #We want both I and Q active, even when using basicRX + #set to 0x10 for RXA + #set to 0x32 for RXB + self.u.set_mux(0x10) #usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) + + if options.width_8: + width = 8 + shift = 8 + format = self.u.make_format(width, shift) + print "format =", hex(format) + r = self.u.set_format(format) + print "set_format =", r + + # determine the daughterboard subdevice we're using + self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) + #if options.rx_subdev_spec==(0,0): + # rx_subdev_spec2=(0,1) + # self.subdev2 = usrp.selected_subdev(self.u, rx_subdev_spec2) + input_rate = self.u.adc_freq() / self.u.decim_rate() + + if options.waterfall: + self.scope = \ + waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate) + elif options.fft: + self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, sample_rate=input_rate) + else: # options.oscilloscope: + #self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate) + self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate, + frame_decim=options.frame_decim, + v_scale=options.v_scale, + t_scale=options.t_scale) + + self.is2c = gr.interleaved_short_to_complex() + if not (options.file is None): + self.filesrc=gr.file_source(gr.sizeof_short, options.file, True) + thr = gr.throttle(gr.sizeof_short, input_rate) + self.connect(self.filesrc,thr,self.is2c,self.scope) + elif options.digital: + self.select_dig=gpio.and_const_ss(0x0001) + self.connect(self.u, self.select_dig,self.is2c,self.scope) + elif options.analog: + self.select_ana=gpio.and_const_ss(0xFFFE) + self.connect(self.u, self.select_ana,self.is2c,self.scope) + else: + self.connect(self.u,self.is2c,self.scope) + + self._build_gui(vbox) + self._setup_events() + + # set initial values + + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = self.subdev.gain_range() + options.gain = float(g[0]+g[1])/2 + + if options.freq is None: + # if no freq was specified, use the mid-point + r = self.subdev.freq_range() + options.freq = float(r[0]+r[1])/2 + + self.set_gain(options.gain) + + if options.antenna is not None: + print "Selecting antenna %s" % (options.antenna,) + self.subdev.select_rx_antenna(options.antenna) + + if self.show_debug_info: + self.myform['decim'].set_value(self.u.decim_rate()) + self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) + self.myform['dbname'].set_value(self.subdev.name()) + self.myform['baseband'].set_value(0) + self.myform['ddc'].set_value(0) + + if not(self.set_freq(options.freq)): + self._set_status_msg("Failed to set initial frequency") + + def _set_status_msg(self, msg): + self.frame.GetStatusBar().SetStatusText(msg, 0) + + def _build_gui(self, vbox): + + def _form_set_freq(kv): + return self.set_freq(kv['freq']) + + vbox.Add(self.scope.win, 10, wx.EXPAND) + + # add control area at the bottom + self.myform = myform = form.form() + hbox = wx.BoxSizer(wx.HORIZONTAL) + hbox.Add((5,0), 0, 0) + myform['freq'] = form.float_field( + parent=self.panel, sizer=hbox, label="Center freq", weight=1, + callback=myform.check_input_and_call(_form_set_freq, self._set_status_msg)) + + hbox.Add((5,0), 0, 0) + g = self.subdev.gain_range() + myform['gain'] = form.slider_field(parent=self.panel, sizer=hbox, label="Gain", + weight=3, + min=int(g[0]), max=int(g[1]), + callback=self.set_gain) + + hbox.Add((5,0), 0, 0) + vbox.Add(hbox, 0, wx.EXPAND) + + self._build_subpanel(vbox) + + def _build_subpanel(self, vbox_arg): + # build a secondary information panel (sometimes hidden) + + # FIXME figure out how to have this be a subpanel that is always + # created, but has its visibility controlled by foo.Show(True/False) + + def _form_set_decim(kv): + return self.set_decim(kv['decim']) + + if not(self.show_debug_info): + return + + panel = self.panel + vbox = vbox_arg + myform = self.myform + + #panel = wx.Panel(self.panel, -1) + #vbox = wx.BoxSizer(wx.VERTICAL) + + hbox = wx.BoxSizer(wx.HORIZONTAL) + hbox.Add((5,0), 0) + + myform['decim'] = form.int_field( + parent=panel, sizer=hbox, label="Decim", + callback=myform.check_input_and_call(_form_set_decim, self._set_status_msg)) + + hbox.Add((5,0), 1) + myform['fs@usb'] = form.static_float_field( + parent=panel, sizer=hbox, label="Fs@USB") + + hbox.Add((5,0), 1) + myform['dbname'] = form.static_text_field( + parent=panel, sizer=hbox) + + hbox.Add((5,0), 1) + myform['baseband'] = form.static_float_field( + parent=panel, sizer=hbox, label="Analog BB") + + hbox.Add((5,0), 1) + myform['ddc'] = form.static_float_field( + parent=panel, sizer=hbox, label="DDC") + + hbox.Add((5,0), 0) + vbox.Add(hbox, 0, wx.EXPAND) + + + def set_freq(self, target_freq): + """ + Set the center frequency we're interested in. + + @param target_freq: frequency in Hz + @rypte: bool + + Tuning is a two step process. First we ask the front-end to + tune as close to the desired frequency as it can. Then we use + the result of that operation and our target_frequency to + determine the value for the digital down converter. + """ + r = self.u.tune(0, self.subdev, target_freq) + + if r: + self.myform['freq'].set_value(target_freq) # update displayed value + if self.show_debug_info: + self.myform['baseband'].set_value(r.baseband_freq) + self.myform['ddc'].set_value(r.dxc_freq) + if not self.options.waterfall and not self.options.oscilloscope: + self.scope.win.set_baseband_freq(target_freq) + return True + + return False + + def set_gain(self, gain): + self.myform['gain'].set_value(gain) # update displayed value + self.subdev.set_gain(gain) + + def set_decim(self, decim): + ok = self.u.set_decim_rate(decim) + if not ok: + print "set_decim failed" + input_rate = self.u.adc_freq() / self.u.decim_rate() + self.scope.set_sample_rate(input_rate) + if self.show_debug_info: # update displayed values + self.myform['decim'].set_value(self.u.decim_rate()) + self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) + return ok + + def _setup_events(self): + if not self.options.waterfall and not self.options.oscilloscope: + self.scope.win.Bind(wx.EVT_LEFT_DCLICK, self.evt_left_dclick) + + def evt_left_dclick(self, event): + (ux, uy) = self.scope.win.GetXY(event) + if event.CmdDown(): + # Re-center on maximum power + points = self.scope.win._points + if self.scope.win.peak_hold: + if self.scope.win.peak_vals is not None: + ind = numpy.argmax(self.scope.win.peak_vals) + else: + ind = int(points.shape()[0]/2) + else: + ind = numpy.argmax(points[:,1]) + (freq, pwr) = points[ind] + target_freq = freq/self.scope.win._scale_factor + print ind, freq, pwr + self.set_freq(target_freq) + else: + # Re-center on clicked frequency + target_freq = ux/self.scope.win._scale_factor + self.set_freq(target_freq) + + +def main (): + app = stdgui2.stdapp(app_top_block, "USRP FFT", nstatus=1) + app.MainLoop() + +if __name__ == '__main__': + main () diff --git a/gr-gpio/src/python/gpio_usrp_siggen.py b/gr-gpio/src/python/gpio_usrp_siggen.py new file mode 100755 index 0000000000..0a0ea685b0 --- /dev/null +++ b/gr-gpio/src/python/gpio_usrp_siggen.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# +from gnuradio import gr, gru +from gnuradio import usrp +from gnuradio.eng_option import eng_option +from gnuradio import eng_notation +from optparse import OptionParser +import sys + +from gnuradio import gpio + +class my_top_block(gr.top_block): + def __init__ (self): + gr.top_block.__init__(self) + + # controllable values + self.interp = 64 + self.waveform_type = gr.GR_CONST_WAVE + self.waveform_ampl = 16000 + self.waveform_freq = 100.12345e3 + self.waveform_offset = 0 + self._instantiate_blocks () + self.set_waveform_type (self.waveform_type) + + def usb_freq (self): + return self.u.dac_freq() / self.interp + + def usb_throughput (self): + return self.usb_freq () * 4 + + def set_waveform_type (self, type): + ''' + valid waveform types are: gr.GR_SIN_WAVE, gr.GR_CONST_WAVE, + gr.GR_UNIFORM and gr.GR_GAUSSIAN + ''' + self._configure_graph (type) + self.waveform_type = type + + def set_waveform_ampl (self, ampl): + self.waveform_ampl = ampl + self.siggen.set_amplitude (ampl) + self.noisegen.set_amplitude (ampl) + + def set_waveform_freq (self, freq): + self.waveform_freq = freq + self.siggen.set_frequency (freq) + + def set_waveform_offset (self, offset): + self.waveform_offset = offset + self.siggen.set_offset (offset) + + def set_interpolator (self, interp): + self.interp = interp + self.siggen.set_sampling_freq (self.usb_freq ()) + self.u.set_interp_rate (interp) + + def _instantiate_blocks (self): + self.src = None + self.u = usrp.sink_c (0, self.interp,fpga_filename=gpio.fpga_filename) + + self.siggen = gr.sig_source_c (self.usb_freq (), + gr.GR_SIN_WAVE, + self.waveform_freq, + self.waveform_ampl, + self.waveform_offset) + + self.noisegen = gr.noise_source_c (gr.GR_UNIFORM, + self.waveform_ampl) + self.vecgen = gr.vector_source_c ([complex(1.0,0.0),complex(0.0,0.0),complex(1.0,1.0),complex(0.0,1.0)],True) + + # self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat") + + def _configure_graph (self, type): + was_running = self.is_running () + if was_running: + self.stop () + self.disconnect_all () + if type == gr.GR_SIN_WAVE: + self.connect (self.siggen, self.u) + # self.connect (self.siggen, self.file_sink) + self.siggen.set_waveform (type) + self.src = self.siggen + elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN: + self.connect (self.noisegen, self.u) + self.noisegen.set_type (type) + self.src = self.noisegen + elif type == gr.GR_CONST_WAVE: + self.connect (self.vecgen, self.u) + self.src = self.vecgen + else: + raise ValueError, type + if was_running: + self.start () + + def set_freq(self, target_freq): + """ + Set the center frequency we're interested in. + + @param target_freq: frequency in Hz + @rypte: bool + + Tuning is a two step process. First we ask the front-end to + tune as close to the desired frequency as it can. Then we use + the result of that operation and our target_frequency to + determine the value for the digital up converter. + """ + r = self.u.tune(self.subdev._which, self.subdev, target_freq) + if r: + #print "r.baseband_freq =", eng_notation.num_to_str(r.baseband_freq) + #print "r.dxc_freq =", eng_notation.num_to_str(r.dxc_freq) + #print "r.residual_freq =", eng_notation.num_to_str(r.residual_freq) + #print "r.inverted =", r.inverted + return True + + return False + + + +def main (): + parser = OptionParser (option_class=eng_option) + parser.add_option ("-T", "--tx-subdev-spec", type="subdev", default=(0, 0), + help="select USRP Tx side A or B") + parser.add_option ("-f", "--rf-freq", type="eng_float", default=None, + help="set RF center frequency to FREQ") + parser.add_option ("-i", "--interp", type="int", default=512, + help="set fgpa interpolation rate to INTERP [default=%default]") + parser.add_option ("--sine", dest="type", action="store_const", const=gr.GR_SIN_WAVE, + help="generate a complex sinusoid [default]", default=gr.GR_SIN_WAVE) + + parser.add_option ("--gaussian", dest="type", action="store_const", const=gr.GR_GAUSSIAN, + help="generate Gaussian random output") + parser.add_option ("--uniform", dest="type", action="store_const", const=gr.GR_UNIFORM, + help="generate Uniform random output") + + parser.add_option ("-w", "--waveform-freq", type="eng_float", default=100e3, + help="set waveform frequency to FREQ [default=%default]") + parser.add_option ("-a", "--amplitude", type="eng_float", default=16e3, + help="set waveform amplitude to AMPLITUDE [default=%default]", metavar="AMPL") + parser.add_option ("-g", "--gain", type="eng_float", default=None, + help="set output gain to GAIN [default=%default]") + parser.add_option ("-o", "--offset", type="eng_float", default=0, + help="set waveform offset to OFFSET [default=%default]") + parser.add_option ("--digital", dest="type", action="store_const", const=gr.GR_CONST_WAVE, + help="generate (only) a digital wave on lsb (will be output on gpio pins with special usrp firmware)") + (options, args) = parser.parse_args () + + if len(args) != 0: + parser.print_help() + raise SystemExit + + if options.rf_freq is None: + sys.stderr.write("usrp_siggen: must specify RF center frequency with -f RF_FREQ\n") + parser.print_help() + raise SystemExit + + tb = my_top_block() + tb.set_interpolator (options.interp) + tb.set_waveform_type (options.type) + tb.set_waveform_freq (options.waveform_freq) + tb.set_waveform_ampl (options.amplitude) + tb.set_waveform_offset (options.offset) + + # determine the daughterboard subdevice we're using + if options.tx_subdev_spec is None: + options.tx_subdev_spec = usrp.pick_tx_subdevice(tb.u) + + m = usrp.determine_tx_mux_value(tb.u, options.tx_subdev_spec) + #print "mux = %#04x" % (m,) + tb.u.set_mux(m) + tb.subdev = usrp.selected_subdev(tb.u, options.tx_subdev_spec) + print "Using TX d'board %s" % (tb.subdev.side_and_name(),) + + if options.gain is None: + tb.subdev.set_gain(tb.subdev.gain_range()[1]) # set max Tx gain + else: + tb.subdev.set_gain(options.gain) # set max Tx gain + + if not tb.set_freq(options.rf_freq): + sys.stderr.write('Failed to set RF frequency\n') + raise SystemExit + + tb.subdev.set_enable(True) # enable transmitter + + try: + tb.run() + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main () diff --git a/gr-gpio/src/python/qa_gpio.py b/gr-gpio/src/python/qa_gpio.py new file mode 100755 index 0000000000..1d140c2484 --- /dev/null +++ b/gr-gpio/src/python/qa_gpio.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +# This is different from the usage after installation +import gpio_swig + +class qa_gpio (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block() + + def tearDown (self): + self.tb = None + +if __name__ == '__main__': + gr_unittest.main () diff --git a/gr-gpio/src/python/run_tests.in b/gr-gpio/src/python/run_tests.in new file mode 100644 index 0000000000..999e4634cf --- /dev/null +++ b/gr-gpio/src/python/run_tests.in @@ -0,0 +1,10 @@ +#!/bin/sh + +# 1st parameter is absolute path to component source directory +# 2nd parameter is absolute path to component build directory +# 3rd parameter is path to Python QA directory + +@top_builddir@/run_tests.sh \ + @abs_top_srcdir@/gr-gpio \ + @abs_top_builddir@/gr-gpio \ + @srcdir@ |