本章内容:一个DMA写的小例子
这里给一个小例子:文章来源:https://www.toymoban.com/news/detail-653544.html
往0地址写入
突发长度为256突发,数据位宽为64bit
数据为0~255文章来源地址https://www.toymoban.com/news/detail-653544.html
//------------------------------------------------------------------------------------------------------------------------------------//
//Ourself
/*
Write Addr channel : 1. axi_awvalid 2. axi_awaddr 3. M_AXI_AWREADY
Write channel : 1. axi_wvalid 2. axi_wdata 3. axi_wlast 4.M_AXI_WREADY
Write response channel : 1. axi_bready 2. M_AXI_BVALID 3. M_AXI_BRESP
*/
//--------------------------------------------------------------//
//----------------------parameter define------------------------//
//--------------------------------------------------------------//
parameter ADDR_OFFSET = C_M_AXI_BURST_LEN * C_M_AXI_DATA_WIDTH >> 2;//自己写的时候可不敢这么写嗷,不能用乘法
reg [1:0] init_valid;
reg [7:0] data_cnt;
//--------------------------------------------------------------//
//-----------------------Write Addr channel---------------------//
//--------------------------------------------------------------//
always @(posedge M_AXI_ACLK) begin
init_valid <= {init_valid[0],INIT_AXI_TXN};
end
//axi_awvalid
always @(posedge M_AXI_ACLK) begin
if (M_AXI_ARESETN == 0)
axi_awvalid <= 1'b0;
else if(M_AXI_AWREADY == 1'b1 && axi_awvalid == 1'b1)
axi_awvalid <= 1'b0;
else if (init_valid == 2'b01)
axi_awvalid <= 1'b1;
end
//axi_awaddr
always @(posedge M_AXI_ACLK) begin
if (M_AXI_ARESETN == 0) begin
// reset
axi_awaddr <= 32'd0;
end
else if (axi_awvalid == 1'b1 && M_AXI_AWREADY == 1'b1) begin
axi_awaddr <= axi_awaddr + ADDR_OFFSET;
end
end
//--------------------------------------------------------------//
//-----------------------Write channel---------------------//
//--------------------------------------------------------------//
//axi_wvalid
always @(posedge M_AXI_ACLK) begin
if (M_AXI_ARESETN == 0)
axi_wvalid <= 1'b0;
else if(axi_wlast == 1'b1 && axi_wvalid == 1'b1 && M_AXI_WREADY == 1'b1)
axi_wvalid <= 1'b0;
else if (axi_awvalid == 1'b1 && M_AXI_AWREADY == 1'b1)
axi_wvalid <= 1'b1;
end
//data_cnt
always @(posedge M_AXI_ACLK) begin
if (M_AXI_ARESETN == 0)
data_cnt <= 'd0;
else if (axi_wvalid == 1'b1 && M_AXI_WREADY == 1'b1)
data_cnt <= data_cnt + 1'b1;
else if((data_cnt == C_M_AXI_BURST_LEN-1) && axi_wvalid == 1'b1 && M_AXI_WREADY == 1'b1)
data_cnt <= 'd0;
end
//axi_wlast
always @(posedge M_AXI_ACLK) begin
if (M_AXI_ARESETN == 0)
axi_wlast <= 1'b0;
else if (M_AXI_WREADY == 1'b1 && axi_wvalid == 1'b1 && (data_cnt == C_M_AXI_BURST_LEN-1))
axi_wlast <= 1'b0;
else if (M_AXI_WREADY == 1'b1 && axi_wvalid == 1'b1 && (data_cnt == C_M_AXI_BURST_LEN-2))
axi_wlast <= 1'b1;
end
//axi_wdata
always @(*) begin
axi_wdata <= data_cnt;
end
//--------------------------------------------------------------//
//-----------------------Write response channel-----------------//
//--------------------------------------------------------------//
always @(posedge M_AXI_ACLK) begin
if (M_AXI_ARESETN == 0)
axi_bready <= 1'b0;
else
axi_bready <= 1'b1;
end
到了这里,关于AXI4-写DMA如何使用verilog实现(三)DMA例子的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!