默认情况下,AXI4 主接口从地址 0x00000000
启动所有读写操作。例如,给定以下代码时,设计会读取从地址 0x00000000
到 0x000000C7
(50 个 32 位代码字,提供 200 字节)的数据,它表示 50 个地址值。随后,设计会将数据重新写入相同地址。
void example(volatile int *a){
#pragma HLS INTERFACE mode=m_axi depth=50 port=a
#pragma HLS INTERFACE mode=s_axilite port=return bundle=AXILiteS
int i;
int buff[50];
memcpy(buff,(const int*)a,50*sizeof(int));
for(i=0; i < 50; i++){
buff[i] = buff[i] + 100;
}
memcpy((int *)a,buff,50*sizeof(int));
}
要应用地址偏移,请将 -offset
选项与 INTERFACE 指令搭配使用,并指定以下选项之一:
-
off
:不应用偏移地址。这是默认方式。 -
direct
:向设计添加 32 位端口以应用地址偏移。 -
slave
:在 AXI4-Lite 接口内添加 32 位寄存器以应用地址偏移。
在最终 RTL 中,Vitis HLS 会将地址偏移直接应用于 AXI4 主接口生成的任意读取地址或写入地址。这样即可允许设计访问系统中的任意地址位置。
如果在 AXI 接口中使用 slave
选项,则必须在设计接口上使用 AXI4-Lite 端口。赛灵思建议使用以下编译指示来实现 AXI4-Lite 接口:
#pragma HLS INTERFACE mode=s_axilite port=return
此外,如果使用 slave
选项并使用多个 AXI4-Lite 接口,则必须确保 AXI 主端口偏移寄存器已与正确的 AXI4-Lite 接口捆绑。在以下示例中,端口 a
作为含偏移和 AXI4-Lite 接口(名为 AXI_Lite_1
和 AXI_Lite_2
)的 AXI 主接口来实现:
#pragma HLS INTERFACE mode=m_axi port=a depth=50 offset=slave
#pragma HLS INTERFACE mode=s_axilite port=return bundle=AXI_Lite_1
#pragma HLS INTERFACE mode=s_axilite port=b bundle=AXI_Lite_2
以下 INTERFACE 指令是确保端口 a
的偏移寄存器与名为 AXI_Lite_1
的 AXI4-Lite 接口捆绑所必需的:
#pragma HLS INTERFACE mode=s_axilite port=a bundle=AXI_Lite_1