分享

HLS学习(二)Using AXI4 Interfaces

 奔跑的瓦力 2019-06-05

第一部分 AXI4-Stream Interfaces  暂时不细看。

第二部分

AXI4-Lite Interface

作用:use an AXI4-Lite interface to allow the design to be controlled by a CPU or microcontroller。

 HLS会自动给各个使用axilite接口的port分配地址,会在驱动文件里提供地址。

如果想自己显式的指明地址,可以使用offset选项。如上图。注意:hls会保留0x0000 到0x000C的地址给block-level I/O protocol signals and interrupt controls。

这是综合之后的模块,都会产生一个中断端口。当函数返回的时候,会产生一个中断信号。也可以使用block-level protocols的信号:ap_done(函数完成所有操作), ap_ready(模块准备好等待新的输入)。 这两个信号都可以触发中断。

C Driver Files

AXI4-Lite slave interface综合完成之后,会自动生成驱动文件。C 驱动文件提供了所有通过该AXI4-Lite slave interface 控制模块的操作。驱动包括standalone模式和linux模式。

P116对生成的驱动文件进行了详细的解释。

注意生成的驱动文件使用的参数都是U32,使用的时候要注意一下类型转换,以下为类型转换示例:

P503对驱动API进行了详细的解释。这里的Example 和 DUT就是你所综合出的IP的名称。

如何控制硬件?

xexample_hw.h 文件provides a complete list of the memory mapped locations for the ports grouped into the AXI4-Lite slave interface.以下为各个端口的地址分布。

 如何使用呢,举个例子:ap_start 寄存器设为1,则启动了模块计算,完成之后,ap_done, ap_idle and ap_ready registers会被设置,过程可以用下图描述:

推荐使用方法一:让硬件模块执行一次

推荐使用方法二:让硬件模块连续执行

P122,针对以上两种情况,分别解释了如何使用驱动API,包括XExample_Set_a, XExample_Set_b,XExample_Set_c_i,ap_start=1 then XExample_Start开始,XExample_Get_c_o_vld来确认输出数据有效,然后得到数据XExample_Get_c_o.

如何构建SDK程序

  • Create an instance of the HW instance
  • Look Up the device configuration
  • Initialize the Device
  • Set the input parameters of the HLS block
  • Start the device and read the results

示例程序:

  1. #include "xexample.h" // Device driver for HLS HW block
  2. #include "xparameters.h"
  3. // HLS HW instance
  4. XExample HlsExample;
  5. XExample_Config *ExamplePtr
  6. int main() {
  7. int res_hw;
  8. // Look Up the device configuration
  9. ExamplePtr = XExample_LookupConfig(XPAR_XEXAMPLE_0_DEVICE_ID);
  10. if (!ExamplePtr) {
  11. print("ERROR: Lookup of accelerator configuration failed.\n\r");
  12. return XST_FAILURE;
  13. }
  14. // Initialize the Device
  15. status = XExample_CfgInitialize(&HlsExample, ExamplePtr);
  16. if (status != XST_SUCCESS) {
  17. print("ERROR: Could not initialize accelerator.\n\r");
  18. exit(-1);
  19. }
  20. //Set the input parameters of the HLS block
  21. XExample_Set_a(&HlsExample, 42);
  22. XExample_Set_b(&HlsExample, 12);
  23. XExample_Set_c_i(&HlsExample, 1);
  24. // Start the device and read the results
  25. XExample_Start(&HlsExample);
  26. do {
  27. res_hw = XExample_Get_c_o(&HlsExample);
  28. } while (XExample_Get_c_o(&HlsExample) == 0); // wait for valid data output
  29. print("Detected HLS peripheral complete. Result received.\n\r");
  30. }

 第三部分

AXI4 Master Interface

作用:支持HLS模块单个数据传输和Burst mode data transfers(一次可以传输多个数据,增大吞吐量。比如像memcpy或者pipeline loop循环的时候非常合适)

示例程序解释:使用memcpy函数,顶层函数参数a指定为AXI4 master interface.

  1. void example(volatile int *a){
  2. #pragma HLS INTERFACE m_axi depth=50 port=a
  3. #pragma HLS INTERFACE s_axilite port=return
  4. //Port a is assigned to an AXI4 master interface
  5. int i;
  6. int buff[50];
  7. //memcpy creates a burst access to memory
  8. memcpy(buff,(const int*)a,50*sizeof(int));
  9. for(i=0; i < 50; i++){
  10. buff[i] = buff[i] + 100;
  11. }
  12. memcpy((int *)a,buff,50*sizeof(int));
  13. }

Controlling the Address Offset in an AXI4 Interface

AXI4 master interface默认开始所有的读写操作都是从0x0地址开始的。如果想设置读写地址偏移,需要用到offset选项。主要解释一下offset = slave的时候,表示在接口处添加一个32位寄存器表示offset的值。设置了offset之后,HLS模块读取或者写出数据的时候会直接添加上偏移,来读取任意位置的数据。

如果使用了slave选项,要确保对应的master port offset register 被捆绑在正确的AXI4-Lite接口上。比如:

  1. #pragma HLS INTERFACE m_axi port=a depth=50 offset=slave
  2. #pragma HLS INTERFACE s_axilite port=return bundle=AXI_Lite_1
  3. #pragma HLS INTERFACE s_axilite port=b bundle=AXI_Lite_2

还需要一句:

#pragma HLS INTERFACE s_axilite port=a bundle=AXI_Lite_1

则把端口绑定在名字为AXI_Lite_1的AXI4-Lite interface上。

 

 

 

 

 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多