Files
SpinalTemplateSbt/src/main/scala/mylib/MyTopLevelSim.scala
2017-12-19 00:12:02 +01:00

47 lines
1.1 KiB
Scala

package mylib
import spinal.core._
import spinal.sim._
import spinal.core.sim._
import scala.util.Random
//MyTopLevel's testbench
object MyTopLevelSim {
def main(args: Array[String]) {
SimConfig(new MyTopLevel).withWave.doManagedSim{dut =>
//Fork a process to generate the reset and the clock on the dut
dut.clockDomain.forkStimulus(period = 10)
var modelState = 0
var idx = 0
while(idx < 100){
//Generate random values to drive the reference model and the dut
val cond0, cond1 = Random.nextBoolean()
//Drive the dut inputs
dut.io.cond0 #= cond0
dut.io.cond1 #= cond1
//Wait a rising edge on the clock
dut.clockDomain.waitRisingEdge()
//Update the reference model values
val modelFlag = modelState == 0 || cond1
if(cond0) {
modelState = (modelState + 1) & 0xFF
}
//Check that the dut values match with the reference model ones
assert(dut.io.state.toInt == modelState)
assert(dut.io.flag.toBoolean == modelFlag)
idx += 1
}
}
}
}