chisel - 如何将零打包到凿子中的捆绑中

标签 chisel

我有一个关于将零打包到 bundle 中的问题。例如,考虑下面的代码:

    class CmplxNum(val bitwidth: Int) extends Bundle {
       val real = SInt(INPUT,bitwidth.W)
       val imag = SInt(INPUT,bitwidth.W)
    }  

    class MyClass extends Module {
       val io = IO(new Bundle {
          val in = new CmplxNum(16)
          val load = Bool(INPUT)
          val clr  = Bool(INPUT)
          ...
       })
       ...
       val sample = RegEnable(io.in,0.S,io.load) // <-- how do i set the reset value     
       When(io.clr) {
          sample <> sample.fromBits(0.S) // <-- I tried this it compiles, but dont know if it is correct  
       }

    }

在 RegEnable 和 clr 情况下,如何将零打包到此 bundle 中? 对于 RegEnable 我遇到了类型不匹配的详细错误,这是有道理的

最佳答案

这是一种方法。它依赖于相对较新的 BundleLiterals (new CmplxNum(16)).Lit(_.real -> 0.S, _.imag -> 0.S)。我还对您的代码进行了一些重构,以使用当前的 chisel3 习惯用法。如果没有特定的需要,我不建议将您的输入/输出放在捆绑中。另外,更现代的方法是将 IO 字段包装在 Input() 或 Output() 中

import chisel3._
import chisel3.util.RegEnable
import chisel3.experimental.BundleLiterals._


class CmplxNum(val bitwidth: Int) extends Bundle {
  val real = SInt(bitwidth.W)
  val imag = SInt(bitwidth.W)
}

class MyClass extends Module {
  val io = IO(new Bundle {
    val in = Input(new CmplxNum(16))
    val load = Input(Bool())
    val clr  = Input(Bool())
      ...
  })

    ...
  val sample = RegEnable(
    io.in,
    init = (new CmplxNum(16)).Lit(_.real -> 0.S, _.imag -> 0.S),
    enable = io.load
  )
  when(io.clr) {
    sample <> sample.fromBits(0.S) // <-- I tried this it compiles, but dont know if it is correct
  }

}

关于chisel - 如何将零打包到凿子中的捆绑中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57405246/

相关文章:

chisel - 从列表生成 Chisel 模块 IO 接口(interface)

chisel - 如何向火箭芯片外设添加 sbus 主控

凿子束连接和类型 安全

chisel - Chisel 开发者指南?

chisel - 如何将 IO 端口动态添加到 Chisel Bundle?

chisel - 模块是对象还是类?

chisel - 如何调用内部定义的变量 withClockAndReset

scala - 具有多时钟域的凿子测试仪 SteppedHWIOTester