-
Hi everyone, I'm facing the following problem in chisel: It is important to me to generate the new Bundles dynamically, as the given Bundle is a "CoreBundle" (as defined in trait "HasCoreIO") from the Rocket Chip Generator with a complex structure and lots of nested Bundles. I would like to connect the incoming signals to multiple cores and vote the majority of the output signals of all the cores. Therefore I need a way to wrap the output signals from the cores in separate Bundles, pass them as UInt to my voter and use the UInt output from my voter to drive the CoreBundle output fields. My current approach is to use Record instead of Bundle, so I can recursively set the elements of the Record: class DirectedBundle(bundle: Bundle, dir: SpecifiedDirection) extends Record {
val elements = for ((name, data) <- bundle.elements if DataMirror.specifiedDirectionOf(data.asInstanceOf[Data]) == dir) yield (
if (data.isInstanceOf[Bundle]) {
(name -> new DirectedBundle(data.asInstanceOf[Bundle], dir))
}
else {
(name -> data)
}
)
override def cloneType: this.type = (new DirectedBundle(bundle, dir)).asInstanceOf[this.type]
} I use my DirectedBundle the following way: val out = new DirectedBundle(new DemoBundle(), SpecifiedDirection.Output) Unfortunately, I can not use DataMirror.directionOf(...) instead outside of a Module which makes sense:
But DataMirror.specifiedDirectionOf(...) doesn't do the job for all Data, as some directions are "Unspecified" this way. Is there any alternative/better way of doing this, so I can avoid hard coding the bundle? Many thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello again, I found a way to generate the bundle based on the "ActualDirection". My first approach was quite close to the solution: class DirectedBundle(bundle: Bundle, dir: ActualDirection) extends Record {
val elements =
for ((name, data) <- bundle.elements
if (DataMirror.directionOf(data.asInstanceOf[Data]) == dir || data.isInstanceOf[Bundle])) yield {
if (data.isInstanceOf[Bundle]) {
(name -> new DirectedBundle(data.asInstanceOf[Bundle], dir))
}
else {
(name -> data.asInstanceOf[Data].cloneType)
}
}
override def cloneType: this.type = (new DirectedBundle(bundle, dir)).asInstanceOf[this.type]
} To instantiate a "DirectedBundle", the parameter "bundle" must be hardware, e.g. wrapped in IO: val myWire = Wire(new DirectedBundle(io, ActualDirection.Output)) Please feel free to comment on my solution. Is there a cleaner way? |
Beta Was this translation helpful? Give feedback.
Hello again,
I found a way to generate the bundle based on the "ActualDirection". My first approach was quite close to the solution:
To instantiate a "DirectedBundle", …