Created
August 20, 2020 03:35
-
-
Save adamgreig/6a155042cd4db2f63269262e0142657b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Takes an ecpunpack output .config file and a iodb.json and works out attributes | |
set for each package pin as best it can. | |
LFE5U-25F-xBG256 only. | |
""" | |
import re | |
import sys | |
import json | |
import pprint | |
DBPATH = "/usr/share/trellis/database/ECP5/LFE5U-25F/iodb.json" | |
def lookup_pin(iodb, loc, pio): | |
# print("lookup, loc=", loc, "pio=", pio, end="") | |
row, col = loc | |
if row == 0 and col in (5, 7, 10, 12, 14, 16, 19, 21, 23, 25, 28, 30, 34, | |
36, 39, 43, 45, 48, 50, 52, 54, 57, 59, 61, 63, | |
66, 68): | |
col -= 1 | |
if col in (0, 72) and row in (3, 12, 48): | |
row -= 1 | |
# print(", mapped row=", row, "col=", col, ",", iodb.get((row, col, pio))) | |
return iodb.get((row, col, pio)) | |
def load_iodb(): | |
with open(DBPATH, "r") as f: | |
iodb = json.load(f) | |
db = {} | |
for pin, loc in iodb["packages"]["CABGA256"].items(): | |
row = loc["row"] | |
col = loc["col"] | |
pio = loc["pio"] | |
db[(row, col, pio)] = pin | |
return db | |
def process_config(iodb, cfgpath): | |
with open(cfgpath, "r") as f: | |
tiles = {} | |
loc = None | |
for line in f: | |
if line.startswith(".tile"): | |
match = re.search("^.tile MIB_R([0-9]*)C([0-9]*):", line) | |
if not match: | |
loc = None | |
continue | |
row = int(match.group(1)) | |
col = int(match.group(2)) | |
loc = (row, col) | |
if loc not in tiles: | |
tiles[loc] = {} | |
elif loc and line.startswith("enum: PIO"): | |
key, val = line.split()[1:] | |
io, key = key.split(".") | |
io = io[3] | |
if io not in tiles[loc]: | |
tiles[loc][io] = {"pin": lookup_pin(iodb, loc, io)} | |
tiles[loc][io][key] = val.strip() | |
return tiles | |
if __name__ == "__main__": | |
tiles = process_config(load_iodb(), sys.argv[1]) | |
pins = {} | |
for tile in tiles: | |
for pio in tiles[tile]: | |
p = tiles[tile][pio] | |
if p.get("pin"): | |
pins[p["pin"]] = p | |
del pins[p["pin"]]["pin"] | |
pprint.pprint(pins.keys()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment