AXI总线代码详细整理(一)

article/2025/10/18 4:47:09

目录

  • 说明
  • 1. AXI 的时钟与复位
    • 1.1 时钟
    • 1.2 复位
  • 2. 五个通道
    • 2.1 Write Address Channel
    • 2.2 Write Data Channel
    • 2.3 Write Response (B) Channel
    • 2.4 Read Address Channel
    • 2.5 Read Data (and Response) Channel
  • 3 突发传输机制
    • 3.1 突发传输长度和宽度
    • 3.2 突发传输类型

说明

文字说明来自"AMBA® AXI™ and ACE™ ProtocolSpecification",百度直接可以搜到。
代码源自Xilinx的AXI IP,获取方法如下:
在这里插入图片描述
选择create and package new IP.
在这里插入图片描述
在这里插入图片描述
Interface Mode 选择 Master,Interface Type 选择 Full, Date Width自行设定,这里选择32.
在这里插入图片描述
选择edit IP.
本文整理了master的部分代码,后续有时间会整理master部分剩下的代码和slave的代码,因为学习协议去看文档非常枯燥,还是与代码结合比较有效,当做一个学习笔记。

1. AXI 的时钟与复位

1.1 时钟

Each AXI component uses a single clock signal, ACLK. All input signals are sampled on the rising edge of ACLK. 
All output signal changes must occur after the rising edge of ACLK.

代码:

		// Global Clock Signal.input wire  M_AXI_ACLK,

1.2 复位

The AXI protocol uses a single active LOW reset signal, ARESETn. The reset signal can be asserted 
asynchronously, but deassertion must be synchronous with a rising edge of ACLK.

引脚定义:
master:

		// Global Reset Singal. This Signal is Active Lowinput wire  M_AXI_ARESETN,

复位的作用引脚为:

a master interface must drive ARVALID, AWVALID, and WVALID LOW

2. 五个通道

如图所示:
在这里插入图片描述

2.1 Write Address Channel

相关信号:

signalsourcedescription
AWVALIDmasterWrite address valid. This signal indicates that the channel is signaling valid write address and control information.
AWREADYslaveWrite address valid. This signal indicates that the channel is signaling valid write address and control information.
AWADDRmasterWrite address. The write address gives the address of the first transfer in a write burst transaction.

代码:

always @(posedge M_AXI_ACLK)                                   begin                                                                if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1 )                                           begin                                                            axi_awvalid <= 1'b0;                                           end                                                              // If previously not valid , start next transaction                else if (~axi_awvalid && start_single_burst_write)                 begin                                                            axi_awvalid <= 1'b1;                                           end                                                              /* Once asserted, VALIDs cannot be deasserted, so axi_awvalid      must wait until transaction is accepted */                         else if (M_AXI_AWREADY && axi_awvalid)                             begin                                                            axi_awvalid <= 1'b0;                                           end                                                              else                                                               axi_awvalid <= axi_awvalid;                                      end     

这一段代码即为握手过程:

Once VALID is asserted it must remain asserted until the handshake occurs, at a rising clock edge at which VALID and READY are both asserted.

在这里插入图片描述
在这里插入图片描述
代码:

// Next address after AWREADY indicates previous address acceptance    always @(posedge M_AXI_ACLK)                                         begin                                                                if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1)                                            begin                                                            axi_awaddr <= 'b0;                                             end                                                              else if (M_AXI_AWREADY && axi_awvalid)                             begin                                                            axi_awaddr <= axi_awaddr + burst_size_bytes;                   end                                                              else                                                               axi_awaddr <= axi_awaddr;                                        end   

这里init_txn_pulse是初始标志,将axi_awvalid清零和axi_awaddr地址归到起始。
如前面所说,AWADDR是每次burst传输的首地址,因此每次加一个burst_size_bytes。
burst_size_bytes定义为:

assign burst_size_bytes	= C_M_AXI_BURST_LEN * C_M_AXI_DATA_WIDTH/8;

即长度×宽度/8(字节),这里涉及到突发传输的长度宽度,可以看3.1。

2.2 Write Data Channel

相关信号:

signalsourcedescription
WVALIDmasterWrite valid. This signal indicates that valid write data and strobes are available.
WREADYslaveWrite ready. This signal indicates that the slave can accept the write data.
WLASTmasterWrite last. This signal indicates the last transfer in a write burst.
WDATAmasterWrite data.

代码:

// WVALID logic, similar to the axi_awvalid always block above                      always @(posedge M_AXI_ACLK)                                                      begin                                                                             if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1 )                                                        begin                                                                         axi_wvalid <= 1'b0;                                                         end                                                                           // If previously not valid, start next transaction                              else if (~axi_wvalid && start_single_burst_write)                               begin                                                                         axi_wvalid <= 1'b1;                                                         end                                                                           /* If WREADY and too many writes, throttle WVALID                               Once asserted, VALIDs cannot be deasserted, so WVALID                           must wait until burst is complete with WLAST */                                 else if (M_AXI_WREADY & axi_wvalid&& axi_wlast)                                                    axi_wvalid <= 1'b0;                                                           else                                                                            axi_wvalid <= axi_wvalid;                                                     end             

这一段和上面的握手过程类似,不同的是WVALID需要在axi_wlast为1时清零。
代码:

//WLAST generation on the MSB of a counter underflow                                // WVALID logic, similar to the axi_awvalid always block above                      always @(posedge M_AXI_ACLK)                                                      begin                                                                             if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1 )                                                        begin                                                                         axi_wlast <= 1'b0;                                                          end                                                                           // axi_wlast is asserted when the write index                                   // count reaches the penultimate count to synchronize                           // with the last write data else if (((write_index == C_M_AXI_BURST_LEN-2 && C_M_AXI_BURST_LEN >= 2) && M_AXI_WREADY & axi_wvalid) || (C_M_AXI_BURST_LEN == 1 ))begin                                                                         axi_wlast <= 1'b1;                                                          end                                                                           // Deassrt axi_wlast when the last write data has been                          // accepted by the slave with a valid response                                  else if (M_AXI_WREADY & axi_wvalid)                                                                 axi_wlast <= 1'b0;                                                            else if (axi_wlast && C_M_AXI_BURST_LEN == 1)                                   axi_wlast <= 1'b0;                                                            else                                                                            axi_wlast <= axi_wlast;                                                       end    

C_M_AXI_BURST_LEN为burst的长度,在长度大于等于2时,write_index为C_M_AXI_BURST_LEN-2时wlast置1,如果长度为1则直接置1。在最后一个数据被接收后wlast清零。
代码,write_index:

/* Burst length counter. Uses extra counter register bit to indicate terminal       count to reduce decode logic */                                                    always @(posedge M_AXI_ACLK)                                                      begin                                                                             if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1 || start_single_burst_write == 1'b1)    begin                                                                         write_index <= 0;                                                           end                                                                           else if (wnext && (write_index != C_M_AXI_BURST_LEN-1))                         begin                                                                         write_index <= write_index + 1;                                             end                                                                           else                                                                            write_index <= write_index;                                                   end    

代码,write data,这里给出的是简单的每次增加1的data

/* Write Data Generator                                                             Data pattern is only a simple incrementing count from 0 for each burst  */         always @(posedge M_AXI_ACLK)                                                      begin                                                                             if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1)                                                         axi_wdata <= 'b1;                                                             //else if (wnext && axi_wlast)                                                  //  axi_wdata <= 'b0;                                                           else if (wnext)                                                                 axi_wdata <= axi_wdata + 1;                                                   else                                                                            axi_wdata <= axi_wdata;                                                       end

2.3 Write Response (B) Channel

相关信号:

signalsourcedescription
BVALIDslaveWrite response valid. This signal indicates that the channel is signaling a valid write response.
BREADYmasterResponse ready. This signal indicates that the master can accept a write response.

代码:

 always @(posedge M_AXI_ACLK)                                     begin                                                                 if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1 )                                            begin                                                             axi_bready <= 1'b0;                                             end                                                               // accept/acknowledge bresp with axi_bready by the master           // when M_AXI_BVALID is asserted by slave                           else if (M_AXI_BVALID && ~axi_bready)                               begin                                                             axi_bready <= 1'b1;                                             end                                                               // deassert after one clock cycle                                   else if (axi_bready)                                                begin                                                             axi_bready <= 1'b0;                                             end                                                               // retain the previous value                                        else                                                                axi_bready <= axi_bready;                                         end 

这是握手过程,是上面两段握手的反过程,valid由slave发送,ready由master发送。ready仅发送一个时钟。

2.4 Read Address Channel

signalsourcedescription
ARVALIDmasterRead address valid. This signal indicates that the channel is signaling valid read address and control information.
ARREADYsalveRead address ready. This signal indicates that the slave is ready to accept an address and associated control signals.
ARADDRmasterRead address. The read address gives the address of the first transfer in a read burst transaction.

握手机制代码:

	  always @(posedge M_AXI_ACLK)                                 begin                                                              if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1 )                                         begin                                                          axi_arvalid <= 1'b0;                                         end                                                            // If previously not valid , start next transaction              else if (~axi_arvalid && start_single_burst_read)                begin                                                          axi_arvalid <= 1'b1;                                         end                                                            else if (M_AXI_ARREADY && axi_arvalid)                           begin                                                          axi_arvalid <= 1'b0;                                         end                                                            else                                                             axi_arvalid <= axi_arvalid;                                    end

地址增加代码,这里和写地址十分类似:

	  always @(posedge M_AXI_ACLK)                                       begin                                                              if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1)                                          begin                                                          axi_araddr <= 'b0;                                           end                                                            else if (M_AXI_ARREADY && axi_arvalid)                           begin                                                          axi_araddr <= axi_araddr + burst_size_bytes;                 end                                                            else                                                             axi_araddr <= axi_araddr;                                      end   

2.5 Read Data (and Response) Channel

signalsourcedescription
RLASTslaveRead last. This signal indicates the last transfer in a read burst.
RVALIDsalveRead valid. This signal indicates that the channel is signaling the required read data.
RREADYmasterRead ready. This signal indicates that the master can accept the read data and response information.

握手机制代码:

 always @(posedge M_AXI_ACLK)                                          begin                                                                 if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1 )                  begin                                                             axi_rready <= 1'b0;                                             end                                                               // accept/acknowledge rdata/rresp with axi_rready by the master     // when M_AXI_RVALID is asserted by slave                           else if (M_AXI_RVALID)                       begin                                      if (M_AXI_RLAST && axi_rready)          begin                                  axi_rready <= 1'b0;                  end                                    else                                    begin                                 axi_rready <= 1'b1;                 end                                   end                                        // retain the previous value                 end       

3 突发传输机制

3.1 突发传输长度和宽度

相关信号:

signalsourcedescription
AWLENmasterBurst length. The burst length gives the exact number of transfers in a burst. This information determines the number of data transfers associated with the address.
AWSIZEmasterBurst size. This signal indicates the size of each transfer in the burst.
ARLENmaster同AWLEN
ARSIZEmaster同ARSIZE

引脚定义(master):

output wire [7 : 0] M_AXI_AWLEN,
output wire [2 : 0] M_AXI_AWSIZE,
output wire [7 : 0] M_AXI_ARLEN,
output wire [2 : 0] M_AXI_ARSIZE,
assign M_AXI_ARLEN	= C_M_AXI_BURST_LEN - 1;
assign M_AXI_ARSIZE	= clogb2((C_M_AXI_DATA_WIDTH/8)-1);
assign M_AXI_AWLEN	= C_M_AXI_BURST_LEN - 1;
assign M_AXI_AWSIZE	= clogb2((C_M_AXI_DATA_WIDTH/8)-1);

ARLEN/AWLEN:

The burst length for AXI4 is defined as,
Burst_Length = AxLEN[7:0] + 1, to accommodate the extended burst length of the INCR burst type in AXI4.

ARSIZE/AWSIZE如下表所示:
在这里插入图片描述
都与代码是一致的。
C_M_AXI_DATA_WIDTH定义与之前定义的width是一致的:

parameter integer C_M_AXI_DATA_WIDTH	= 32,

一次传输的字节数:

assign burst_size_bytes	= C_M_AXI_BURST_LEN * C_M_AXI_DATA_WIDTH/8;

读数据通道的突发传输长度计数:
突发传输方式计数:

 always @(posedge M_AXI_ACLK)                                          begin                                                                 if (M_AXI_ARESETN == 0 || init_txn_pulse == 1'b1 || start_single_burst_read)                  begin                                                             read_index <= 0;                                                end                                                               else if (rnext && (read_index != C_M_AXI_BURST_LEN-1))              begin                                                             read_index <= read_index + 1;                                   end                                                               else                                                                read_index <= read_index;                                         end   

3.2 突发传输类型

相关信号:

signalsourcedescription
ARBURSTmasterBurst type. The burst type and the size information determine how the address for each transfer within the burst is calculated.
AWBURSTmaster同ARBURST

引脚定义(master):

output wire [1 : 0] M_AXI_AWBURST,
output wire [1 : 0] M_AXI_ARBURST

不同的ARBURST/AWBURST对应的突发传输类型如下表,具体的机制需要分析slave的代码 (slave的代码后续有时间也会整理)。
在这里插入图片描述
同时突发传输长度也与突发传输类型有关,突发传输长度的规定:

AXI4 extends burst length support for the INCR burst type to 1 to 256 transfers. Support for all other burst types in AXI4 remains at 1 to 16 transfers.

http://chatgpt.dhexx.cn/article/WZxpeqUU.shtml

相关文章

AXI总线详解完结篇

经过几个月的整理和发文,AXI总线详解系列正式迎来最终篇,内容基本涵盖了上一篇文章的全部内容。 所有文章的链接如下: 1、 AXI总线详解 2、AXI总线详解-总线和接口以及协议 3、AXI协议中的通道结构 4、AXI总线详解-AXI4读

AXI接口简介

此部分&#xff0c;有参考他人帖子的内容&#xff0c;加上自己的理解&#xff0c;感恩原作者 1、 AXI&#xff08;Advanced eXtensible Interface&#xff09;协议主要描述了主设备&#xff08;Master&#xff09;和从设备&#xff08;Slave&#xff09;之间的数据传输方式&…

AXI接口协议详解-AXI总线、接口、协议

转自&#xff1a;https://cloud.tencent.com/developer/article/1695010 AXI接口协议详解-AXI总线、接口、协议 AXI 总线 上面介绍了AMBA总线中的两种&#xff0c;下面看下我们的主角—AXI&#xff0c;在ZYNQ中有支持三种AXI总线&#xff0c;拥有三种AXI接口&#xff0c;当然用…

【AXI】解读AXI协议的低功耗设计

芯片设计验证社区芯片爱好者聚集地硬件相关讨论社区数字verifier星球四社区联合力荐&#xff01;近500篇数字IC精品文章收录&#xff01;【数字IC精品文章收录】学习路线基础知识总线脚本语言芯片求职EDA工具低功耗设计VerilogSTA设计验证FPGA架构AMBA书籍 解读AXI协议的低功耗…

AXI总线协议

0.绪论 AXI(Advanced eXtensible Interface)是一种总线协议,该协议是ARM公司提出的AMBA3.0中最重要的部分,是一种面向高性能、高带宽、低延迟的片内总线。AMBA4.0将其修改升级为AXI4.0。 AMBA4.0 包括AXI4.0、AXI4.0-lite、ACE4.0、AXI4.0-stream。 AXI4.0-lite是AXI的简化…

AXI总线学习------从零开始详细学-----------连载(2)axi protocol 通道分类

AXI总线学习连载&#xff08;2&#xff09; 鲁迅曾经说过&#xff1a; 学硬件&#xff0c;不是学哪里查哪里&#xff0c;有一些东西是必须系统的学的&#xff0c;不管是嵌入式还是FPGA,硬件学习的积累一定要是系统的。 我也曾经说过&#xff1a; 英文手册非常重要&#xff0c…

【AXI】解读AXI协议中的burst突发传输机制

芯片设计验证社区芯片爱好者聚集地硬件相关讨论社区数字verifier星球四社区联合力荐&#xff01;近500篇数字IC精品文章收录&#xff01;【数字IC精品文章收录】学习路线基础知识总线脚本语言芯片求职EDA工具低功耗设计VerilogSTA设计验证FPGA架构AMBA书籍 解读AXI协议中的burs…

【AXI】解读AXI协议事务属性(Transaction Attributes)

芯片设计验证社区芯片爱好者聚集地硬件相关讨论社区数字verifier星球四社区联合力荐&#xff01;近500篇数字IC精品文章收录&#xff01;【数字IC精品文章收录】学习路线基础知识总线脚本语言芯片求职EDA工具低功耗设计VerilogSTA设计验证FPGA架构AMBA书籍 解读AXI协议事务属性…

AXI总线知多少?

关注、星标公众号&#xff0c;精彩内容每日送达 来源&#xff1a;数字ICer 前言 本文针对秋招面试高频问题: AXI总线进行总结&#xff1b; 1.简介 AXI是个什么东西呢&#xff0c;它其实不属于Zynq&#xff0c;不属于Xilinx&#xff0c;而是属于ARM。它是ARM最新的总线接口&…

AXI学习

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 一、AXI中关于非对齐问题理解 AXI 协议支持地址非对齐的传输&#xff0c;允许突发传输的首字节地址&#xff0c;即起始地址与突发传输位宽不对齐。举个例子&#xff0c;总线位…

AXI 中文

AXI总线协议资料整理 第一部分&#xff1a; 1、AXI简介&#xff1a;AXI&#xff08;AdvancedeXtensible Interface&#xff09;是一种总线协议&#xff0c;该协议是ARM公司提出的AMBA&#xff08;AdvancedMicrocontroller Bus Architecture&#xff09;3.0协议中最重要的部分&a…

AXI协议

文章目录 前言一、通道信号二、AXI 握手机制三、读写Timing3.1 写数据3.2 读数据 四、通道间的依赖关系4.1 写地址通道&#xff08; AW &#xff09;4.2 写数据通道&#xff08; W &#xff09;4.2 写响应通道( B )4.3 读数据( R ) 五、信号详细解释5.1 ACLK和ARESETn5.2 Burst…

AXI 总线详解

综述 本文我们详解AXI&#xff0c;在ZYNQ中有支持三种AXI总线&#xff0c;拥有三种AXI接口&#xff0c;当然用的都是AXI协议。其中三种AXI总线分别为&#xff1a; AXI4&#xff1a;&#xff08;For high-performance memory-mapped requirements.&#xff09;主要面向高性能地…

AXI总线概述

AXI&#xff08;Advanced eXtensible Interface&#xff09;是一种总线协议&#xff0c;该协议是ARM公司提出的AMBA3.0中最重要的部分&#xff0c;是一种面向高性能、高带宽、低延迟的片内总线。AMBA4.0将其修改升级为AXI4.0。 AMBA4.0 包括AXI4.0、AXI4.0-lite、ACE4.0、AXI4.…

AXI协议学习笔记~~

AXI总线简介 ​  AXI属于AMBA(The ARM Advanced Microcontroller Bus Architecture)家族的一员&#xff0c;AXI协议在AMBA3.0版本中开始出现&#xff0c;并在后续的AMBA4.0&#xff0c;AMBA5.0中持续更新&#xff0c;对应为 AXI3&#xff0c;AXI4&#xff0c;AXI5。 ​   …

AXI 系列 之 AXI概述

目录 AXI简介 AMBA总线的演进图 AXI overriew AXI读写通道 AXI读取传输 事务 AXI 写入传输事务 AXI 概念解读 burst传输 FIXED模式下传输首地址后就可以不停传输数据吗&#xff1f; 突发传输不能跨4KB边界&#xff1f; 非对齐传输 复位期间对接口有如下要求&#xf…

AXI接口协议学习总结

AXI接口协议学习总结 下面将AXI接口协议学到的相关内容整理如下 一、AXI接口协议定义 AXI是Advanced eXtensible Interface的缩写&#xff0c;译为高级可扩展接口协议&#xff0c;是ARM公司提出的AMBA&#xff08;Advanced Microcontroller Bus Architecture&#xff09;高级…

【AXI】解读AXI协议双向握手机制的原理

解读AXI协议双向握手机制的原理 一、写在前面二、AXI 双向握手机制简介2.1 信号列表2.2 双向握手目的2.3 握手过程2.3.1 CASE1&#xff08;READY信号先于VALID信号改变&#xff09;2.3.2 CASE2&#xff08;READY信号与VALID信号同时改变&#xff09;2.3.3 CASE3&#xff08;REA…

带你快速入门AXI4总线--AXI4-Full篇(1)----AXI4-Full总线

写在前面 AXI4系列链接&#xff1a;带你快速入门AXI4总线--汇总篇&#xff08;直达链接&#xff09; 1、什么是AXI4-Full&#xff1f; AXI 表示 Advanced eXtensible Interface&#xff08;高级可扩展接口&#xff09;&#xff0c;它是由 Arm 定义的接口协议&#xff0c;包含在…

通信协议(AXI)

一、AXI简介 SoC片上总线尚处于发展阶段&#xff0c;不像微机总线那样成熟&#xff0c;目前还没有统一的标准&#xff0c;因此各大厂商和组织纷纷推出自己的标准&#xff0c;以便在未来的SoC片上总线标准中占有一席之地。ARM公司就在1995年推出了自己的总线——AMBA&#xff0…