From 12516c53fb74bc8afc0dea8617ecff902d0131af Mon Sep 17 00:00:00 2001 From: John McMaster Date: Tue, 30 Jan 2018 14:43:18 -0800 Subject: [PATCH] roi_harness: Basys3 LED switch demo Signed-off-by: John McMaster --- minitests/roi_harness/.gitignore | 4 ++ minitests/roi_harness/demo_sw_led.py | 31 ++++++++++++ minitests/roi_harness/demo_sw_led_fasm.py | 57 +++++++++++++++++++++++ minitests/roi_harness/test_demo_sw_led.py | 16 +++++++ 4 files changed, 108 insertions(+) create mode 100644 minitests/roi_harness/demo_sw_led.py create mode 100644 minitests/roi_harness/demo_sw_led_fasm.py create mode 100644 minitests/roi_harness/test_demo_sw_led.py diff --git a/minitests/roi_harness/.gitignore b/minitests/roi_harness/.gitignore index dd262534..b24efbad 100644 --- a/minitests/roi_harness/.gitignore +++ b/minitests/roi_harness/.gitignore @@ -7,3 +7,7 @@ /vivado* /design.txt /out_* +/*.fasm +/*.bit +/*.bin +/*.frm diff --git a/minitests/roi_harness/demo_sw_led.py b/minitests/roi_harness/demo_sw_led.py new file mode 100644 index 00000000..161151f1 --- /dev/null +++ b/minitests/roi_harness/demo_sw_led.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import subprocess +import demo_sw_led_fasm +import os + +def run(roi_dir, swn, ledn): + design_txt_fn = roi_dir + '/design.txt' + bit_ref_fn = roi_dir + '/design.bit' + fasm_fn = 'demo_sw_led.fasm' + bit_out_fn = 'demo_sw_led.bit' + ocd_cfg = os.getenv('XRAY_DIR') + '/utils/openocd/board-digilent-basys3.cfg' + + # Clean up old tmp files to be sure we are generating them fresh + subprocess.call('rm -f %s %s' % (fasm_fn, bit_out_fn), shell=True) + + # subprocess.shell("python3 demo_sw_led.py out_xc7a35tcpg236-1_BASYS3-SWBUT_roi_basev/design.txt 0 0 demo.fasm") + demo_sw_led_fasm.run(open(design_txt_fn, 'r'), swn, ledn, open(fasm_fn, 'w')) + subprocess.check_call("./fasm2bit.sh %s %s %s" % (fasm_fn, bit_ref_fn , bit_out_fn), shell=True) + subprocess.check_call('openocd -f %s -c "init; pld load 0 %s; exit"' % (ocd_cfg, bit_out_fn), shell=True) + +if __name__ == '__main__': + import argparse + + parser = argparse.ArgumentParser(description='Basys3 switch to LED interconnect demo. Compiles and programs') + parser.add_argument('roi_dir', help='ROI project dir for harness .bit and metadata.txt') + parser.add_argument('sw', type=int, help='Switch to use') + parser.add_argument('led', type=int, help='LED to use') + + args = parser.parse_args() + run(args.roi_dir, args.sw, args.led) diff --git a/minitests/roi_harness/demo_sw_led_fasm.py b/minitests/roi_harness/demo_sw_led_fasm.py new file mode 100644 index 00000000..a773fee2 --- /dev/null +++ b/minitests/roi_harness/demo_sw_led_fasm.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +import sys +import os +sys.path.append(os.getenv("XRAY_DIR") + "/tools") +import simpleroute + +print() +print('ready') + +def load_design(f): + ''' + name node pin wire + clk CLK_HROW_TOP_R_X60Y130/CLK_HROW_CK_BUFHCLK_L0 W5 HCLK_VBRK_X34Y130/HCLK_VBRK_CK_BUFHCLK0 + din[0] INT_R_X9Y100/NE2BEG3 V17 VBRK_X29Y106/VBRK_NE2A3 + ''' + ret = {} + f.readline() + for l in f: + l = l.strip() + name,node,pin,wire = l.split(' ') + ret[name] = wire + return ret + +def route2fasm(route, out_f): + pips = simpleroute.route(route) + for pip in pips: + # INT_L_X10Y122.NL1BEG2.NE2END3 + # to + # INT_L_X10Y122.NL1BEG2 NE2END3 + doti = pip.rfind('.') + pip = pip[0:doti] + ' ' + pip[doti + 1:] + out_f.write(pip + '\n') + +def run(design_f, swn, ledn, out_f): + name2wire = load_design(design_f) + led_name = 'dout[%d]' % ledn + sw_name = 'din[%d]' % swn + led_wire = name2wire[led_name] + sw_wire = name2wire[sw_name] + print('Routing %s (%s) => %s (%s)' % (sw_wire, sw_name, led_wire, led_name)) + + route2fasm((sw_wire, led_wire), out_f) + # XXX: terminate LEDs so they are off? + +if __name__ == '__main__': + import argparse + + parser = argparse.ArgumentParser(description='Switch to LED interconnect demo: FASM generator') + parser.add_argument('design_txt', help='ROI metadata file') + parser.add_argument('sw', type=int, help='Switch to use') + parser.add_argument('led', type=int, help='LED to use') + # For now can't use stdout since simpleroute is spewing out prints + parser.add_argument('out_fasm', help='Output .fasm file') + + args = parser.parse_args() + run(open(args.design_txt, 'r'), args.sw, args.led, open(args.out_fasm, 'w')) diff --git a/minitests/roi_harness/test_demo_sw_led.py b/minitests/roi_harness/test_demo_sw_led.py new file mode 100644 index 00000000..0a35abd6 --- /dev/null +++ b/minitests/roi_harness/test_demo_sw_led.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +import unittest +import demo_sw_led + +class TestStringMethods(unittest.TestCase): + def test_all(self): + for i in range(8): + print() + print() + print() + print(i) + demo_sw_led.run('out_xc7a35tcpg236-1_BASYS3-SWBUT_roi_basev', i, i) + +if __name__ == '__main__': + unittest.main()