|
| 1 | +# -*- encoding: ascii -*- |
| 2 | + |
| 3 | +from prga.api.context import * |
| 4 | +from prga.api.flow import * |
| 5 | +from prga.api.config import * |
| 6 | + |
| 7 | +from itertools import product |
| 8 | + |
| 9 | +def run(): |
| 10 | + width, height = 42, 34 |
| 11 | + context = ArchitectureContext('top', width, height, BitchainConfigCircuitryDelegate) |
| 12 | + |
| 13 | + # 1. routing stuff |
| 14 | + clk = context.create_global('clk', is_clock = True, bind_to_position = (0, 1)) |
| 15 | + context.create_segment('L1', 48, 1) |
| 16 | + context.create_segment('L2', 16, 2) |
| 17 | + context.create_segment('L4', 8, 4) |
| 18 | + |
| 19 | + # 2. create IOB |
| 20 | + iob = context.create_io_block('iob') |
| 21 | + while True: |
| 22 | + clkport = iob.create_global(clk) |
| 23 | + outpad = iob.create_input('outpad', 1) |
| 24 | + inpad = iob.create_output('inpad', 1) |
| 25 | + ioinst = iob.instances['io'] |
| 26 | + iff = iob.instantiate(context.primitives['flipflop'], 'iff') |
| 27 | + off = iob.instantiate(context.primitives['flipflop'], 'off') |
| 28 | + iob.connect(clkport, iff.pins['clk']) |
| 29 | + iob.connect(ioinst.pins['inpad'], iff.pins['D']) |
| 30 | + iob.connect(iff.pins['Q'], inpad) |
| 31 | + iob.connect(ioinst.pins['inpad'], inpad) |
| 32 | + iob.connect(clkport, off.pins['clk']) |
| 33 | + iob.connect(off.pins['Q'], ioinst.pins['outpad']) |
| 34 | + iob.connect(outpad, ioinst.pins['outpad']) |
| 35 | + iob.connect(outpad, off.pins['D']) |
| 36 | + break |
| 37 | + |
| 38 | + # 3. create tile |
| 39 | + iotiles = {} |
| 40 | + for orientation in iter(Orientation): |
| 41 | + if orientation.is_auto: |
| 42 | + continue |
| 43 | + iotiles[orientation] = context.create_tile( |
| 44 | + 'io_tile_{}'.format(orientation.name), iob, 8, orientation) |
| 45 | + |
| 46 | + # 5. create CLB |
| 47 | + clb = context.create_logic_block('clb') |
| 48 | + while True: |
| 49 | + clkport = clb.create_global(clk, Orientation.south) |
| 50 | + ceport = clb.create_input('ce', 1, Orientation.south) |
| 51 | + srport = clb.create_input('sr', 1, Orientation.south) |
| 52 | + cin = clb.create_input('cin', 1, Orientation.north) |
| 53 | + for i in range(4): |
| 54 | + inst = clb.instantiate(context.primitives['fraclut6sffc'], 'cluster{}'.format(i)) |
| 55 | + clb.connect(clkport, inst.pins['clk']) |
| 56 | + clb.connect(ceport, inst.pins['ce']) |
| 57 | + clb.connect(srport, inst.pins['sr']) |
| 58 | + clb.connect(clb.create_input('ia' + str(i), 6, Orientation.west), inst.pins['ia']) |
| 59 | + clb.connect(clb.create_input('ib' + str(i), 1, Orientation.west), inst.pins['ib']) |
| 60 | + clb.connect(cin, inst.pins['cin'], pack_pattern = 'carrychain') |
| 61 | + cin = inst.pins['cout'] |
| 62 | + clb.connect(inst.pins['oa'], clb.create_output('oa' + str(i), 1, Orientation.east)) |
| 63 | + clb.connect(inst.pins['ob'], clb.create_output('ob' + str(i), 1, Orientation.east)) |
| 64 | + clb.connect(inst.pins['q'], clb.create_output('q' + str(i), 1, Orientation.east)) |
| 65 | + clb.connect(cin, clb.create_output('cout', 1, Orientation.south), pack_pattern = 'carrychain') |
| 66 | + break |
| 67 | + |
| 68 | + # 6. create direct inter-block tunnels |
| 69 | + context.create_direct_tunnel('carrychain', clb.ports['cout'], clb.ports['cin'], (0, 1)) |
| 70 | + |
| 71 | + # 7. create tile |
| 72 | + clbtile = context.create_tile('clb_tile', clb) |
| 73 | + |
| 74 | + # 8. create BRAM |
| 75 | + bram = context.create_logic_block('bram', 1, 2) |
| 76 | + while True: |
| 77 | + clkport = bram.create_global(clk, Orientation.south, position = (0, 0)) |
| 78 | + addrport1 = bram.create_input('addr1', 10, Orientation.west, position = (0, 0)) |
| 79 | + dinport1 = bram.create_input('data1', 8, Orientation.west, position = (0, 0)) |
| 80 | + weport1 = bram.create_input('we1', 1, Orientation.west, position = (0, 0)) |
| 81 | + doutport1 = bram.create_output('out1', 8, Orientation.east, position = (0, 0)) |
| 82 | + addrport2 = bram.create_input('addr2', 10, Orientation.west, position = (0, 1)) |
| 83 | + dinport2 = bram.create_input('data2', 8, Orientation.west, position = (0, 1)) |
| 84 | + weport2 = bram.create_input('we2', 1, Orientation.west, position = (0, 1)) |
| 85 | + doutport2 = bram.create_output('out2', 8, Orientation.east, position = (0, 1)) |
| 86 | + inst = bram.instantiate(context.primitive_library.get_or_create_memory(10, 8, |
| 87 | + dualport = True), 'ram') |
| 88 | + bram.auto_connect(inst) |
| 89 | + break |
| 90 | + |
| 91 | + # 9. create tile |
| 92 | + bramtile = context.create_tile('bram_tile', bram) |
| 93 | + |
| 94 | + # 10. create sub-array |
| 95 | + subarray = context.create_array('subarray', 5, 4) |
| 96 | + for x, y in product(range(5), range(4)): |
| 97 | + if x == 2: |
| 98 | + if y % 2 == 0: |
| 99 | + subarray.instantiate_element(bramtile, (x, y)) |
| 100 | + else: |
| 101 | + subarray.instantiate_element(clbtile, (x, y)) |
| 102 | + |
| 103 | + # 11. fill top-level array |
| 104 | + for x in range(width): |
| 105 | + for y in range(height): |
| 106 | + if x == 0: |
| 107 | + if y > 0 and y < height - 1: |
| 108 | + context.top.instantiate_element(iotiles[Orientation.west], (x, y)) |
| 109 | + elif x == width - 1: |
| 110 | + if y > 0 and y < height - 1: |
| 111 | + context.top.instantiate_element(iotiles[Orientation.east], (x, y)) |
| 112 | + elif y == 0: |
| 113 | + context.top.instantiate_element(iotiles[Orientation.south], (x, y)) |
| 114 | + elif y == height - 1: |
| 115 | + context.top.instantiate_element(iotiles[Orientation.north], (x, y)) |
| 116 | + elif x % 5 == 1 and y % 4 == 1: |
| 117 | + context.top.instantiate_element(subarray, (x, y)) |
| 118 | + |
| 119 | + # 12. flow |
| 120 | + flow = Flow(( |
| 121 | + CompleteRoutingBox(BlockFCValue(BlockPortFCValue(0.25), BlockPortFCValue(0.1))), |
| 122 | + CompleteSwitch(), |
| 123 | + CompleteConnection(), |
| 124 | + GenerateVerilog('rtl'), |
| 125 | + InjectBitchainConfigCircuitry(), |
| 126 | + GenerateVPRXML('vpr'), |
| 127 | + CompletePhysical(), |
| 128 | + ZeroingBRAMWriteEnable(), |
| 129 | + ZeroingBlockPins(), |
| 130 | + GenerateYosysResources('syn'), |
| 131 | + )) |
| 132 | + |
| 133 | + # 13. run flow |
| 134 | + flow.run(context) |
| 135 | + |
| 136 | + # 14. create a pickled version |
| 137 | + context.pickle('ctx.pickled') |
| 138 | + |
| 139 | +if __name__ == '__main__': |
| 140 | + run() |
0 commit comments