|
| 1 | +from __future__ import absolute_import |
| 2 | +from __future__ import print_function |
| 3 | +import sys |
| 4 | +import os |
| 5 | +import numpy as np |
| 6 | + |
| 7 | +# the next line can be removed after installation |
| 8 | +sys.path.insert(0, os.path.dirname(os.path.dirname( |
| 9 | + os.path.dirname(os.path.abspath(__file__))))) |
| 10 | + |
| 11 | +from veriloggen import * |
| 12 | +import veriloggen.thread as vthread |
| 13 | +import veriloggen.types.axi as axi |
| 14 | + |
| 15 | + |
| 16 | +def mkLed(): |
| 17 | + m = Module('blinkled') |
| 18 | + clk = m.Input('CLK') |
| 19 | + rst = m.Input('RST') |
| 20 | + |
| 21 | + datawidth = 32 |
| 22 | + addrwidth = 10 |
| 23 | + |
| 24 | + maxi = vthread.AXIM(m, 'maxi', clk, rst, datawidth) |
| 25 | + saxi = vthread.AXISLiteRegister(m, 'saxi', clk, rst, |
| 26 | + datawidth=32, length=8) |
| 27 | + |
| 28 | + axi_in = vthread.AXIStreamInFifo(m, 'axi_in', clk, rst, datawidth, |
| 29 | + with_last=True) |
| 30 | + axi_out = vthread.AXIStreamOutFifo(m, 'axi_out', clk, rst, datawidth, |
| 31 | + with_last=True) |
| 32 | + |
| 33 | + fifo_addrwidth = 8 |
| 34 | + fifo_a = vthread.FIFO(m, 'fifo_a', clk, rst, datawidth, fifo_addrwidth) |
| 35 | + fifo_b = vthread.FIFO(m, 'fifo_b', clk, rst, datawidth, fifo_addrwidth) |
| 36 | + fifo_c = vthread.FIFO(m, 'fifo_c', clk, rst, datawidth, fifo_addrwidth) |
| 37 | + |
| 38 | + ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth) |
| 39 | + |
| 40 | + strm0 = vthread.Stream(m, 'mystream_reduce', clk, rst) |
| 41 | + a = strm0.source('a') |
| 42 | + reduce_size = strm0.constant('reduce_size') |
| 43 | + v = a * a |
| 44 | + sum, sum_valid = strm0.ReduceAddValid(v, reduce_size) |
| 45 | + strm0.sink(sum, 'sum', when=sum_valid, when_name='sum_valid') |
| 46 | + |
| 47 | + strm1 = vthread.Stream(m, 'mystream_bias', clk, rst) |
| 48 | + x = strm1.source('x') |
| 49 | + y = strm1.source('y') |
| 50 | + z = x + y |
| 51 | + strm1.sink(z, 'z') |
| 52 | + |
| 53 | + def comp(): |
| 54 | + |
| 55 | + while True: |
| 56 | + saxi.wait_flag(0, value=1, resetvalue=0) |
| 57 | + |
| 58 | + saxi.write(1, 1) # set busy |
| 59 | + |
| 60 | + read_size = saxi.read(2) |
| 61 | + write_size = saxi.read(3) |
| 62 | + reduce_size = saxi.read(4) |
| 63 | + offset = saxi.read(5) |
| 64 | + |
| 65 | + if read_size <= 0: |
| 66 | + read_size = 1 |
| 67 | + if write_size <= 0: |
| 68 | + write_size = 1 |
| 69 | + if reduce_size <= 0: |
| 70 | + reduce_size = 1 |
| 71 | + |
| 72 | + maxi.dma_read(ram_b, offset, 0, write_size) |
| 73 | + |
| 74 | + axi_in.write_fifo(fifo_a, read_size) |
| 75 | + axi_out.read_fifo(fifo_c, write_size) |
| 76 | + |
| 77 | + strm0.set_source_fifo('a', fifo_a, read_size) |
| 78 | + strm0.set_constant('reduce_size', reduce_size) |
| 79 | + strm0.set_sink_fifo('sum', fifo_b, write_size) |
| 80 | + |
| 81 | + strm1.set_source_fifo('x', fifo_b, write_size) |
| 82 | + strm1.set_source('y', ram_b, 0, write_size) |
| 83 | + strm1.set_sink_fifo('z', fifo_c, write_size) |
| 84 | + |
| 85 | + strm0.run() |
| 86 | + strm1.run() |
| 87 | + |
| 88 | + strm0.join() |
| 89 | + strm1.join() |
| 90 | + |
| 91 | + saxi.write(1, 0) # unset busy |
| 92 | + |
| 93 | + th = vthread.Thread(m, 'th_comp', clk, rst, comp) |
| 94 | + fsm = th.start() |
| 95 | + |
| 96 | + return m |
| 97 | + |
| 98 | + |
| 99 | +def run(filename='tmp.v', simtype='iverilog', outputfile=None): |
| 100 | + |
| 101 | + test = mkLed() |
| 102 | + |
| 103 | + if filename is not None: |
| 104 | + test.to_verilog(filename) |
| 105 | + |
| 106 | + return '# verify: PASSED' |
| 107 | + |
| 108 | + |
| 109 | +if __name__ == '__main__': |
| 110 | + rslt = run(filename='tmp.v') |
| 111 | + print(rslt) |
0 commit comments