4 # Copyright 2003 Free Software Foundation, Inc.
6 # This file is part of GNU Radio
8 # GNU Radio is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3, or (at your option)
13 # GNU Radio is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Radio; see the file COPYING. If not, write to
20 # the Free Software Foundation, Inc., 51 Franklin Street,
21 # Boston, MA 02110-1301, USA.
25 # Edit the gpif.c file generated by the Cypress GPIF Designer Tool and
26 # produce usrp_gpif.c, and usrp_gpif_inline.h, files suitable for our
33 def check_flow_state (line, flow_state_dict):
34 mo = re.match (r'/\* Wave (\d) FlowStates \*/ (.*),', line)
36 wave = int (mo.group (1))
38 split = data.split (',', 8)
39 v = map (lambda x : int (x, 16), split)
40 # print "%s, %s" % (wave, data)
41 # print "split: ", split
43 flow_state_dict[wave] = v
46 def delta (xseq, yseq):
55 def write_define (output, name, pairs):
56 output.write ('#define %s()\t\\\n' % name)
57 output.write ('do {\t\t\t\t\t\\\n')
58 for reg, val in pairs:
59 output.write ('%14s = 0x%02x;\t\t\t\\\n' % (reg, val))
60 output.write ('} while (0)\n\n')
62 def write_inlines (output, dict):
63 regs = ['FLOWSTATE', 'FLOWLOGIC', 'FLOWEQ0CTL', 'FLOWEQ1CTL', 'FLOWHOLDOFF',
64 'FLOWSTB', 'FLOWSTBEDGE', 'FLOWSTBHPERIOD', 'GPIFHOLDAMOUNT']
69 read_info = zip (regs, dict[READ_FLOW_STATE])
70 write_info = zip (regs, dict[WRITE_FLOW_STATE])
73 * Machine generated by "edit-gpif". Do not edit by hand.
77 write_define (output, 'setup_flowstate_common', read_info)
78 write_define (output, 'setup_flowstate_read', delta (read_info, write_info))
79 write_define (output, 'setup_flowstate_write', delta (write_info, read_info))
82 def edit_gpif (input_name, output_name, inline_name):
83 input = open (input_name, 'r')
84 output = open (output_name, 'w')
85 inline = open (inline_name, 'w')
89 * Machine generated by "edit-gpif". Do not edit by hand.
95 line = input.readline ()
96 line = string.replace (line, '\r','')
97 line = re.sub (r' *$', r'', line)
99 check_flow_state (line, flow_state_dict)
101 line = re.sub (r'#include', r'// #include', line)
102 line = re.sub (r'xdata ', r'', line)
103 if re.search (r'GpifInit', line):
109 write_inlines (inline, flow_state_dict)
113 # gpif.c usrp_gpif.c usrp_gpif_inline.h
114 edit_gpif (sys.argv[1], sys.argv[2], sys.argv[3])