| 1 |
|
| 2 |
|
| 3 |
import os |
| 4 |
import re |
| 5 |
import subprocess |
| 6 |
|
| 7 |
def run_script(port : str, pinName : str): |
| 8 |
with open('template.vhd', 'rt') as f: |
| 9 |
template = f.read() |
| 10 |
|
| 11 |
f.close() |
| 12 |
|
| 13 |
template = template.replace("##PORT##", port) |
| 14 |
template = template.replace("##PORTNAME##", pinName) |
| 15 |
with open('findpin.vhd', 'wt') as f2: |
| 16 |
f2.write(template) |
| 17 |
|
| 18 |
f2.close() |
| 19 |
|
| 20 |
GowinHome = os.getenv('GOWINHOME') |
| 21 |
|
| 22 |
result = subprocess.run(["rm", "unpack.v"]) |
| 23 |
result = subprocess.run([GowinHome+"/IDE/bin/gw_sh", "findpin.tcl"], check=True) |
| 24 |
result = subprocess.run(["gowin_unpack", "-d", "GW1N-9", "impl/pnr/project.fs"], check=True) |
| 25 |
|
| 26 |
with open('unpack.v', 'rt') as f3: |
| 27 |
unpackv = f3.readline() |
| 28 |
|
| 29 |
iobre = re.compile("\(([a-zA-Z0-9_]*)\)") |
| 30 |
|
| 31 |
matches = iobre.findall(unpackv) |
| 32 |
|
| 33 |
print("Found IOB: ", matches[0]) |
| 34 |
|
| 35 |
with open('pin_report.txt', 'a+') as f: |
| 36 |
f.write(pinName + " -> " + matches[0] + "\n") |
| 37 |
|
| 38 |
f.close() |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
result = subprocess.run(["rm", "pin_report.txt"]) |
| 46 |
|
| 47 |
|
| 48 |
pins = [ |
| 49 |
["IO_sdram_dq", 16, 0], |
| 50 |
["O_sdram_clk", 0, 0], |
| 51 |
["O_sdram_cke", 0, 0], |
| 52 |
["O_sdram_cs_n", 0, 0], |
| 53 |
["O_sdram_cas_n", 0, 0], |
| 54 |
["O_sdram_ras_n", 0, 0], |
| 55 |
["O_sdram_wen_n", 0, 0], |
| 56 |
["O_sdram_addr", 12, 0], |
| 57 |
["O_sdram_dqm", 2, 0], |
| 58 |
["O_sdram_ba", 2, 0] |
| 59 |
] |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
for pin in pins: |
| 64 |
pinName = pin[0] |
| 65 |
pinBuswidth = pin[1] |
| 66 |
pinOffset = pin[2] |
| 67 |
|
| 68 |
if (pinBuswidth == 0): |
| 69 |
port = pinName |
| 70 |
if (pinName.startswith("O")): |
| 71 |
port = port + " : out std_logic" |
| 72 |
else: |
| 73 |
port = port + " : inout std_logic" |
| 74 |
|
| 75 |
run_script(port, pinName) |
| 76 |
else: |
| 77 |
for pinIdx in range(0, pinBuswidth): |
| 78 |
port = pinName |
| 79 |
if (pinName.startswith("O")): |
| 80 |
port = port + " : out " |
| 81 |
else: |
| 82 |
port = port + " : inout " |
| 83 |
|
| 84 |
actualIdx = pinIdx + pinOffset |
| 85 |
|
| 86 |
port = port + "std_logic_vector(" + str(actualIdx) + " downto " + str(actualIdx) + ")" |
| 87 |
|
| 88 |
run_script(port, pinName+"("+str(actualIdx)+")") |