[英]In chisel 3, how to initialize memory test code with text file
I wanted to initialize memory test code in chisel 3.我想在凿子 3 中初始化 memory 测试代码。
I referred the code from this website ( https://www.chisel-lang.org/chisel3/docs/appendix/experimental-features#loading-memories )我参考了这个网站的代码( 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 }
}
}
This code works well when it is compiled to verilog.此代码在编译为 verilog 时运行良好。
So, i thought that it also can emit number in tester code.所以,我认为它也可以在测试代码中发出数字。
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)
}
}
}
However, this test code doesn't work well.但是,此测试代码效果不佳。
Its output is just zero.它的 output 只是零。
I want to know how to initialize chisel test code with text file.我想知道如何用文本文件初始化凿子测试代码。
It's seem to be a path problem.这似乎是一个路径问题。 Give the path of your memory content file in tester code when you instantiate module:
实例化模块时,在测试代码中给出 memory 内容文件的路径:
//...
it should "read memory" in{
test (new InitMemInline("/the/path/to/memory.hex")) { c=>
//...
If your memory.hex is well formated it should solve the problem.如果您的 memory.hex 格式正确,它应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.