Add exercises
This commit is contained in:
commit
ac3cf23632
19 changed files with 21160 additions and 0 deletions
55
Exercises/src/main/scala/exercises/Top.scala
Normal file
55
Exercises/src/main/scala/exercises/Top.scala
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue