chisel - 异常连接IO的Vec

标签 chisel

谁能解释一下这个结构的问题是什么?我有一个带有 IO Vec 的子模块,我试图将其附加到父模块中的等效 IO。

这只用一个 Seq 就可以很好地工作,但是当我在 Vec 中包装时,我在详细说明过程中遇到了一个异常。 Vec 是必需的,因为在我的真实情况下,它在子模块中使用硬件信号进行索引。

错误:

[error] chisel3.internal.ChiselException: Connection between left (MyBundle[3](Wire in Lower)) and source (MyBundle[3](Wire in Upper)) failed @(0).out: Left or Right unavailable to current module.

代码:

package Testcase

import chisel3._
import chisel3.util._
import chisel3.stage.ChiselStage

import amba._

class MyBundle extends Bundle {
  val out = Output(UInt(32.W))
}

class Upper (n : Int) extends RawModule {
  val io = VecInit(Seq.fill(n)(IO(new MyBundle)))
  val lower = Module(new Lower(n))

  // This should word in the Vec case but gets the same error
  // lower.io <> io

  // This works for non Vec case
  (lower.io, io).zipped map (_ <> _)
}


class Lower (n : Int) extends RawModule {
  val io = VecInit(Seq.fill(n)(IO(new MyBundle)))

  for (i <- 0 to n - 1) {
    io(i).out := 0.U
  }
}

object VerilogMain extends App {
  (new ChiselStage).emitVerilog(new Upper(3), Array("--target-dir", "generated"))
}

最佳答案

这里的问题是 VecInit创建一个 Wire类型 Vec并连接 Seq 中的所有内容Wire的元素.你基本上在做的是创建一个 SeqIOs然后将它们连接到 Wire .

错误消息中提到了这一点(例如 (MyBundle[3](Wire in Lower)) ),但我完全看到了困惑——它不是那么清楚 VecInit可能是错误的名字。 API 中的这种特殊歧义来自 Chisel 中的历史设计决策,这些决策正在慢慢得到修复,但它是一个有时会伤害用户的疣,对此深表歉意。

这是完成您想要的事情的正确方法,只需使用 IO(Vec(<n>, <type>)) . Vec(<n>, <type>)是创建类型 Vec 的方法,在本例中为 IO类型 Vec ,而不是创建一个 Wire并连接所有字段:

class Upper (n : Int) extends RawModule {
  //val io = VecInit(Seq.fill(n)(IO(new MyBundle)))
  val io = IO(Vec(n, new MyBundle))
  val lower = Module(new Lower(n))

  // This should word in the Vec case but gets the same error
  lower.io <> io
  
}


class Lower (n : Int) extends RawModule {
  //val io = VecInit(Seq.fill(n)(IO(new MyBundle)))
  val io = IO(Vec(n, new MyBundle))

  for (i <- 0 to n - 1) {
    io(i).out := 0.U
  }
}

(Scastie 链接:https://scastie.scala-lang.org/COb88oXGRmKQb7BZ3id9gg)

关于chisel - 异常连接IO的Vec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68750142/

相关文章:

sbt - chisel 5.0.0-RC1 和 chiseltest

Chisel 和时序约束文件

hdl - 如何获取 chisel 中 UInt() 的大小?

scala - RegInit 仅在复位时初始化值

scala - firrtl 中的 AND 运算未进行符号扩展

凿子同步

chisel - 解复用器 : Unconnected Wires/firrtl error

chisel - 在 Chisel3 中创建通用 Bundle

bus - Chisel:如何实现高效的 one-hot mux?