简体   繁体   English

提供凿子黑匣子的仿真模型

[英]Providing a simulation model for a chisel blackbox

I am trying to simulate a system using chisel 3. The system has a blackbox that has a verilog.我正在尝试使用 chisel 3 模拟一个系统。该系统有一个带有 verilog 的黑匣子。 The verilog code is not behavioural, it simply instantiate a module that the synthesizer configures.I know the behaviour of the module and want to write a code in chisel to simulate the behaviour. verilog 代码不是行为性的,它只是实例化合成器配置的模块。我知道模块的行为,想用凿子编写代码来模拟行为。

So basically how to extend a blackbox in chisel 3 with a behaviour that could be used in simulation.所以基本上如何使用可用于模拟的行为来扩展 chisel 3 中的黑盒。

Currently there is no built-in way to directly provide a behavioral model to substitute a blackbox when testing chisel3 code.目前没有内置的方法可以在测试 chisel3 代码时直接提供行为模型来替代黑盒。 However, there are some options that could work in your situation:但是,有一些选项可能适用于您的情况:

Option 1: Use a Chisel SyncReadMem and substitute it with --repl-seq-mem选项 1:使用 Chisel SyncReadMem并将其替换为--repl-seq-mem

For memories in particular, you can used the built-in SyncReadMem which will work fine in all simulation and even formal verification backends.特别是对于内存,您可以使用内置的SyncReadMem ,它将在所有模拟甚至形式验证后端中正常工作。 Then for your "tape-out" / FPGA synthesis you replace all synchronous read memories with Verilog code that uses the Vendor provided memory.然后,对于您的“流片”/FPGA 合成,您将所有同步读取存储器替换为使用供应商提供的存储器的 Verilog 代码。 This flow is used by the open-source chipyard project for ASIC tapeout.这个流程被用于 ASIC tapeout 的开源chipyard项目使用。 You essentially need to pass the following flags to the firrtl compiler: --infer-rw --repl-seq-mem which will then automatically blackbox all SyncReadMem instances and generate description files for them.您基本上需要将以下标志传递给 firrtl 编译器: --infer-rw --repl-seq-mem然后它将自动黑盒所有SyncReadMem实例并为它们生成描述文件。 From these files you can write Verilog implementations using the vendor provided RTL.从这些文件中,您可以使用供应商提供的 RTL 编写 Verilog 实现。 Hint : You can use --gen-mem-verilog to get a blueprint for the Verilog modules you need to implement in terms of the Xilinx block.提示:您可以使用--gen-mem-verilog来获取您需要根据 Xilinx 块实现的 Verilog 模块的蓝图。

Option 2: Use a Chisel SyncReadMem and try to get BRAM interference working选项 2:使用 Chisel SyncReadMem并尝试让 BRAM 干扰正常工作

You should be able to get Chisel SyncReadMem to be correctly inferred as BRAM by the Xilinx tool.您应该能够让 Xilinx 工具将 Chisel SyncReadMem正确推断为 BRAM。 This options is afaik used by the open-source firesim project to generate RTL for Xilinx FPGAs.这个选项是开源firesim项目用来为 Xilinx FPGA 生成 RTL 的 afaik。 The flags you would want to pass to the firrtl compiler are: --infer-rw --target:fpga您想要传递给 firrtl 编译器的标志是: --infer-rw --target:fpga

Option 3: Use a generator parameter to choose between the behavioral and the synthesizable model选项 3:使用生成器参数在行为模型和可综合模型之间进行选择

This option is the most versatile, but also requires the most work.这个选项是最通用的,但也需要最多的工作。 Here is a quick draft of what that may look like:这是可能看起来像的快速草稿:

import chisel3._


class MemIO extends Bundle {
  val addr = Input(UInt(4.W))
  val doWrite = Input(Bool())
  val dataIn = Input(UInt(8.W))
  val dataOut = Output(UInt(8.W))
}

class MemBlackBox extends BlackBox {
  val io = IO(new MemIO)

  // ...
}

class MemBehavioral extends Module {
  val io = IO(new MemIO)

  // ...
  io <> DontCare // to make things compile
}

class Memory(simulation: Boolean) extends Module {
  val io = IO(new MemIO)

  if(simulation) {
    val inner = Module(new MemBehavioral) ; inner.io <> io
  } else {
    val inner = Module(new MemBlackBox) ; inner.io <> io
  }
  
}




val pretty = Array(
  "--emission-options", "disableMemRandomization,disableRegisterRandomization"
)
println("Behavioral")
println(getVerilogString(new Memory(simulation = true), pretty))
println("\n\nSynthesizable")
println(getVerilogString(new Memory(simulation = false), pretty))

You can see the output on scasti .您可以在 scasti 上看到输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM