def streaming_ip_a_top(reset, clk, av_snk, av_src): data_enable_o=Signal(bool(0)) av_snk_if = AvalonST_SNK(len(av_snk.data_i)) av_src_if = AvalonST_SRC(len(av_src.data_o)) @always_comb def signal_assignments(): av_snk_if.valid_i.next=av_snk.valid_i av_snk.ready_o.next=av_snk_if.ready_o av_src.valid_o.next=av_src_if.valid_o av_src_if.ready_i.next=av_src.ready_i streaming_ip_a_inst = streaming_ip_a(reset, clk, av_snk_if, av_src_if,data_enable_o ) @always(clk.posedge, reset.posedge) def av_signals_process(): if reset==1: av_src.startofpacket_o.next = 0 av_src.endofpacket_o.next = 0 av_src.data_o.next = 0 av_src.channel_o.next = 0 elif data_enable_o == 1: av_src.startofpacket_o.next = av_snk.startofpacket_i av_src.data_o.next = av_snk.data_i av_src.endofpacket_o.next = av_snk.endofpacket_i av_src.channel_o.next = av_snk.channel_i return instances()
def streaming_ip_wire_convert(): SYMBOL_WIDTH = 8 NR_OF_SYMBOLS = 8 reset = Signal(bool(0)) clk = Signal(bool(0)) av_snk = AvalonST_SNK(SYMBOL_WIDTH * NR_OF_SYMBOLS) av_src = AvalonST_SRC(SYMBOL_WIDTH * NR_OF_SYMBOLS) toVerilog(streaming_ip_wire, reset, clk, av_snk, av_src)
def streaming_ip_a_convert(): DATA_WIDTH = 64 EMPTY_WIDTH = 3 ERROR_WIDTH = 3 CHANNEL_WIDTH = 4 av_snk = AvalonST_SNK(DATA_WIDTH, ERROR_WIDTH, EMPTY_WIDTH, CHANNEL_WIDTH) av_src = AvalonST_SRC(DATA_WIDTH, ERROR_WIDTH, EMPTY_WIDTH, CHANNEL_WIDTH) reset = Signal(bool(0)) clk = Signal(bool(0)) toVerilog(streaming_ip_a_top, reset, clk, av_snk, av_src)
def block_connect(pars, reset, clk, av_snk, av_src ): """ simple load block""" av_snk_if = AvalonST_SNK(pars.SNK_DATAWIDTH) av_src_if = AvalonST_SRC(pars.SRC_DATAWIDTH) @always_comb def signal_assignments(): av_snk_if.valid_i.next=av_snk.valid_i av_snk.ready_o.next=av_snk_if.ready_o av_src.valid_o.next=av_src_if.valid_o av_src_if.ready_i.next=av_src.ready_i streaming_ip_a_top_inst = streaming_ip_a_top(reset, clk, av_snk_if, av_src_if)
def block_connect(self, pars, reset, clk, av_snk0, av_snk1, av_src): """ streaming_simple modesub block""" data_enable_o = Signal(bool(0)) av_snk0_if = AvalonST_SNK(pars.SNK0_DATAWIDTH) av_snk1_if = AvalonST_SNK(pars.SNK1_DATAWIDTH) av_src_if = AvalonST_SRC(pars.SRC_DATAWIDTH) @always_comb def signal_assignments(): av_snk0_if.valid_i.next = av_snk0.valid_i av_snk0.ready_o.next = av_snk0_if.ready_o av_src.valid_o.next = av_src_if.valid_o av_src_if.ready_i.next = av_src.ready_i av_snk1_if.valid_i.next = av_snk1.valid_i av_snk1.ready_o.next = av_snk1_if.ready_o streaming_ip_a_2xinp_inst = streaming_ip_a_2xinp( reset, clk, av_snk0_if, av_snk1_if, av_src_if, data_enable_o) @always(clk.posedge, reset.posedge) def streaming_simple_modesub(): """ streaming_simple modesub """ if reset == 1: av_src.startofpacket_o.next = 0 av_src.endofpacket_o.next = 0 av_src.data_o.next = 0 av_src.channel_o.next = 0 elif data_enable_o == 1: av_src.startofpacket_o.next = av_snk0.startofpacket_i and av_snk1.startofpacket_i av_src.data_o.next = (av_snk0.data_i - av_snk1.data_i) if (av_snk0.data_i > av_snk1.data_i) \ else (av_snk1.data_i - av_snk0.data_i) av_src.endofpacket_o.next = av_snk0.endofpacket_i and av_snk1.endofpacket_i av_src.channel_o.next = av_snk0.channel_i and av_snk1.channel_i return instances()
def sim_streaming_chain_adder(pars_obj): # removing the files if already available for i in range(NB_CHAIN_ADDERS): txdata0_filename[i] = "transmit_data_inpA_adder{:d}.log".format(i) if (os.path.exists(txdata0_filename[i])): os.remove(txdata0_filename[i]) txdata1_filename[i] = "transmit_data_inpB_adder{:d}.log".format(i) if (os.path.exists(txdata1_filename[i])): os.remove(txdata1_filename[i]) rxdata_filename[i] = "receive_data_adder{:d}.log".format(i) if (os.path.exists(rxdata_filename[i])): os.remove(rxdata_filename[i]) reset = Signal(bool(1)) clk = Signal(bool(0)) elapsed_time = Signal(0) nb_transmit = [Signal(int(0)) for i in range(NB_CHAIN_ADDERS)] nb_transmit0 = [Signal(int(0)) for i in range(NB_CHAIN_ADDERS)] nb_transmit1 = [Signal(int(0)) for i in range(NB_CHAIN_ADDERS)] nb_receive = [Signal(int(0)) for i in range(NB_CHAIN_ADDERS)] av_src0_bfm = [ AvalonST_SRC(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS) ] av_src1_bfm = [ AvalonST_SRC(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS) ] av_snk0 = [AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS)] av_snk1 = [AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS)] av_src = [AvalonST_SRC(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS)] av_snk_bfm = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS) ] src_bfm_i = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS) ] src_bfm_0 = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS) ] src_bfm_1 = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS) ] src_bfm_o = [ AvalonST_SRC(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_ADDERS) ] clkgen = clk_driver(elapsed_time, clk, period=20) add_i = [None for i in range(NB_CHAIN_ADDERS)] src0_bfm_inst = [None for i in range(NB_CHAIN_ADDERS)] src1_bfm_inst = [None for i in range(NB_CHAIN_ADDERS)] streaming_chain_adder_inst = None snk_bfm_inst = [None for i in range(NB_CHAIN_ADDERS)] VALID_PATTERN0 = [ random.randint(0x0100, 0xffff) for i in range(NB_CHAIN_ADDERS) ] VALID_PATTERN1 = [ random.randint(0x0100, 0xffff) for i in range(NB_CHAIN_ADDERS) ] READY_PATTERN = [ random.randint(0x0100, 0xffff) for i in range(NB_CHAIN_ADDERS) ] for i in range(NB_CHAIN_ADDERS): print("Chain Adder: " + str(i) + " Valid0: " + str(VALID_PATTERN0[i]) + " Valid1: " + str(VALID_PATTERN1[i]) + " Ready: " + str(READY_PATTERN[i])) src0_bfm_inst[i] = src_bfm(reset, clk, VALID_PATTERN0[i], src_bfm_0[i], av_src0_bfm[i]) src1_bfm_inst[i] = src_bfm(reset, clk, VALID_PATTERN1[i], src_bfm_1[i], av_src1_bfm[i]) snk_bfm_inst[i] = snk_bfm(reset, clk, READY_PATTERN[i], av_snk_bfm[i], src_bfm_o[i]) add_pars = StreamingChainAdderPars() add_pars.SNK0_DATAWIDTH = STREAM_DATA_WIDTH add_pars.SNK1_DATAWIDTH = STREAM_DATA_WIDTH add_pars.SRCD_ATAWIDTH = STREAM_DATA_WIDTH add_pars.NB_CHAIN_ADDERS = NB_CHAIN_ADDERS add_pars(add_pars) add_i = StreamingChainAdder() streaming_chain_adder_inst = add_i.block_connect(add_pars, reset, clk, av_snk0, av_snk1, av_src) snk0_valid_inst = [None for i in range(NB_CHAIN_ADDERS)] snk0_data_inst = [None for i in range(NB_CHAIN_ADDERS)] snk0_ready_inst = [None for i in range(NB_CHAIN_ADDERS)] snk1_valid_inst = [None for i in range(NB_CHAIN_ADDERS)] snk1_data_inst = [None for i in range(NB_CHAIN_ADDERS)] snk1_ready_inst = [None for i in range(NB_CHAIN_ADDERS)] src_valid_inst = [None for i in range(NB_CHAIN_ADDERS)] src_data_inst = [None for i in range(NB_CHAIN_ADDERS)] src_ready_inst = [None for i in range(NB_CHAIN_ADDERS)] for i in range(NB_CHAIN_ADDERS): snk0_valid_inst[i] = simple_wire_assign(av_snk0[i].valid_i, av_src0_bfm[i].valid_o) snk0_data_inst[i] = simple_wire_assign(av_snk0[i].data_i, av_src0_bfm[i].data_o) snk0_ready_inst[i] = simple_wire_assign(av_src0_bfm[i].ready_i, av_snk0[i].ready_o) snk1_valid_inst[i] = simple_wire_assign(av_snk1[i].valid_i, av_src1_bfm[i].valid_o) snk1_data_inst[i] = simple_wire_assign(av_snk1[i].data_i, av_src1_bfm[i].data_o) snk1_ready_inst[i] = simple_wire_assign(av_src1_bfm[i].ready_i, av_snk1[i].ready_o) src_valid_inst[i] = simple_wire_assign(av_snk_bfm[i].valid_i, av_src[i].valid_o) src_data_inst[i] = simple_wire_assign(av_snk_bfm[i].data_i, av_src[i].data_o) src_ready_inst[i] = simple_wire_assign(av_src[i].ready_i, av_snk_bfm[i].ready_o) @always(clk.posedge) def stimulus(): if elapsed_time == 40: reset.next = 0 INIT_DATA0 = [random.randint(1, RANDRANGE) for i in range(NB_CHAIN_ADDERS)] INIT_DATA1 = [random.randint(1, RANDRANGE) for i in range(NB_CHAIN_ADDERS)] data_in0 = [Signal(int(0)) for i in range(NB_CHAIN_ADDERS)] data_in1 = [Signal(int(0)) for i in range(NB_CHAIN_ADDERS)] src_bfm_0_valid_inst = [None for i in range(NB_CHAIN_ADDERS)] src_bfm_1_valid_inst = [None for i in range(NB_CHAIN_ADDERS)] src_bfm_0_data_inst = [None for i in range(NB_CHAIN_ADDERS)] src_bfm_1_data_inst = [None for i in range(NB_CHAIN_ADDERS)] for i in range(NB_CHAIN_ADDERS): src_bfm_0_data_inst[i] = conditional_wire_assign( src_bfm_0[i].data_i, (av_src0_bfm[i].ready_i and av_src0_bfm[i].valid_o), data_in0[i], src_bfm_0[i].data_i) src_bfm_1_data_inst[i] = conditional_wire_assign( src_bfm_1[i].data_i, (av_src1_bfm[i].ready_i and av_src1_bfm[i].valid_o), data_in1[i], src_bfm_1[i].data_i) for i in range(NB_CHAIN_ADDERS): src_bfm_0_valid_inst[i] = conditional_wire_assign_lt( src_bfm_0[i].valid_i, nb_transmit0[i], Signal(MAX_NB_TRANSFERS), 1, 0) src_bfm_1_valid_inst[i] = conditional_wire_assign_lt( src_bfm_1[i].valid_i, nb_transmit1[i], Signal(MAX_NB_TRANSFERS), 1, 0) data_in0_inst = [None for i in range(NB_CHAIN_ADDERS)] data_in1_inst = [None for i in range(NB_CHAIN_ADDERS)] nb_transmit0_inst = [None for i in range(NB_CHAIN_ADDERS)] nb_transmit1_inst = [None for i in range(NB_CHAIN_ADDERS)] transmit_data0_append_inst = [None for i in range(NB_CHAIN_ADDERS)] transmit_data1_append_inst = [None for i in range(NB_CHAIN_ADDERS)] receive_data_append_inst = [None for i in range(NB_CHAIN_ADDERS)] #Datain is randomized values (for next valid data) for i in range(NB_CHAIN_ADDERS): data_in0_inst[i] = conditional_random_generator( reset, clk, data_in0[i], int(INIT_DATA0[i]), (av_src0_bfm[i].ready_i and av_src0_bfm[i].valid_o and src_bfm_0[i].valid_i), RANDRANGE) data_in1_inst[i] = conditional_random_generator( reset, clk, data_in1[i], int(INIT_DATA1[i]), (av_src1_bfm[i].ready_i and av_src1_bfm[i].valid_o and src_bfm_1[i].valid_i), RANDRANGE) nb_transmit0_inst[i] = conditional_reg_counter( reset, clk, nb_transmit0[i], Reset.LOW, (av_src0_bfm[i].ready_i and av_src0_bfm[i].valid_o and src_bfm_0[i].valid_i)) nb_transmit1_inst[i] = conditional_reg_counter( reset, clk, nb_transmit1[i], Reset.LOW, (av_src1_bfm[i].ready_i and av_src1_bfm[i].valid_o and src_bfm_1[i].valid_i)) transmit_data0_append_inst[i] = conditional_clocked_appendfile( reset, clk, (av_src0_bfm[i].ready_i and av_src0_bfm[i].valid_o and src_bfm_0[i].valid_i), data_in0[i], txdata0_filename[i]) transmit_data1_append_inst[i] = conditional_clocked_appendfile( reset, clk, (av_src1_bfm[i].ready_i and av_src1_bfm[i].valid_o and src_bfm_1[i].valid_i), data_in1[i], txdata1_filename[i]) receive_data_append_inst[i] = conditional_clocked_appendfile( reset, clk, (src_bfm_o[i].valid_o), src_bfm_o[i].data_o, rxdata_filename[i]) recv_inst = [None for i in range(NB_CHAIN_ADDERS)] for i in range(NB_CHAIN_ADDERS): recv_inst[i] = conditional_reg_counter(reset, clk, nb_receive[i], Reset.LOW, src_bfm_o[i].valid_o) @always(clk.posedge) def receive_data_process(): TIME_SHUTDOWN = 5000 nb_recv = 0 sim_time_now = now() for i in range(NB_CHAIN_ADDERS): nb_recv += nb_receive[i] if (nb_recv == NB_CHAIN_ADDERS * (MAX_NB_TRANSFERS)): for i in range(NB_CHAIN_ADDERS): print("INF242: adder: " + str(i) + " Num ready pulses: " + str(int(ready_pulses[i]))) raise StopSimulation("Simulation Finished in %d clks: In total " % now() + str(nb_recv) + " data words received") @always(clk.posedge) def simulation_time_check(): sim_time_now = now() if (sim_time_now > MAX_SIM_TIME): raise StopSimulation( "Warning! Simulation Exited upon reaching max simulation time of " + str(MAX_SIM_TIME) + " clocks") ready_pulse_cnt_inst = [None for i in range(NB_CHAIN_ADDERS)] for i in range(NB_CHAIN_ADDERS): ready_pulse_cnt_inst[i] = conditional_reg_counter( reset, clk, ready_pulses[i], Reset.LOW, (av_snk_bfm[i].ready_o)) return instances()
def sim_streaming_ip_comb(pars_obj): PATTERN_WIDTH = 16 DATA_WIDTH = 8 reset = Signal(bool(1)) clk = Signal(bool(0)) elapsed_time=Signal(0) data_enable = Signal(bool(0)) asi_snk_bfm = AvalonST_SNK(DATA_WIDTH) av_snk_dut = AvalonST_SNK(DATA_WIDTH) aso_src_bfm = AvalonST_SRC(DATA_WIDTH) av_src_dut = AvalonST_SRC(DATA_WIDTH) src_bfm_i = AvalonST_SNK(DATA_WIDTH) src_bfm_o = AvalonST_SRC(DATA_WIDTH) clkgen=clk_driver(elapsed_time,clk,period=20) src_bfm_inst = src_bfm(reset, clk, pars_obj.valid, src_bfm_i, aso_src_bfm) streaming_ip_comb_inst = streaming_ip_comb(reset, clk, av_snk_dut, av_src_dut, data_enable ) snk_bfm_inst = snk_bfm(reset, clk, pars_obj.ready, asi_snk_bfm, src_bfm_o) print("Ready Pattern: ", str(hex(pars_obj.ready))) print("Valid Pattern: ", str(hex(pars_obj.valid))) @always_comb def beh_comb_logic(): # Streaming Input Interface av_snk_dut.valid_i.next = aso_src_bfm.valid_o av_snk_dut.data_i.next = aso_src_bfm.data_o aso_src_bfm.ready_i.next = av_snk_dut.ready_o #Streaming Output interface asi_snk_bfm.valid_i.next = av_src_dut.valid_o asi_snk_bfm.data_i.next = av_src_dut.data_o av_src_dut.ready_i.next = asi_snk_bfm.ready_o src_bfm_i.valid_i.next = 1 if (nb1 < MAX_NB_TRANSFERS) else 0 @always_comb def beh_comb_logic_enable(): #data_enable av_src_dut.data_o.next = av_snk_dut.data_i @always(clk.posedge) def stimulus(): if elapsed_time > 40: reset.next = 0 INIT_DATA=1 data_in=Signal(int(0)) @always_comb def transmit_data_process(): if (aso_src_bfm.ready_i == 1 and aso_src_bfm.valid_o == 1): src_bfm_i.data_i.next = data_in #Dataout is just an increment (for next valid data) @always(clk.posedge, reset.posedge) def transmit_data_clk_process(): global trans_data,nb1 if reset==1: data_in.next = int(INIT_DATA) elif (aso_src_bfm.ready_i == 1 and aso_src_bfm.valid_o == 1 and src_bfm_i.valid_i == 1): nb1+=1 #print str(nb1) + ". Transmitted data to src bfm:", ": ", src_bfm_i.data_i trans_data.append(int(data_in)) data_in.next = data_in + 1 @always(clk.posedge) def receive_data_process(): global recv_data,nb2 if (src_bfm_o.valid_o == 1): nb2+=1 #print str(nb2) + ". Received data from sink bfm:", ": ", src_bfm_o.data_o recv_data.append(int(src_bfm_o.data_o)) sim_time_now=now() if (nb2 == MAX_NB_TRANSFERS): raise StopSimulation("Simulation Finished in %d clks: In total " %now() + str(MAX_NB_TRANSFERS) + " data words received") @always(clk.posedge) def simulation_time_check(): sim_time_now=now() if(sim_time_now>MAX_SIM_TIME): raise StopSimulation("Warning! Simulation Exited upon reaching max simulation time of " + str(MAX_SIM_TIME) + " clocks") @always(clk.posedge) def cnt_ready_pulses(): global ready_pulses if (asi_snk_bfm.ready_o == 1): ready_pulses+=1 #print "ready received from bfm" return instances()
from random import randrange from myhdl import Signal, delay, always, now, Simulation, traceSignals, instance, intbv from snk_bfm import snk_bfm from clk_driver import clk_driver from avalon_buses import AvalonST_SNK, AvalonST_SRC valid_ready_pattern_width = 16 DATA_WIDTH = 8 nb2 = int(0) # A global currently inevitable recv_data = [] valid_i_pattern = int(sys.argv[1], valid_ready_pattern_width) ready_i_pattern = int(sys.argv[2], valid_ready_pattern_width) asi_snk = AvalonST_SNK(DATA_WIDTH) src_bfm_o = AvalonST_SRC(DATA_WIDTH) def sim_snk_bfm(): reset = Signal(bool(0)) clk = Signal(bool(0)) elapsed_time = Signal(0) snk_bfm_inst = snk_bfm(reset, clk, ready_i_pattern, asi_snk, src_bfm_o) clkgen = clk_driver(elapsed_time, clk, period=20) @always(clk.posedge) def stimulus(): if elapsed_time > 40: reset.next = 0
def block_connect(self, pars, reset, clk, av_snk0, av_snk1, av_src): """ streaming_simple adder block""" av_snk0_if = [ AvalonST_SNK(pars.SNK0_DATAWIDTH) for i in range(pars.NB_CHAIN_ADDERS) ] av_snk1_if = [ AvalonST_SNK(pars.SNK1_DATAWIDTH) for i in range(pars.NB_CHAIN_ADDERS) ] av_src_if = [ AvalonST_SRC(pars.SRC_DATAWIDTH) for i in range(pars.NB_CHAIN_ADDERS) ] add_pars = StreamingSimpleAdderPars() add_pars.SNK0_DATAWIDTH = pars.SNK0_DATAWIDTH add_pars.SNK1_DATAWIDTH = pars.SNK1_DATAWIDTH add_pars.SRC_DATAWIDTH = pars.SRC_DATAWIDTH snk0_valid_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] snk0_data_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] snk0_ready_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] snk1_valid_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] snk1_data_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] snk1_ready_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] src_valid_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] src_data_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] src_ready_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] for i in range(pars.NB_CHAIN_ADDERS): snk0_valid_inst[i] = simple_wire_assign(av_snk0_if[i].valid_i, av_snk0[i].valid_i) snk0_data_inst[i] = simple_wire_assign(av_snk0_if[i].data_i, av_snk0[i].data_i) snk0_ready_inst[i] = simple_wire_assign(av_snk0[i].ready_o, av_snk0_if[i].ready_o) snk1_valid_inst[i] = simple_wire_assign(av_snk1_if[i].valid_i, av_snk1[i].valid_i) snk1_data_inst[i] = simple_wire_assign(av_snk1_if[i].data_i, av_snk1[i].data_i) snk1_ready_inst[i] = simple_wire_assign(av_snk1[i].ready_o, av_snk1_if[i].ready_o) src_valid_inst[i] = simple_wire_assign(av_src[i].valid_o, av_src_if[i].valid_o) src_data_inst[i] = simple_wire_assign(av_src[i].data_o, av_src_if[i].data_o) src_ready_inst[i] = simple_wire_assign(av_src_if[i].ready_i, av_src[i].ready_i) chain_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] add_inst = [None for i in range(pars.NB_CHAIN_ADDERS)] for i in range(pars.NB_CHAIN_ADDERS): add_inst[i] = StreamingSimpleAdder() chain_inst[i] = add_inst[i].block_connect(add_pars, reset, clk, av_snk0_if[i], av_snk1_if[i], av_src_if[i]) return instances()
def sim_streaming_chain_mult(pars_obj): global rxdata_filename global txdata0_filename global txdata1_filename # removing the files if already available for i in range(NB_CHAIN_MULTIPLIERS): txdata0_filename[i] = "transmit_data_inpA_mult{:d}.log".format(i) if (os.path.exists(txdata0_filename[i])): os.remove(txdata0_filename[i]) txdata1_filename[i] = "transmit_data_inpB_mult{:d}.log".format(i) if (os.path.exists(txdata1_filename[i])): os.remove(txdata1_filename[i]) if (os.path.exists(rxdata_filename)): os.remove(rxdata_filename) reset = Signal(bool(1)) clk = Signal(bool(0)) elapsed_time = Signal(0) nb_transmit = [Signal(int(0)) for i in range(NB_CHAIN_MULTIPLIERS)] nb_transmit0 = [Signal(int(0)) for i in range(NB_CHAIN_MULTIPLIERS)] nb_transmit1 = [Signal(int(0)) for i in range(NB_CHAIN_MULTIPLIERS)] nb_receive = Signal(int(0)) av_src0_bfm = [ AvalonST_SRC(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] av_src1_bfm = [ AvalonST_SRC(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] av_snk0 = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] av_snk1 = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] av_snk_bfm = AvalonST_SNK(STREAM_DATA_WIDTH) src_bfm_i = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] src_bfm_0 = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] src_bfm_1 = [ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] src_bfm_o = AvalonST_SRC(STREAM_DATA_WIDTH) clkgen = clk_driver(elapsed_time, clk, period=20) src0_bfm_inst = [None for i in range(NB_CHAIN_MULTIPLIERS)] src1_bfm_inst = [None for i in range(NB_CHAIN_MULTIPLIERS)] snk_bfm_inst = None VALID_PATTERN0 = [ random.randint(0x0100, 0xffff) for i in range(NB_CHAIN_MULTIPLIERS) ] VALID_PATTERN1 = [ random.randint(0x0100, 0xffff) for i in range(NB_CHAIN_MULTIPLIERS) ] READY_PATTERN = [ random.randint(0x0100, 0xffff) for i in range(NB_CHAIN_MULTIPLIERS) ] for i in range(NB_CHAIN_MULTIPLIERS): print("Chain Mult: " + str(i) + " Valid0: " + str(VALID_PATTERN0[i]) + " Valid1: " + str(VALID_PATTERN1[i]) + " Ready: " + str(READY_PATTERN[i])) src0_bfm_inst[i] = src_bfm(reset, clk, VALID_PATTERN0[i], src_bfm_0[i], av_src0_bfm[i]) src1_bfm_inst[i] = src_bfm(reset, clk, VALID_PATTERN1[i], src_bfm_1[i], av_src1_bfm[i]) snk_bfm_inst = snk_bfm(reset, clk, READY_PATTERN[0], av_snk_bfm, src_bfm_o) i = NB_CHAIN_MULTIPLIERS * 2 nb_chain_mults = 0 nb_chain_mults_list = [] mod_list = [] nb_mult_stages = 0 while i > 1: mod_val = 0 if (i % 2 == 0 or i == 1) else 1 mod_list.append(mod_val) i = i / 2 if (i % 2 == 0) else i / 2 + 1 nb_chain_mults += i nb_chain_mults_list.append(i) nb_mult_stages += 1 print("nb_chain_mults: " + str(nb_chain_mults)) print("nb_mult_stages: " + str(nb_mult_stages)) print("mod_list: " + str(mod_list)) print("nb_chain_mults_list: " + str(nb_chain_mults_list)) av_snk0_cmb = [[ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] for j in range(nb_mult_stages)] av_snk1_cmb = [[ AvalonST_SNK(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] for j in range(nb_mult_stages)] av_src = [[ AvalonST_SRC(STREAM_DATA_WIDTH) for i in range(NB_CHAIN_MULTIPLIERS) ] for j in range(nb_mult_stages)] snk0_valid_inst = [None for i in range(NB_CHAIN_MULTIPLIERS)] snk0_data_inst = [None for i in range(NB_CHAIN_MULTIPLIERS)] snk0_ready_inst = [None for i in range(NB_CHAIN_MULTIPLIERS)] snk1_valid_inst = [None for i in range(NB_CHAIN_MULTIPLIERS)] snk1_data_inst = [None for i in range(NB_CHAIN_MULTIPLIERS)] snk1_ready_inst = [None for i in range(NB_CHAIN_MULTIPLIERS)] src_valid_inst = None src_data_inst = None src_ready_inst = None streaming_chain_mult_inst = [None for i in range(nb_mult_stages)] add_i = [None for i in range(nb_mult_stages)] add_pars = [None for i in range(nb_mult_stages)] snk0_inst = [] snk1_inst = [] for i in range(nb_mult_stages): add_pars[i] = StreamingChainMultPars() add_pars[i].SNK0_DATAWIDTH = STREAM_DATA_WIDTH add_pars[i].SNK1_DATAWIDTH = STREAM_DATA_WIDTH add_pars[i].SRC_DATAWIDTH = STREAM_DATA_WIDTH add_pars[i].NB_CHAIN_MULTIPLIERS = NB_CHAIN_MULTIPLIERS add_pars[i](add_pars[i]) add_i[i] = StreamingChainMult() if (i != 0 and i <= nb_mult_stages - 1): for j in range(nb_chain_mults_list[i]): k = j * 2 snk0_inst.append( simple_wire_assign(av_snk0_cmb[i][j].valid_i, av_src[i - 1][k].valid_o)) snk0_inst.append( simple_wire_assign(av_snk0_cmb[i][j].data_i, av_src[i - 1][k].data_o)) snk0_inst.append( simple_wire_assign(av_src[i - 1][k].ready_i, av_snk0_cmb[i][j].ready_o)) if (mod_list[i] == 1 and j == (nb_chain_mults_list[i]) - 1): snk1_inst.append( simple_wire_assign(av_snk1_cmb[i][j].valid_i, Signal(1))) snk1_inst.append( simple_wire_assign(av_snk1_cmb[i][j].data_i, Signal(1))) snk1_inst.append( simple_wire_assign(Signal(1), av_snk1_cmb[i][j].ready_o)) else: snk1_inst.append( simple_wire_assign(av_snk1_cmb[i][j].valid_i, av_src[i - 1][k + 1].valid_o)) snk1_inst.append( simple_wire_assign(av_snk1_cmb[i][j].data_i, av_src[i - 1][k + 1].data_o)) snk1_inst.append( simple_wire_assign(av_src[i - 1][k + 1].ready_i, av_snk1_cmb[i][j].ready_o)) elif (i == 0): for k in range(NB_CHAIN_MULTIPLIERS): snk0_valid_inst[k] = simple_wire_assign( av_snk0_cmb[0][k].valid_i, av_src0_bfm[k].valid_o) snk0_data_inst[k] = simple_wire_assign( av_snk0_cmb[0][k].data_i, av_src0_bfm[k].data_o) snk0_ready_inst[k] = simple_wire_assign( av_src0_bfm[k].ready_i, av_snk0_cmb[0][k].ready_o) snk1_valid_inst[k] = simple_wire_assign( av_snk1_cmb[0][k].valid_i, av_src1_bfm[k].valid_o) snk1_data_inst[k] = simple_wire_assign( av_snk1_cmb[0][k].data_i, av_src1_bfm[k].data_o) snk1_ready_inst[k] = simple_wire_assign( av_src1_bfm[k].ready_i, av_snk1_cmb[0][k].ready_o) streaming_chain_mult_inst[i] = add_i[i].block_connect( add_pars[i], reset, clk, av_snk0_cmb[i], av_snk1_cmb[i], av_src[i]) src_valid_inst = simple_wire_assign(av_snk_bfm.valid_i, av_src[nb_mult_stages - 1][0].valid_o) src_data_inst = simple_wire_assign(av_snk_bfm.data_i, av_src[nb_mult_stages - 1][0].data_o) src_ready_inst = simple_wire_assign(av_src[nb_mult_stages - 1][0].ready_i, av_snk_bfm.ready_o) @always(clk.posedge) def stimulus(): if elapsed_time == 40: reset.next = 0 INIT_DATA0 = [ random.randint(1, RANDRANGE) for i in range(NB_CHAIN_MULTIPLIERS) ] INIT_DATA1 = [ random.randint(1, RANDRANGE) for i in range(NB_CHAIN_MULTIPLIERS) ] data_in0 = [Signal(int(0)) for i in range(NB_CHAIN_MULTIPLIERS)] data_in1 = [Signal(int(0)) for i in range(NB_CHAIN_MULTIPLIERS)] src_bfm_0_valid_inst = [] src_bfm_1_valid_inst = [] src_bfm_0_data_inst = [] src_bfm_1_data_inst = [] for i in range(NB_CHAIN_MULTIPLIERS): src_bfm_0_data_inst.append( conditional_wire_assign( src_bfm_0[i].data_i, (av_src0_bfm[i].ready_i and av_src0_bfm[i].valid_o), data_in0[i], src_bfm_0[i].data_i)) src_bfm_1_data_inst.append( conditional_wire_assign( src_bfm_1[i].data_i, (av_src1_bfm[i].ready_i and av_src1_bfm[i].valid_o), data_in1[i], src_bfm_1[i].data_i)) for i in range(NB_CHAIN_MULTIPLIERS): src_bfm_0_valid_inst.append( conditional_wire_assign_lt(src_bfm_0[i].valid_i, nb_transmit0[i], Signal(MAX_NB_TRANSFERS), 1, 0)) src_bfm_1_valid_inst.append( conditional_wire_assign_lt(src_bfm_1[i].valid_i, nb_transmit1[i], Signal(MAX_NB_TRANSFERS), 1, 0)) data_in0_inst = [] data_in1_inst = [] nb_transmit0_inst = [] nb_transmit1_inst = [] transmit_data0_append_inst = [] transmit_data1_append_inst = [] receive_data_append_inst = [] for i in range(NB_CHAIN_MULTIPLIERS): data_in0_inst.append( conditional_random_generator( reset, clk, data_in0[i], int(INIT_DATA0[i]), (av_src0_bfm[i].ready_i and av_src0_bfm[i].valid_o and src_bfm_0[i].valid_i), RANDRANGE)) data_in1_inst.append( conditional_random_generator( reset, clk, data_in1[i], int(INIT_DATA1[i]), (av_src1_bfm[i].ready_i and av_src1_bfm[i].valid_o and src_bfm_1[i].valid_i), RANDRANGE)) nb_transmit0_inst.append( conditional_reg_counter( reset, clk, nb_transmit0[i], Reset.LOW, (av_src0_bfm[i].ready_i and av_src0_bfm[i].valid_o and src_bfm_0[i].valid_i))) nb_transmit1_inst.append( conditional_reg_counter( reset, clk, nb_transmit1[i], Reset.LOW, (av_src1_bfm[i].ready_i and av_src1_bfm[i].valid_o and src_bfm_1[i].valid_i))) transmit_data0_append_inst.append( conditional_clocked_appendfile( reset, clk, (av_src0_bfm[i].ready_i and av_src0_bfm[i].valid_o and src_bfm_0[i].valid_i), data_in0[i], txdata0_filename[i])) transmit_data1_append_inst.append( conditional_clocked_appendfile( reset, clk, (av_src1_bfm[i].ready_i and av_src1_bfm[i].valid_o and src_bfm_1[i].valid_i), data_in1[i], txdata1_filename[i])) receive_data_append_inst.append( conditional_clocked_appendfile(reset, clk, (src_bfm_o.valid_o), src_bfm_o.data_o, rxdata_filename)) recv_inst = None recv_inst = conditional_reg_counter(reset, clk, nb_receive, Reset.LOW, src_bfm_o.valid_o) @always(clk.posedge) def receive_data_process(): TIME_SHUTDOWN = 5000 nb_recv = 0 sim_time_now = now() nb_recv += nb_receive if (nb_recv == (MAX_NB_TRANSFERS)): print("INF242: Num ready pulses: " + str(int(ready_pulses))) raise StopSimulation("Simulation Finished in %d clks: In total " % now() + str(nb_recv) + " data words received") @always(clk.posedge) def simulation_time_check(): sim_time_now = now() if (sim_time_now > MAX_SIM_TIME): raise StopSimulation( "Warning! Simulation Exited upon reaching max simulation time of " + str(MAX_SIM_TIME) + " clocks") ready_pulse_cnt_inst = None ready_pulse_cnt_inst = conditional_reg_counter(reset, clk, ready_pulses, Reset.LOW, (av_snk_bfm.ready_o)) return instances()
def sim_streaming_simple_square(pars_obj): PATTERN_WIDTH = 16 INP_DATA_WIDTH = 8 OP_DATA_WIDTH = INP_DATA_WIDTH + INP_DATA_WIDTH reset = Signal(bool(1)) clk = Signal(bool(0)) elapsed_time = Signal(0) av_src0_bfm = AvalonST_SRC(INP_DATA_WIDTH) av_src1_bfm = AvalonST_SRC(INP_DATA_WIDTH) av_snk0 = AvalonST_SNK(INP_DATA_WIDTH) av_snk1 = AvalonST_SNK(INP_DATA_WIDTH) av_src = AvalonST_SRC(OP_DATA_WIDTH) av_snk_bfm = AvalonST_SNK(OP_DATA_WIDTH) src_bfm_i = AvalonST_SNK(INP_DATA_WIDTH) src_bfm_o = AvalonST_SRC(OP_DATA_WIDTH) clkgen = clk_driver(elapsed_time, clk, period=20) square_pars = StreamingSimpleSquarePars() square_pars.SNK0_DATA_WIDTH = INP_DATA_WIDTH square_pars.SNK1_DATA_WIDTH = INP_DATA_WIDTH square_pars.SRC_DATA_WIDTH = OP_DATA_WIDTH square_pars(square_pars) square_i = StreamingSimpleSquare() src0_bfm_inst = src_bfm(reset, clk, pars_obj.valid.pattern0, src_bfm_i, av_src0_bfm) src1_bfm_inst = src_bfm(reset, clk, pars_obj.valid.pattern1, src_bfm_i, av_src1_bfm) streaming_simple_square_inst = square_i.block_connect( square_pars, reset, clk, av_snk0, av_snk1, av_src) snk_bfm_inst = snk_bfm(reset, clk, pars_obj.ready, av_snk_bfm, src_bfm_o) print("Ready Pattern: ", str(hex(pars_obj.ready))) print("Valid Pattern0: ", str(hex(pars_obj.valid.pattern0))) print("Valid Pattern1: ", str(hex(pars_obj.valid.pattern1))) @always_comb def beh_comb_logic(): # Streaming Input Interface av_snk0.valid_i.next = av_src0_bfm.valid_o av_snk0.data_i.next = av_src0_bfm.data_o av_src0_bfm.ready_i.next = av_snk0.ready_o av_snk1.valid_i.next = av_src1_bfm.valid_o av_snk1.data_i.next = av_src1_bfm.data_o av_src1_bfm.ready_i.next = av_snk1.ready_o #Streaming Output interface av_snk_bfm.valid_i.next = av_src.valid_o av_snk_bfm.data_i.next = av_src.data_o av_src.ready_i.next = av_snk_bfm.ready_o src_bfm_i.valid_i.next = 1 if (nb1 < MAX_NB_TRANSFERS) else 0 @always(clk.posedge) def stimulus(): if elapsed_time == 40: reset.next = 0 INIT_DATA = 1 data_in = Signal(int(0)) @always_comb def transmit_data_process(): if (av_src0_bfm.ready_i == 1 and av_src0_bfm.valid_o == 1): src_bfm_i.data_i.next = data_in #Dataout is just an increment (for next valid data) @always(clk.posedge, reset.posedge) def transmit_data_clk_process(): global trans_data, nb1 if reset == 1: data_in.next = int(INIT_DATA) elif (av_src0_bfm.ready_i == 1 and av_src0_bfm.valid_o == 1 and src_bfm_i.valid_i == 1): nb1 += 1 #print str(nb1) + ". Transmitted data to src bfm:", ": ", src_bfm_i.data_i trans_data.append(int(data_in)) data_in.next = data_in + 1 @always(clk.posedge) def receive_data_process(): global recv_data, nb2 if (src_bfm_o.valid_o == 1): nb2 += 1 #print str(nb2) + ". Received data from sink bfm:", ": ", src_bfm_o.data_o recv_data.append(int(src_bfm_o.data_o)) sim_time_now = now() if (nb2 == MAX_NB_TRANSFERS): raise StopSimulation( "Simulation Finished in %d clks: In total " % now() + str(MAX_NB_TRANSFERS) + " data words received") @always(clk.posedge) def simulation_time_check(): sim_time_now = now() if (sim_time_now > MAX_SIM_TIME): raise StopSimulation( "Warning! Simulation Exited upon reaching max simulation time of " + str(MAX_SIM_TIME) + " clocks") @always(clk.posedge) def cnt_ready_pulses(): global ready_pulses if (av_snk_bfm.ready_o == 1): ready_pulses += 1 #print "ready received from bfm" return instances()
import sys from random import randrange from myhdl import Signal, delay, always, now, Simulation, traceSignals, instance, intbv from src_bfm import src_bfm from clk_driver import clk_driver from avalon_buses import AvalonST_SRC, AvalonST_SNK valid_ready_pattern_width = 16 DATA_WIDTH = 8 valid_i_pattern = int(sys.argv[1], valid_ready_pattern_width) ready_i_pattern = int(sys.argv[2], valid_ready_pattern_width) aso_src = AvalonST_SRC(DATA_WIDTH) src_bfm_i = AvalonST_SNK(DATA_WIDTH) def sim_src_bfm(): reset = Signal(bool(1)) clk = Signal(bool(0)) src_bfm_i.data_i = Signal(intbv(0x0a)[DATA_WIDTH:]) elapsed_time = Signal(0) src_bfm_inst = src_bfm(reset, clk, valid_i_pattern, src_bfm_i, aso_src) class num_counter: nb = 0 clkgen = clk_driver(elapsed_time, clk, period=20) @always(clk.posedge)