| # Copyright 2020 Project U-Ray Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import sys |
| import numpy as np |
| |
| bram_init = [] # ypos -> init; initp |
| |
| for y in range(0, 24): |
| bram_init.append(( |
| np.random.randint(0, 2, size=16384), |
| np.random.randint(0, 2, size=2048), |
| )) |
| |
| with open(sys.argv[1] + "/braminit/bram.v", "w") as f: |
| print("module top;", file=f) |
| for y in range(0, 24): |
| print("(* KEEP, DONT_TOUCH, LOC=\"RAMB18_X1Y%d\" *)" % y, file=f) |
| print("RAMB18E2 #(", file=f) |
| for i in range(0, 64): |
| print(" .INIT_%02X(256'b%s)," % (i, "".join([str(x) for x in reversed(bram_init[y][0][ i*256 : (i+1)*256 ])])), file=f) |
| for i in range(0, 8): |
| print(" .INITP_%02X(256'b%s)," % (i, "".join([str(x) for x in reversed(bram_init[y][1][ i*256 : (i+1)*256 ])])), file=f) |
| print(" .DOA_REG(1'b0)", file=f) # just here for simpler commas |
| print(") bram_%d ();" % y, file=f) |
| print("endmodule", file=f) |
| |
| with open(sys.argv[1] + "/braminit/bram.txt", "w") as f: |
| for y in range(0, 24): |
| site_y = y % 2 |
| tile_y = y // 2 |
| startbit = tile_y * 240 |
| if tile_y >= 6: |
| startbit += 96 |
| for frame in range(0, 256): |
| print("%d %d %d %s %s" % |
| ( |
| frame, |
| startbit, |
| site_y, |
| "".join(str(x) for x in bram_init[y][0][ frame*64 : (frame+1)*64 ]), |
| "".join(str(x) for x in bram_init[y][1][ frame*8 : (frame+1)*8 ]), |
| ), file=f) |
| with open(sys.argv[1] + "/braminit/build.tcl", "w") as f: |
| print("add_files %s" % (sys.argv[1] + "/braminit/bram.v"), file=f) |
| print("synth_design -top top -part xczu7ev-ffvc1156-2-e", file=f) |
| print("# set_property CLOCK_DEDICATED_ROUTE FALSE [get_nets]", file=f) |
| print("opt_design", file=f) |
| print("place_design", file=f) |
| print("route_design", file=f) |
| print("set_property SEVERITY {Warning} [get_drc_checks]", file=f) |
| print("set_property BITSTREAM.GENERAL.PERFRAMECRC YES [current_design]", file=f) |
| print("write_checkpoint -force bram.dcp", file=f) |
| print("write_edif -force bram.edf", file=f) |
| print("write_bitstream -force bram.bit", file=f) |