玩命加载中 . . .

SpinalHDL基础-例化与传参


传参

class adder(width: Int = 8) extends Module {
  val io = new Bundle {
    val a = in UInt(width bits)
    val b = in UInt(width bits)
    val sum = out UInt(width bits)
  }
  io.sum := io.a + io.b
}

class top extends Module {
  val adder0 = new adder(16)
  val adder1 = new adder(32)
}
module top (
);

  wire       [15:0]   adder0_io_a;
  wire       [15:0]   adder0_io_b;
  wire       [31:0]   adder1_io_a;
  wire       [31:0]   adder1_io_b;
  wire       [15:0]   adder0_io_sum;
  wire       [31:0]   adder1_io_sum;

  adder adder0 (
    .io_a      (adder0_io_a[15:0]    ), //i
    .io_b      (adder0_io_b[15:0]    ), //i
    .io_sum    (adder0_io_sum[15:0]  )  //o
  );
  adder_1 adder1 (
    .io_a      (adder1_io_a[31:0]    ), //i
    .io_b      (adder1_io_b[31:0]    ), //i
    .io_sum    (adder1_io_sum[31:0]  )  //o
  );

endmodule

module adder_1 (
  input      [31:0]   io_a,
  input      [31:0]   io_b,
  output     [31:0]   io_sum
);


  assign io_sum = (io_a + io_b);

endmodule

module adder (
  input      [15:0]   io_a,
  input      [15:0]   io_b,
  output     [15:0]   io_sum
);


  assign io_sum = (io_a + io_b);

endmodule

本文作者: 董续胜

本文链接: https://dxsm.github.io/p/spinalhdl-inst.html

版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0许可协议。转载请注明出处!


 评论