【问题标题】:Exception connecting Vec of IOIO 连接 Vec 异常
【发布时间】:2023-03-06 06:42:01
【问题描述】:

谁能解释这个结构的问题是什么?我有一个带有 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"))
}

【问题讨论】:

    标签: chisel


    【解决方案1】:

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

    错误消息中提到了这一点(例如(MyBundle[3](Wire in Lower))),但我完全看到了混乱——不是很清楚,VecInit 可能命名错误。 API 中这种特殊的模糊性来自 Chisel 中的历史设计决策,这些决策正在慢慢得到修复,但它有时会咬用户,对此感到抱歉。

    这是完成您想要的事情的正确方法,只需使用IO(Vec(&lt;n&gt;, &lt;type&gt;))Vec(&lt;n&gt;, &lt;type&gt;) 是创建 Vec 类型的方法,在本例中是 Vec 类型的 IO,而不是创建 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

    【讨论】:

    • 谢谢杰克。这就说得通了。我可能过度简化了测试用例,因为我最终选择 VecInit 的原因是我已经有一个 Seq,我正试图将其转换为 Vec。 val apb = VecInit(clients.map({x => IO(new ApbChannel).suggestName(x.name)}))。这样做的首选方式是什么?
    • 将其标记为已接受,因为它确实解决了问题。如果您有时间,请参阅stackoverflow.com/q/67387506/1795592,它处理让SuggestName 处理IO(Vec()) 的各个元素。再次感谢。
    • 你可能收到了通知,但我已经回复了stackoverflow.com/a/68762881/2483329
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多