Skip to content

Commit 508ac69

Browse files
committed
1 parent 3b906ab commit 508ac69

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package hdlbits.circuits
2+
3+
import chisel3._
4+
import chisel3.util.{switch, is}
5+
6+
// _root_ disambiguates from package chisel3.util.circt if user imports chisel3.util._
7+
import _root_.circt.stage.ChiselStage
8+
9+
// Generate Verilog sources and save it in file HdlBitsExamsEce2412014Q5b.sv
10+
object HdlBitsExamsEce2412014Q5b extends App {
11+
ChiselStage.emitSystemVerilogFile(
12+
new HdlBitsExamsEce2412014Q5b,
13+
firtoolOpts = Array(
14+
"-disable-all-randomization",
15+
"-strip-debug-info"
16+
),
17+
args = Array("--target-dir", "gen/hdlbits/circuits")
18+
)
19+
}
20+
21+
// https://hdlbits.01xz.net/wiki/Exams/ece241_2014_q5b
22+
class HdlBitsExamsEce2412014Q5b extends RawModule {
23+
val clk = IO(Input(Clock()))
24+
val areset = IO(Input(Bool()))
25+
val x = IO(Input(Bool()))
26+
val z = IO(Output(Bool()))
27+
28+
// State register with clock and reset
29+
val state = withClockAndReset(clk, areset.asAsyncReset) {
30+
RegInit(0.U(1.W))
31+
}
32+
33+
// State transition logic
34+
switch(state) {
35+
is(0.U) {
36+
state := Mux(x, 1.U, 0.U)
37+
}
38+
}
39+
// Output logic
40+
z := (state === 0.U && x) || (state === 1.U && !x)
41+
}

0 commit comments

Comments
 (0)