How to do a vector of modules?

三世轮回 提交于 2019-12-21 13:30:13

问题


I want to instantiate a one dimensional array of element, and element extends Module. How would I do this? If I say my best guess, which is:

val elements = Vec( 64, new element )

I get the following error message:

[error] /Users/mykland/work/chisel/array.scala:20: overloaded method value apply with alternatives:
[error]   [T <: Chisel.Data](n: Int, gen: => T)Chisel.Vec[T] <and>
[error]   [T <: Chisel.Data](elt0: T, elts: T*)Chisel.Vec[T] <and>
[error]   [T <: Chisel.Data](gen: => T, n: Int)Chisel.Vec[T]
[error]  cannot be applied to (Int, ascenium.element)
[error]     val elements    = Vec( 64, new element )
[error]                       ^

Thanks in advance for any assistance you can provide.


回答1:


Edit: I'm adding what I think is a better way to generate a vector of modules:

val my_args = Seq(1,2,3,4)
val exe_units = for (i <- 0 until num_units) yield
{
   val exe_unit = Module(new AluExeUnit(args = my_args(i)))
   // any wiring or other logic can go here
   exe_unit
}

Notice that this method allows you to individually tailor each unit differently, and returns a Seq() of Chisel modules. It will generate better looking hardware too.

But if you really need to be able to dynamically index into your array of Modules, you can pull out a Vec() of the IOs like this:

val exe_units_io = Vec(exe_units.map(_.io))

(This is the old suggestion, which I think is less good).

You can create a Vec of Modules as follows:

val vec_of_elements = Vec.fill(n) {Module(new MyElement(my_args)).io }

But notice, a Vec can really only be either of Wires or of Registers, so we've really just created a Vec of the IO Wires, which just so happen to create the Modules we care about in the process.



来源:https://stackoverflow.com/questions/33621533/how-to-do-a-vector-of-modules

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!