File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
src/main/scala/hdlbits/circuits Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments