生成块项中的 SystemVerilog 变量索引

SystemVerilog Variable index in generate block items

我用几个SPI接口编写SPI从BFM模块。我使用 Active-HDL 9.1。我在我的 SystemVerilog 代码中生成了几个块(spi slaves)。我还编写了读取和重置此块中数据的函数。这是我的代码的一部分:

module bfm_spi(itf_spi);
   parameter C_NUM = 1;
   parameter C_DATA_WIDTH = 32;

   spi_interface  itf_spi [C_NUM];


   genvar i;
   generate
      for(i=0; i < C_NUM; i++) begin : bfm_spi_arr
     bfm_spi_1 #(.C_DATA_WIDTH(C_DATA_WIDTH)) bfm_spi_1_i (itf_spi[i]); 
      end
   endgenerate

   /**
    * Reset all input buffers
    * */
   task Reset;
      integer i;
      for(i = 0; i < C_NUM; i++) bfm_spi_arr[i].bfm_spi_1_i.Reset(); //Error this
   endtask // Reset

在编译期间编译器写入错误行,其中我注意到 "Error this"。

Error message: Generate block item selection with variable index is not supported: i

如果我用常量替换i,编译就OK了。

module bfm_spi(itf_spi);
   parameter C_NUM = 1;
   parameter C_DATA_WIDTH = 32;

   spi_interface  itf_spi [C_NUM];


   genvar i;
   generate
      for(i=0; i < C_NUM; i++) begin : bfm_spi_arr
     bfm_spi_1 #(.C_DATA_WIDTH(C_DATA_WIDTH)) bfm_spi_1_i (itf_spi[i]); 
      end
   endgenerate

   /**
    * Reset all input buffers
    * */
   task Reset;
      integer i;
      for(i = 0; i < C_NUM; i++) bfm_spi_arr[0].bfm_spi_1_i.Reset(); //OK
   endtask // Reset

如何在我的任务 Reset() 中生成 select 多个 bfm_spi_1_i 块?此BFM模块仅用于仿真,不用于实现

您可以做什么创建一个接口或抽象class,其中的实现调用生成

中的每个 Reset()
interface class Reset_c; // you can use a virtual class if your simulator does not yet support interface classes.
  pure virtual task Reset;
endclass
Reset_c R_h[C_NUM]; // array of handles to each implementation instance
 for(genvar i=0; i < C_NUM; i++) begin : bfm_spi_arr
   bfm_spi_1 #(.C_DATA_WIDTH(C_DATA_WIDTH)) bfm_spi_1_i (itf_spi[i]); 

   class Reset_imp implements Reset_c;
     virtual task Reset;
        bfm_spi_1_i.Reset()
     endtask
  endclass
  initial R_h[i] = Reset_imp::new;
 end : bfm_spi_arr

   task Reset;
      for(int i = 0; i < C_NUM; i++) R_h[i].Reset();
   endtask // Reset