深入理解AXI4总线burst type | wrap burst地址如何计算?

目录

一、burst type 基本概念

1.1. fixed模式

1.2. INCR模式

1.3. wrap模式

二、地址计算公式

2.1. 地址相关概念

2.2. INCR burst 地址计算: 

2.3. WRAP burst 地址上下界及地址计算

三、详细示例

3.1.  起始地址对齐

3.1.1 INCR burst

3.1.2 wrap burst

3.2. 起始地址非对齐

3.2.1 INCR burst    


一、burst type 基本概念

基于AXI4 协议规范,axi burst type支持的类型有如下三种, 其中当burst type取值为2'b11,为reserved情况

1.1. fixed模式

        这时对于一笔burst中的每个transfer对应的地址均为固定值, 这种burst type 多用于对相同位置的重复访问,例如加载或清空FIFO。

1.2. INCR模式

        对于burst type 值为2'b01时, 为INCR模式, 这时对于一笔burst中的每个transfer对应的地址位依次递增,递增的值与每个transfer的size有关,这种burst type 多用于访问正常的顺序存储器。        

1.3. wrap模式

        对于burst type 值为2'b10时, 为wrap模式, 这时对于一笔burst中的每个transfer对应的地址有上限和下限的限制,在这个限制范围之内,每个transfer对应的地址也是递增的关系,这种burst type多用于cache line 访问(如MCU), 但是需要注意的是

  1. 起始地址必须与每次传输的大小对齐

  2. burst length 的取值必须是2,4,8,16

二、地址计算公式

2.1. 地址相关概念

那么如何计算burst type为INCR和wrap两种情况下每笔burst中每个transfer对应的地址?

首先需要明确如下几个概念

  1. start_address: master发出的每笔burst的首地址

  2. number_bytes: 每个transfer传输的最大数据量,以byte计

  3. burst_length: 在一笔burst中,包含的transfer的数量

  4. address_n: 一笔burst中的第n个transfer对应的地址,对于第一个transfer,对应的地址为address_1,对于第n个transfer,对应的地址为address_n

  5. aligned_address: 起始地址的对齐版本

  6. wrap_boundary: 当burst type为wrap时,一笔burst的地址下界,(为便于理解,后续计算将其定义为wrap_floor)

  7. wrap_celling: 当burst type为wrap时,一笔burst的地址上界

  8. int(x): 对x向下取整

下面给出上述提及概念的具体计算公式

  1. start_address = AxADDR

  2. number_bytes =  2 ^ AxSIZE

  3. burst_length = AxLEN + 1

  4. aligned_address = (int(start_address / number_bytes)) * number_bytes

基于burst type 为INCR和wrap两种情况,对于第n个transfer地址的计算规则如下

2.2. INCR burst 地址计算: 

    address_1 = start_address = AxADDR(起始地址可以不对齐)

    address_n = aligned_address + (n-1)*number_bytes

2.3. WRAP burst 地址上下界及地址计算

    wrap_floor = (int(start_address / (number_bytes * burst_length))) * (number_bytes * burst_length) (起始地址需要对齐)

    wrap_celling = wrap_floor + (number_bytes * burst_length)

    因此对于wrap burst, 一笔burst中的每个transfer的地址取值范围为 wrap_floor<=address_n<wrap_celling

  1. 对于第1个transfer,即address_1 = start_address;

  2. 对于第n个transfer,address_n = address_n-1 + number_bytes == wrap_celling ? wrap_floor :  address_n-1 + number_bytes; 即第n个transfer的地址按照INCR burst计算出来后,如果值和wrap_celling 相等,那么第n个transfer的地址则需要绕回到wrap_floor, 如果不等,则地址继续递增


三、详细示例

3.1.  起始地址对齐

    一笔burst(无论读写)的起始地址为AxADDR = 0x30,AxLEN = 3, AxSIZE = 4

3.1.1 INCR burst

    number_bytes = 2^4 = 16

    burst_length = 3 + 1 = 4

    aligned_address = 0x30(起始地址对齐)

    address_1 = start_address = 0x30

    address_2 = aligned_address + (2 - 1) * 16 = 0x30 + 16 = 0x40

    address_3 = aligned_address + (3 - 1) * 16 = 0x30 + 32 = 0x50

    address_4 = aligned_address + (4 - 1) * 16 = 0x30 + 48 = 0x60

3.1.2 wrap burst

    number_bytes = 2^4 = 16

    burst_length = 3 + 1 = 4

    aligned_address = 0x30(起始地址对齐)

    wrap_floor = (int(0x30 / (16 * 4))) * (16 * 4) = int(0x30 / 0x40) * 0x40 = 0x00

    wrap_celling = 0x00 + (16 * 4) = 0x40

    address_1 = start_address = 0x30

    address_2 = address_1 + 16 == 0x40 ? 0x00 : address_1 + 16 = 0x00(address_1 + 16 = 0x40)

    address_3 = address_2 + 16 = 0x10

    address_4 = address_3 + 16 = 0x20

3.2. 起始地址非对齐

    一笔burst(无论读写)的起始地址为AxADDR = 0x32,AxLEN = 3, AxSIZE = 4

3.2.1 INCR burst    

    number_bytes = 2^4 = 16

    burst_length = 3 + 1 = 4

    aligned_address = (int(0x32 / 16)) * 16 = 3 * 16 = 0x30

    address_1 = start_address = 0x32

    address_2 = aligned_address + (2 - 1) * 16 = 0x30 + 16 = 0x40

    address_3 = aligned_address + (3 - 1) * 16 = 0x30 + 32 = 0x50

    address_4 = aligned_address + (4 - 1) * 16 = 0x30 + 48 = 0x60

参考文献

[1] AMBA® AXI and ACE Protocol Specification

### AXI4窄突发传输规范及其应用 #### 定义与特性 AXI4 协议支持多种类型的突发传输模式,其中包括窄突发(Narrow Burst),这允许数据宽度小于总线宽度的数据传输。当发起者请求的数据量少于目标设备所支持的最大传输宽度时,就会发生这种情况[^1]。 #### 地址对齐规则 在处理非对齐地址的情况下,AXI协议规定了特定的行为准则。例如,在执行32位传输操作时,默认情况下应遵循4字节边界对齐的要求;然而,如果遇到未对齐的情况,则需要特别注意如何启动和完成这样的传输过程[^3]。 #### 实现细节 为了实现窄突发功能,AMBA AXI接口定义了一组参数用于描述每次事务的具体情况: - `BURST SIZE`:指定了单次访问中的最小粒度(即8, 16, 32 bits等) - `LENGTH`:表示整个突发序列中包含多少个有效载荷项 - `BURST TYPE`:指示是固定型(`FIXED`)、增量型(`INCR`)还是包裹型(`WRAP`) 对于窄突发而言,长度字段会指定实际要传送的数据单元数量,并且可能低于当前系统设定的最大限度。此外,还需要设置合适的`SIZE`值以匹配源端提供的较小单位尺寸。 ```c++ // C++ pseudo code to demonstrate setting up a narrow burst transaction on an AXI bus. void setup_narrow_burst(AXIMasterInterface& master_if, uint32_t start_addr, unsigned int num_bytes) { // Ensure the address is aligned according to the data width requirements of the target device. // Set up the write command with appropriate parameters for a narrow burst. axi_write_command cmd; cmd.address = start_addr; // Start Address cmd.length = (num_bytes / 4); // Number of words based on byte count assuming word=4bytes cmd.size = log2(num_bytes); // Size field value depends on number of bytes per beat // Send the configured command over the AXI interface. master_if.sendWriteCommand(cmd); } ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值