Skip to content

Instantly share code, notes, and snippets.

@daveshah1
Created September 17, 2019 21:30
Show Gist options
  • Save daveshah1/a71bbe90f71f988d1bcbb2dd010913e0 to your computer and use it in GitHub Desktop.
Save daveshah1/a71bbe90f71f988d1bcbb2dd010913e0 to your computer and use it in GitHub Desktop.
Intel FPGA pinout parser
import codecs, sys
# Simple parser for Intel pinout files
# ./extract_pinout.py 10m08da.txt
# Prints a list of bidirectional, non-JTAG, IO pins
delim = "\t"
device_prefix = '"Pin Information for the '
header_fields = ("bank", "vref", "func", "optfunc", "cfunc", "txrx", "elvds", "perf", "pin")
curr_device = None
curr_package = None
curr_pins = []
def print_pinlist():
if curr_device is None:
return
d = curr_device.upper()
p = curr_package.upper()
print("# Device {}, Package {}".format(d, p))
print("_io_{}_{} = [".format(d, p))
pinlist = ", ".join("\"{}\"".format(x) for x in curr_pins)
print(" (\"mfio\", 0, Pins({}))".format(pinlist))
print("]")
print()
def filter_pin(data):
# Return True if a pin is to be included in the list, False otherwide
if data["func"] != "IO":
return False
if data["cfunc"] in ("JTAGEN", "TMS", "TCK", "TDI", "TDO"):
return False
return True
# Have to use 'codecs' here because the trademark symbol
# Intel® use is not UTF-8....
with codecs.open(sys.argv[1], 'r', 'iso-8859-1') as inf:
for line in inf:
sl = line.strip() # remove whitespace
if len(sl) == 0: # ignore empty lines
continue
if sl.startswith(device_prefix):
# Initial comment, with device name
print_pinlist()
curr_package = None
curr_pins.clear()
splitl = sl[len(device_prefix):].split(" ")
family = splitl[0]
curr_device = splitl[1]
continue
elif curr_device is None:
continue
splitl = sl.split(delim)
if len(splitl) < len(header_fields):
continue
if curr_package is None:
# Should be header line with column labels, including
# package name
assert splitl[0] == "Bank Number"
curr_package = splitl[-1]
continue
# Convert from array of fields to a Python dictionary
# for ease of access
entries = {}
for i, k in enumerate(header_fields):
entries[k] = splitl[i]
# Apply filter
if filter_pin(entries):
curr_pins.append(entries["pin"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment