我正在嘗試將隱式引數傳遞給實體化模塊中的子模塊。隱含引數是rocketchip中定義的config包在這里輸入鏈接描述,我想用config包給子模塊傳遞一些常量。但是當我使用模塊實體化時,總是找不到我在子模塊中定義的埠。
頂層模塊定義如下:
package test
import chisel3._
import chisel3.util._
import chisel3.experimental.BaseModule
import chipsalliance.rocketchip.config._
class B extends Module{
val io = IO(
...)
val config = new TConfig
val submod: Class[_ <: Any] = Class.forName("test.T").asInstanceOf[Class[_ <: BaseModule]]
val u_T = Module(submod.getConstructor(classOf[Parameters]).newInstance(config) match {
case a: RawModule => a
})
u_T.io <> ...
}
定義子模塊及其引數:
case class TParams(
P: Int = 100
)
case object TKey extends Field[TParams()]
class TConfig extends Config((site, up, here) => {
case TKey => {
TParams(P=1024)
}
})
abstract class TModule(implicit val p: Parameters) extends Module
with HasParameters
trait HasParameters {
implicit val p: Parameters
}
class T(implicit p: Parameters) extends TModule()(p)
{
val io = IO(new Bundle{...})
}
編譯時,報告顯示找不到子模塊的io埠。
值 io 不是 chisel3.RawModule 的成員
uj5u.com熱心網友回復:
我假設您正在使用反射來實體化您的模塊,因為它是 Rocket-chip 進行頂級實體化的方式,但請注意,rocket-chip 之所以這樣做,是因為它通過命令列接受其頂級模塊的名稱。如果您知道要實體化的類,則可以直接這樣做:
class B extends Module {
val io = IO(
...)
// Note the use of implicit here will ensure the compiler finds it
implicit val config = new TConfig
val submod: test.T = Module(new test.T)
u_T.io <> ...
}
請注意,您始終可以顯式傳遞隱式引數(順便說一下,您在傳遞p給TModule(ie. extends TModule()(p)) 時所做的事情:
class B extends Module {
val io = IO(
...)
// Passing it explicitly
val config = new TConfig
val submod: test.T = Module(new test.T()(config))
u_T.io <> ...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/453087.html
