一个寄存器转AXI数据流的代码

module reg2stream #(parameter WIDTH = 1024,parameter DW=8)(
	input	clk,
	input	rst,
	
	input	start,
	input	[WIDTH-1:0] regs,
	
	output	reg out_valid,
	output	reg out_last,
	output	reg [DW-1:0]	out_data,
    input   out_ready
	
	
);
	reg	start_r;
	reg	[WIDTH-1:0]	regs_r;
	reg	[$clog2(WIDTH)-1:0]	bit_cnt;
	reg	state;
	
	always @ (posedge clk or posedge rst)
	begin
		if(rst) begin
			state<=0;
		end
		else case(state)
			0:begin
				start_r<=start;
				if({start_r,start}==2'b01) begin
					regs_r<=regs;
					state<=1;
					bit_cnt<=0;
                    out_valid<=1;
                    out_last<=0;
				end
			end
			1:if(out_ready) begin
                regs_r<=regs_r>>DW;
                bit_cnt<=bit_cnt+DW;
                if(bit_cnt==WIDTH-2*DW)
                    out_last<=1;
                if(bit_cnt==WIDTH-DW) begin
                    state<=0;
                    out_valid<=0;
                end
			end
		endcase
	end
    
    always @ (*)
    out_data=regs_r[DW-1:0];
	
endmodule

			
		
	
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰冻土卫二

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值