summaryrefslogtreecommitdiffstats
path: root/firmware/fx2/utils
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-11-05 21:22:54 -0700
committerJosh Blum <josh@joshknows.com>2010-11-05 21:22:54 -0700
commit374f6ff05e66d10830a7567d2d793de2bf77c06b (patch)
treeca170bd9473de690ffff45b2041cf10f83fb0228 /firmware/fx2/utils
parent92b5034cb5a6e17fe7ebc437f7ef26147d69eba3 (diff)
parentc2cc364f9fde9633e2d7c04fa5b07275e17ba093 (diff)
downloaduhd-374f6ff05e66d10830a7567d2d793de2bf77c06b.tar.gz
uhd-374f6ff05e66d10830a7567d2d793de2bf77c06b.tar.bz2
uhd-374f6ff05e66d10830a7567d2d793de2bf77c06b.zip
Merge branch 'master' into flow_ctrl
Conflicts: host/lib/usrp/usrp2/mboard_impl.cpp host/lib/usrp/usrp2/usrp2_impl.hpp
Diffstat (limited to 'firmware/fx2/utils')
-rwxr-xr-xfirmware/fx2/utils/build_eeprom.py112
-rwxr-xr-xfirmware/fx2/utils/edit-gpif.py114
-rwxr-xr-xfirmware/fx2/utils/generate_regs.py57
3 files changed, 283 insertions, 0 deletions
diff --git a/firmware/fx2/utils/build_eeprom.py b/firmware/fx2/utils/build_eeprom.py
new file mode 100755
index 000000000..298ccc00c
--- /dev/null
+++ b/firmware/fx2/utils/build_eeprom.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2006 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 re
+import sys
+import os, os.path
+from optparse import OptionParser
+
+# USB Vendor and Product ID's
+
+VID = 0xfffe # Free Software Folks
+
+
+def msb (x):
+ return (x >> 8) & 0xff
+
+def lsb (x):
+ return x & 0xff
+
+def build_eeprom_image (filename, rev):
+ """Build a ``C2 Load'' EEPROM image.
+
+ For details on this format, see section 3.4.3 of
+ the EZ-USB FX2 Technical Reference Manual
+ """
+ # get the code we want to run
+ f = open(filename, 'rb')
+ bytes = f.read()
+
+ devid = 4 #for compatibility
+ start_addr = 0 #prove me wrong
+
+ if(rev == 1):
+ PID = 0x0002 #USRP1
+ else:
+ PID = 0x0003 #USRP1P
+
+ rom_header = [
+ 0xC2, # boot from EEPROM
+ lsb (VID),
+ msb (VID),
+ lsb (PID),
+ msb (PID),
+ lsb (devid),
+ msb (devid),
+ 0 # configuration byte
+ ]
+
+ # 4 byte header that indicates where to load
+ # the immediately follow code bytes.
+ code_header = [
+ msb (len (bytes)),
+ lsb (len (bytes)),
+ msb (start_addr),
+ lsb (start_addr)
+ ]
+
+ # writes 0 to CPUCS reg (brings FX2 out of reset)
+ trailer = [
+ 0x80,
+ 0x01,
+ 0xe6,
+ 0x00,
+ 0x00
+ ]
+
+ image = rom_header + code_header + [ord(c) for c in bytes] + trailer
+
+ assert (len (image) <= 256)
+ return image
+
+if __name__ == '__main__':
+ usage = "usage: %prog -r REV [options] bootfile.bin outfile.bin"
+ parser = OptionParser (usage=usage)
+ parser.add_option ("-r", "--rev", type="int", default=-1,
+ help="Specify USRP revision, 1 for USRP1, 2 for USRP1P")
+ (options, args) = parser.parse_args ()
+ if len (args) != 2:
+ parser.print_help ()
+ sys.exit (1)
+ if options.rev < 0:
+ sys.stderr.write (
+ "You must specify the USRP revision number (2 or 4) with -r REV\n")
+ sys.exit (1)
+
+ infile = args[0]
+ outfile = args[1]
+
+ image = "".join(chr(c) for c in build_eeprom_image(infile, options.rev))
+
+ f = open(outfile, 'wb')
+ f.write(str(image))
+ f.close()
diff --git a/firmware/fx2/utils/edit-gpif.py b/firmware/fx2/utils/edit-gpif.py
new file mode 100755
index 000000000..5367b75a5
--- /dev/null
+++ b/firmware/fx2/utils/edit-gpif.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+# -*- Python -*-
+#
+# Copyright 2003 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.
+#
+
+
+# Edit the gpif.c file generated by the Cypress GPIF Designer Tool and
+# produce usrp_gpif.c, and usrp_gpif_inline.h, files suitable for our
+# uses.
+
+import re
+import string
+import sys
+
+def check_flow_state (line, flow_state_dict):
+ mo = re.match (r'/\* Wave (\d) FlowStates \*/ (.*),', line)
+ if mo:
+ wave = int (mo.group (1))
+ data = mo.group (2)
+ split = data.split (',', 8)
+ v = map (lambda x : int (x, 16), split)
+ # print "%s, %s" % (wave, data)
+ # print "split: ", split
+ # print "v : ", v
+ flow_state_dict[wave] = v
+
+
+def delta (xseq, yseq):
+ # set subtraction
+ z = []
+ for x in xseq:
+ if x not in yseq:
+ z.append (x)
+ return z
+
+
+def write_define (output, name, pairs):
+ output.write ('#define %s()\t\\\n' % name)
+ output.write ('do {\t\t\t\t\t\\\n')
+ for reg, val in pairs:
+ output.write ('%14s = 0x%02x;\t\t\t\\\n' % (reg, val))
+ output.write ('} while (0)\n\n')
+
+def write_inlines (output, dict):
+ regs = ['FLOWSTATE', 'FLOWLOGIC', 'FLOWEQ0CTL', 'FLOWEQ1CTL', 'FLOWHOLDOFF',
+ 'FLOWSTB', 'FLOWSTBEDGE', 'FLOWSTBHPERIOD', 'GPIFHOLDAMOUNT']
+
+ READ_FLOW_STATE = 2
+ WRITE_FLOW_STATE = 3
+
+ read_info = zip (regs, dict[READ_FLOW_STATE])
+ write_info = zip (regs, dict[WRITE_FLOW_STATE])
+
+ output.write ('''/*
+ * Machine generated by "edit-gpif". Do not edit by hand.
+ */
+
+''')
+ write_define (output, 'setup_flowstate_common', read_info)
+ write_define (output, 'setup_flowstate_read', delta (read_info, write_info))
+ write_define (output, 'setup_flowstate_write', delta (write_info, read_info))
+
+
+def edit_gpif (input_name, output_name, inline_name):
+ input = open (input_name, 'r')
+ output = open (output_name, 'w')
+ inline = open (inline_name, 'w')
+ flow_state_dict = {}
+
+ output.write ('''/*
+ * Machine generated by "edit-gpif". Do not edit by hand.
+ */
+
+''')
+
+ while 1:
+ line = input.readline ()
+ line = string.replace (line, '\r','')
+ line = re.sub (r' *$', r'', line)
+
+ check_flow_state (line, flow_state_dict)
+
+ line = re.sub (r'#include', r'// #include', line)
+ line = re.sub (r'xdata ', r'', line)
+ if re.search (r'GpifInit', line):
+ break
+
+ output.write (line)
+
+ output.close ()
+ write_inlines (inline, flow_state_dict)
+ inline.close ()
+
+
+# gpif.c usrp_gpif.c usrp_gpif_inline.h
+edit_gpif (sys.argv[1], sys.argv[2], sys.argv[3])
diff --git a/firmware/fx2/utils/generate_regs.py b/firmware/fx2/utils/generate_regs.py
new file mode 100755
index 000000000..656cd5e81
--- /dev/null
+++ b/firmware/fx2/utils/generate_regs.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+import os, os.path
+import re
+import sys
+
+
+# set srcdir to the directory that contains Makefile.am
+try:
+ srcdir = os.environ['srcdir']
+except KeyError, e:
+ srcdir = "."
+srcdir = srcdir + '/'
+
+def open_src (name, mode):
+ global srcdir
+ return open (os.path.join (srcdir, name), mode)
+
+
+def generate_fpga_regs (h_filename, v_filename):
+ const_width = 7 # bit width of constants
+
+ h_file = open_src (h_filename, 'r')
+ v_file = open (v_filename, 'w')
+ v_file.write (
+ '''//
+// This file is machine generated from %s
+// Do not edit by hand; your edits will be overwritten.
+//
+''' % (h_filename,))
+
+ pat = re.compile (r'^#define\s*(FR_\w*)\s*(\w*)(.*)$')
+ pat_bitno = re.compile (r'^#define\s*(bitno\w*)\s*(\w*)(.*)$')
+ pat_bm = re.compile (r'^#define\s*(bm\w*)\s*(\w*)(.*)$')
+ for line in h_file:
+ if re.match ('//|\s*$', line): # comment or blank line
+ v_file.write (line)
+ mo = pat.search (line)
+ mo_bitno =pat_bitno.search (line)
+ mo_bm =pat_bm.search (line)
+ if mo:
+ v_file.write ('`define %-25s %d\'d%s%s\n' % (
+ mo.group (1), const_width, mo.group (2), mo.group (3)))
+ elif mo_bitno:
+ v_file.write ('`define %-25s %s%s\n' % (
+ mo_bitno.group (1), mo_bitno.group (2), mo_bitno.group (3)))
+ elif mo_bm:
+ v_file.write ('`define %-25s %s%s\n' % (
+ mo_bm.group (1), mo_bm.group (2), mo_bm.group (3)))
+
+
+if __name__ == '__main__':
+ if len (sys.argv) != 3:
+ sys.stderr.write ('usage: %s file.h file.v\n' % (sys.argv[0]))
+ sys.exit (1)
+ generate_fpga_regs (sys.argv[1], sys.argv[2])
+