我想询问以下问题的任何想法:我想将宽度为787:0位的一个名为dut的块的输入端口连接到一个字节接口。我做的事情如下:
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)我希望保持连接的顺序,即:
Byte_7:0 ->input7:0
Byte_17:0 ->input15:8
但我得到的是:
Byte_7:0 ->input787:780
Byte_17:0 ->input779:772
如果端口匹配,那么调试就容易多了。
是否有办法使这种连接以正确的顺序进行?谢谢
发布于 2019-11-15 14:10:47
在您使用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发布于 2019-11-15 18:15:00
Cat是向后显示的,因为它与Verilog语义相匹配,因此从Scala语义的角度来看是向后的。
考虑:
val xs = List(8, 9, 10)
println(xs(0)) // 8最左边的元素是Scala中的最低阶索引。然而,在Verilog中,情况正好相反:
assign x = {4'hde, 4'had};连接的最左边的部分实际上是结果中的高阶吞食。Scala Cat是为了匹配Verilog语义而制作的,这使得它在Scala中有些违背直觉。
正如斯凯勒所提到的,您可以始终将reverse Vec或Seq参数设置为Cat。或者,您可以转换为一个UInt,它将使用更直观的Scala顺序:
import chisel3._
class Foo extends RawModule {
val in = IO(Input(Vec(4, UInt(8.W))))
val out = IO(Output(UInt(32.W)))
out := in.asUInt
}.asUInt是在所有Data上定义的,因此您也可以使用它将Bundles和其他类型转换为UInt。唯一的问题是,在Vec上定义的许多方法返回Seq,这是Vec的一个超级类型,它不是凿子Data。这意味着您不能做类似于myVec.map(_ === 0.U).asUInt的事情。你总是可以投出一个Seq[T <: Data]。一个包含Chisel Data元素的Data通过VecInit(mySeq)到Vec的VecInit(mySeq),这样您就可以执行VecInit(myVec.map(_ === 0.U)).asUInt了
https://stackoverflow.com/questions/58875230
复制相似问题