1

我正在尝试将 aBlackBox连接到任意Bundle,但宽度推断似乎不适用于 fromBits 函数。以下编译良好:

class testBundle extends Bundle {
  val io1 = Bool(INPUT)
  val io2 = UInt(INPUT,10)
}

class testBox extends BlackBox {
  val io = new Bundle {
    val in = Bits(INPUT) # Width inference works fine here
    val out = Bits(OUTPUT,(new testBundle).getWidth) # But it doesn't work here!
  }
}

class test extends Module {
  val io = new Bundle {
    val in = new testBundle
    val out = (new testBundle).flip()
  }
  val testbox = Module(new testBox)
  testbox.io.in := io.in.toBits
  io.out := io.out.fromBits(testbox.io.out)
}

但是如果我删除这个(new testBundle).getWidth参数,Chisel 就无法推断出输出端口的宽度并且会出错。如何testBox连接到任意捆绑包?

4

1 回答 1

0

现在我通过将包作为参数传递给 BlackBox 来解决这个问题:

class testBox(b:Bundle) extends BlackBox {
  val w = b.getWidth
  val io = new Bundle {
    val in = Bits(INPUT,w)
    val out = Bits(OUTPUT,w)
  }
}

class test extends Module {
  val io = new Bundle {
    val in = new testBundle
    val out = (new testBundle).flip()
  }
  val testbox = Module(new testBox(io.in))
  testbox.io.in := io.in.toBits
  io.out := io.out.fromBits(testbox.io.out)
}

不过,我欢迎更清洁的解决方案。

于 2015-05-29T16:26:04.843 回答