本文作为SpinalHDL学习笔记第三十篇,介绍SpinalHDL启动仿真器相关内容。
目录:
1.简介
2.配置
3.在同一硬件上运行多个测试
4.从线程中抛出仿真成功或失败结果
5.在失败之前捕获给定时间窗内的波形
1.简介
下面是一个硬件定义 + 测试平台的示例:
import spinal.core._
// Identity takes n bits in a and gives them back in z
class Identity(n: Int) extends Component {
val io = new Bundle {
val a = in Bits(n bits)
val z = out Bits(n bits)
}
io.z := io.a
}
import spinal.core.sim._
object TestIdentity extends App {
// Use the component with n = 3 bits as "dut" (device under test)
SimConfig.withWave.compile(new Identity(3)).doSim{ dut =>
// For each number from 3'b000 to 3'b111 included
for (a <- 0 to 7) {
// Apply input
dut.io.a #= a
// Wait for a simulation time unit
sleep(1)
// Read output
val z = dut.io.z.toInt
// Check result
assert(z == a, s"Got $z, expected $a")
}
}
}