Add exercises

This commit is contained in:
Job Noorman 2022-10-13 11:52:00 +02:00
commit ac3cf23632
19 changed files with 21160 additions and 0 deletions

View file

@ -0,0 +1,55 @@
package exercises
import spinal.core._
import spinal.core.sim._
object PopcntSim {
def runSim(width: BitCount, multiCycle: Boolean, input: Int): Unit = {
SimConfig.withWave.compile(new Popcnt(width, multiCycle)).doSim {dut =>
dut.clockDomain.forkStimulus(10)
dut.value #= input
dut.start #= true
dut.clockDomain.waitSampling()
dut.start #= false
while (!dut.ready.toBoolean) {
dut.clockDomain.waitSampling()
}
dut.clockDomain.waitSampling()
println(s"popcnt($input) = ${dut.count.toBigInt}")
}
}
def main(args: Array[String]) {
runSim(4 bits, false, 15)
}
}
object ShiftRegSim {
def createShiftReg: ShiftReg = {
val sr = new ShiftReg
sr.addReg("foo", 8 bits, 3)
sr.addReg("bar", 16 bits, 5)
sr
}
def main(args: Array[String]) {
SimConfig.withWave.compile(createShiftReg).doSim {dut =>
dut.clockDomain.forkStimulus(10)
val (fooIn, fooOut) = dut.getReg("foo")
val (barIn, barOut) = dut.getReg("bar")
var tick = 0
while (tick < 10) {
fooIn #= tick
barIn #= 10 - tick
dut.clockDomain.waitSampling()
tick += 1
}
}
}
}