forked from schoeberl/chisel-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First SystemVerilog example in the Chisel book
- Loading branch information
Showing
4 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package verilog | ||
|
||
import chisel3._ | ||
import chisel3.util._ | ||
class Simple extends BlackBox with HasBlackBoxInline { | ||
val io = IO(new Bundle() { | ||
val a, b = Input(UInt(8.W)) | ||
val c = Output(UInt(8.W)) | ||
}) | ||
|
||
setInline("Simple.sv", | ||
"""module Simple( | ||
input [7:0] a, | ||
input [7:0] b, | ||
output reg [7:0] c | ||
); | ||
//- start sv_first | ||
always_comb begin | ||
c = a + b; | ||
end | ||
//- end | ||
endmodule | ||
""") | ||
} | ||
|
||
class SimpleTop extends Module { | ||
val io = IO(new Bundle() { | ||
val a, b = Input(UInt(8.W)) | ||
val c = Output(UInt(8.W)) | ||
}) | ||
|
||
val m = Module(new Simple) | ||
m.io <> io | ||
} | ||
|
||
object Simple extends App { | ||
println(getVerilogString(new SimpleTop())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package verilog | ||
|
||
import chisel3._ | ||
import chiseltest._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
|
||
class SimpleTest extends AnyFlatSpec with ChiselScalatestTester { | ||
"Simple" should "pass" in { | ||
test(new SimpleTop()).withAnnotations(Seq(VerilatorBackendAnnotation)) { dut => | ||
dut.io.a.poke(1.U) | ||
dut.io.b.poke(3.U) | ||
dut.clock.step() | ||
dut.io.c.expect(4.U) | ||
} | ||
} | ||
} |