summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/VendingMachine.scala
diff options
context:
space:
mode:
authorHenry Cook2015-11-06 13:23:24 -0800
committerHenry Cook2015-11-06 13:25:07 -0800
commit7fe61318433a8ecaac80ef2b547a88ab9dc04aec (patch)
tree466be7da48a2dfe57b37ada346ebaf01e82389f8 /src/test/scala/chiselTests/VendingMachine.scala
parent89c5d10c81808406b6ae684e1e122d440466280c (diff)
added elaboration tests for remaining old Chisel3 examples
Diffstat (limited to 'src/test/scala/chiselTests/VendingMachine.scala')
-rw-r--r--src/test/scala/chiselTests/VendingMachine.scala67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/VendingMachine.scala b/src/test/scala/chiselTests/VendingMachine.scala
new file mode 100644
index 00000000..8a21cb2e
--- /dev/null
+++ b/src/test/scala/chiselTests/VendingMachine.scala
@@ -0,0 +1,67 @@
+// See LICENSE for license details.
+
+package chiselTests
+import Chisel._
+
+class VendingMachine extends Module {
+ val io = new Bundle {
+ val nickel = Bool(dir = INPUT)
+ val dime = Bool(dir = INPUT)
+ val valid = Bool(dir = OUTPUT) }
+ val c = UInt(5, width = 3)
+ val sIdle :: s5 :: s10 :: s15 :: sOk :: Nil = Enum(UInt(), 5)
+ val state = Reg(init = sIdle)
+ when (state === sIdle) {
+ when (io.nickel) { state := s5 }
+ when (io.dime) { state := s10 }
+ }
+ when (state === s5) {
+ when (io.nickel) { state := s10 }
+ when (io.dime) { state := s15 }
+ }
+ when (state === s10) {
+ when (io.nickel) { state := s15 }
+ when (io.dime) { state := sOk }
+ }
+ when (state === s15) {
+ when (io.nickel) { state := sOk }
+ when (io.dime) { state := sOk }
+ }
+ when (state === sOk) {
+ state := sIdle
+ }
+ io.valid := (state === sOk)
+}
+
+/*
+class VendingMachineTester(c: VendingMachine) extends Tester(c) {
+ var money = 0
+ var isValid = false
+ for (t <- 0 until 20) {
+ val coin = rnd.nextInt(3)*5
+ val isNickel = coin == 5
+ val isDime = coin == 10
+
+ // Advance circuit
+ poke(c.io.nickel, int(isNickel))
+ poke(c.io.dime, int(isDime))
+ step(1)
+
+ // Advance model
+ money = if (isValid) 0 else (money + coin)
+ isValid = money >= 20
+
+ // Compare
+ expect(c.io.valid, int(isValid))
+ }
+}
+*/
+
+class VendingMachineSpec extends ChiselPropSpec {
+
+ property("VendingMachine should elaborate") {
+ elaborate { new VendingMachine }
+ }
+
+ ignore("VendingMachineTester should return the correct result") { }
+}