向axis-fifo写入数据的方法

module dma_frame_gen #(
    parameter TRANS_NUM = 32'd1550336 //1514*1024
    )
    (
    input resetn,
    input clk,
    input trans_start,
    // axi-stream
    output [31:0] m_axis_tdata,
    output [3:0] m_axis_tkeep,
    output m_axis_tlast,
    output m_axis_tvalid,
    input m_axis_tready
    );
    
assign m_axis_tkeep = 4'b1111;
reg trans_start_0, trans_start_1;
wire pos_trans_start;
assign pos_trans_start = trans_start_0 & (~trans_start_1);
always @(posedge clk or negedge resetn) begin
    if(~resetn) begin
        trans_start_0 <= 1'd0;
        trans_start_1 <= 1'd0;
    end
    else begin
        trans_start_0 <= trans_start;
        trans_start_1 <= trans_start_0;
    end
end
localparam IDLE = 2'b00;
localparam TRANS = 2'b01;
localparam DONE = 2'b10;
reg [1:0] state;
reg [31:0] trans_cnt;
reg [31:0] r_tdata;
reg r_tvalid, r_tlast;
always @(posedge clk or negedge resetn) begin
    if(!resetn) begin
        state <= IDLE;
        r_tdata <= 32'd0;
        r_tvalid <= 1'b0;
    end
    else begin
        r_tdata <= 32'd0;
        r_tvalid <= 1'b0;
        case(state)
            IDLE: begin
                if(pos_trans_start && m_axis_tready) begin
                    state <= TRANS;
                end
                else begin
                    state <= IDLE;
                end
            end
            TRANS: begin
                if(trans_cnt < TRANS_NUM) begin
                    state <= TRANS;
                    r_tvalid <= 1'b1;
                    r_tdata <= trans_cnt;
                end
                else begin
                    state <= DONE;
                end
            end
            DONE: begin
                state <= IDLE;
            end
            default: begin
                state <= IDLE;
            end
        endcase
    end
end
always @(posedge clk or negedge resetn) begin
    if(!resetn) begin
        r_tlast <= 1'b0;
    end
    else begin
        if(state == TRANS && trans_cnt == TRANS_NUM-1) begin
            r_tlast <= 1'b1;
        end
        else begin
            r_tlast <= 1'b0;
        end
    end
end
always @(posedge clk or negedge resetn) begin
    if(!resetn) begin
        trans_cnt <= 0;
    end
    else begin
        if(state == TRANS) begin
            trans_cnt <= trans_cnt + 1;
        end
        else begin
            trans_cnt <= 32'd0;
        end
    end
end
assign m_axis_tdata = r_tdata;
assign m_axis_tlast = r_tlast;
assign m_axis_tvalid = r_tvalid;
endmodule

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的AXI4-Stream FIFO数据的VHDL实现,可以用于仿真或实际硬件实现: ```vhdl library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity axi4_stream_fifo is generic ( DATA_WIDTH : integer := 32; -- 数据宽度 ADDR_WIDTH : integer := 6; -- 地址宽度 MAX_DEPTH : integer := 64 -- 最大深度 ); port ( -- AXI4-Stream接口 s_axis_tdata : in std_logic_vector(DATA_WIDTH-1 downto 0); s_axis_tvalid : in std_logic; s_axis_tready : out std_logic; -- AXI接口 s_axi_awaddr : in std_logic_vector(ADDR_WIDTH-1 downto 0); s_axi_awvalid : in std_logic; s_axi_awready : out std_logic; s_axi_wdata : in std_logic_vector(DATA_WIDTH-1 downto 0); s_axi_wvalid : in std_logic; s_axi_wready : out std_logic; s_axi_bresp : out std_logic_vector(1 downto 0); s_axi_bvalid : out std_logic; s_axi_bready : in std_logic ); end entity; architecture rtl of axi4_stream_fifo is -- FIFO深度计数器 signal count : integer range 0 to MAX_DEPTH-1 := 0; -- FIFO存储器 type fifo_mem_t is array (0 to MAX_DEPTH-1) of std_logic_vector(DATA_WIDTH-1 downto 0); signal fifo_mem : fifo_mem_t := (others => (others => '0')); begin -- AXI4-Stream接口数据 write_data: process (s_axis_tdata, s_axis_tvalid, s_axis_tready) is begin if (s_axis_tvalid = '1' and s_axis_tready = '1') then -- 数据写入FIFO fifo_mem(count) <= s_axis_tdata; count <= count + 1; end if; end process; -- AXI接口响应请求 respond_write: process (s_axi_awaddr, s_axi_awvalid, s_axi_awready, s_axi_wdata, s_axi_wvalid, s_axi_wready) is begin if (s_axi_awvalid = '1' and s_axi_awready = '1' and s_axi_wvalid = '1' and s_axi_wready = '1') then -- 写入FIFO的地址为当前深度 s_axi_awaddr <= std_logic_vector(to_unsigned(count-1, ADDR_WIDTH)); -- 写入数据 fifo_mem(count-1) <= s_axi_wdata; -- 计数器加1 count <= count + 1; -- 响应请求 s_axi_bresp <= "00"; s_axi_bvalid <= '1'; end if; end process; -- AXI接口读请求 read_request: process (s_axi_awaddr, s_axi_awvalid, s_axi_awready) is begin if (s_axi_awvalid = '1' and s_axi_awready = '1') then -- 读请求的地址为0 s_axi_awaddr <= (others => '0'); -- 响应读请求 s_axi_bresp <= "00"; s_axi_bvalid <= '1'; end if; end process; -- AXI接口读数据 read_data: process (s_axi_araddr, s_axi_arvalid, s_axi_arready) is begin if (s_axi_arvalid = '1' and s_axi_arready = '1') then -- 读取FIFO的第一个数据 s_axi_rdata <= fifo_mem(0); -- 读取后计数器减1 count <= count - 1; -- 响应读请求 s_axi_rvalid <= '1'; end if; end process; end architecture; ``` 请注意,这只是一个简单的实现,没有考虑流控制和错误处理。在实际应用中,您可能需要更多的功能和保护。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值