繁体   English   中英

在凿子3中,如何用文本文件初始化memory测试代码

[英]In chisel 3, how to initialize memory test code with text file

我想在凿子 3 中初始化 memory 测试代码。

我参考了这个网站的代码( https://www.chisel-lang.org/chisel3/docs/appendix/experimental-features#loading-memories

import chisel3._
import chisel3.util.experimental.loadMemoryFromFileInline

class InitMemInline(memoryFile: String = " My text file location ") extends Module {
  val width: Int = 32
  val io = IO(new Bundle {
    val enable = Input(Bool())
    val write = Input(Bool())
    val addr = Input(UInt(10.W))
    val dataIn = Input(UInt(width.W))
    val dataOut = Output(UInt(width.W))
  })

  val mem = SyncReadMem(1024, UInt(width.W))
  // Initialize memory
  if (memoryFile.trim().nonEmpty) {
    loadMemoryFromFileInline(mem, memoryFile)
  }
  io.dataOut := DontCare
  when(io.enable) {
    val rdwrPort = mem(io.addr)
    when (io.write) { rdwrPort := io.dataIn }
      .otherwise    { io.dataOut := rdwrPort }
  }
}

此代码在编译为 verilog 时运行良好。

所以,我认为它也可以在测试代码中发出数字。

    it should "read memory" in{
        test (new InitMemInline) { c=>

            c.io.enable.poke(true.B)
            c.io.addr.poke(0.U)
                
            c.clock.step(1)
            c.io.dataOut.expect(1.U)

            c.io.addr.poke(1.U)
            c.clock.step(1)
            c.io.dataOut.expect(2.U)
        }
    }
}

但是,此测试代码效果不佳。

它的 output 只是零。

我想知道如何用文本文件初始化凿子测试代码。

这似乎是一个路径问题。 实例化模块时,在测试代码中给出 memory 内容文件的路径:

//...
    it should "read memory" in{
        test (new InitMemInline("/the/path/to/memory.hex")) { c=>
//...

如果您的 memory.hex 格式正确,它应该可以解决问题。

暂无
暂无

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

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