首页 > 解决方案 > 使用 Cat 运算符维护 FIRRTL 上的连接顺序

问题描述

我想就以下问题询问任何想法:我想将一个名为dut的块的输入端口连接到一个字节接口,该块的宽度为 787:0 位。我正在做以下事情:

val io = this.IO(new VerilatorHarnessIO(input_byte_count, output_byte_count*2))
val dut = Module(new DUT(dut_conf))

// inputs
val input_bytes = Cat(io.input_bytes)
val input_width = input_byte_count * 8
dut.io.inputs := input_bytes(input_width-1, input_width - dut_conf.inputBits)

我希望保留连接的顺序,即:

字节_0[7:0] ->输入[7:0]

字节_1[7:0] ->输入[15:8]

但我得到的是:

字节_0[7:0]->输入[787:780]

字节_1[7:0] ->输入[779:772]

如果端口匹配,调试会容易得多。

有没有办法以正确的顺序建立这种联系?谢谢

标签: chiselregister-transfer-level

解决方案


在你应该做你想做的事之前使用该reverse方法。Cat

考虑以下凿子:

import chisel3._
import chisel3.stage.{ChiselStage, ChiselGeneratorAnnotation}
import chisel3.util.Cat

class Foo extends RawModule {
  val in = IO(Input(Vec(4, UInt(8.W))))
  val out = IO(Output(UInt(32.W)))

  out := Cat(in.reverse)
}

(new ChiselStage)
  .execute(Array.empty, Seq(ChiselGeneratorAnnotation(() => new Foo)))

这将生成以下 Verilog,其中的字节按您要查找的顺序排列:

module Foo(
  input  [7:0]  in_0,
  input  [7:0]  in_1,
  input  [7:0]  in_2,
  input  [7:0]  in_3,
  output [31:0] out
);
  wire [15:0] _T; // @[Cat.scala 29:58]
  wire [15:0] _T_1; // @[Cat.scala 29:58]
  assign _T = {in_1,in_0}; // @[Cat.scala 29:58]
  assign _T_1 = {in_3,in_2}; // @[Cat.scala 29:58]
  assign out = {_T_1,_T}; // @[<pastie> 25:7]
endmodule

推荐阅读