aboutsummaryrefslogtreecommitdiff
path: root/top_count/src
diff options
context:
space:
mode:
Diffstat (limited to 'top_count/src')
-rw-r--r--top_count/src/Config.scala17
-rw-r--r--top_count/src/counter.scala19
-rw-r--r--top_count/src/top_count.scala47
3 files changed, 83 insertions, 0 deletions
diff --git a/top_count/src/Config.scala b/top_count/src/Config.scala
new file mode 100644
index 0000000..c498303
--- /dev/null
+++ b/top_count/src/Config.scala
@@ -0,0 +1,17 @@
+package top_count
+
+import spinal.core._
+import spinal.core.sim._
+
+object Config {
+ def spinal = SpinalConfig(
+ targetDirectory = sys.props.getOrElse("spinalTargetDir", "top_count/gen"),
+ defaultConfigForClockDomains = ClockDomainConfig(
+ resetKind = ASYNC,
+ resetActiveLevel = LOW
+ ),
+ onlyStdLogicVectorAtTopLevelIo = false
+ )
+
+ def sim = SimConfig.withGhdl.withConfig(spinal).withFstWave
+}
diff --git a/top_count/src/counter.scala b/top_count/src/counter.scala
new file mode 100644
index 0000000..d8dc06e
--- /dev/null
+++ b/top_count/src/counter.scala
@@ -0,0 +1,19 @@
+package top_count
+
+import spinal.core._
+
+case class counter() extends Component {
+ val io = new Bundle {
+ val en_i = in Bool()
+ val cnt_o = out UInt(4 bits)
+ }
+
+ // The counter register
+ val cnt = Reg(UInt(4 bits)) init 0
+
+ when (io.en_i) {
+ cnt := cnt + 1
+ }
+ // Map the register content to the output
+ io.cnt_o := cnt
+}
diff --git a/top_count/src/top_count.scala b/top_count/src/top_count.scala
new file mode 100644
index 0000000..ff2e54a
--- /dev/null
+++ b/top_count/src/top_count.scala
@@ -0,0 +1,47 @@
+package top_count
+
+import spinal.core._
+
+// Hardware definition
+case class top_count() extends Component {
+ val io = new Bundle {
+ val SW = in Bits(10 bits)
+ val CLOCK_50 = in Bool()
+ val KEY = in Bits(4 bits)
+ val HEX0 = out Bits(7 bits)
+ val EXP = out Bits(8 bits)
+ val LEDR = out Bits(10 bits)
+ val LEDG = out Bits(4 bits)
+ }
+ // Remove io_ from the port names in generated vhdl code
+ noIoPrefix()
+
+ val clk = new Bool()
+ val rst_n = new Bool()
+ clk := io.CLOCK_50
+ rst_n := io.KEY(0)
+ val coreclockdomain = ClockDomain(clk, rst_n)
+ val coreArea = new ClockingArea(coreclockdomain) {
+ val counter = new counter()
+ counter.io.en_i := io.KEY(1)
+
+ io.LEDR := io.SW
+ io.EXP(7 downto 4) := counter.io.cnt_o.asBits
+ io.EXP(3) := io.KEY(1)
+ io.EXP(2) := False
+ io.EXP(1) := rst_n
+ io.EXP(0) := clk
+
+ io.LEDG := io.KEY
+ io.HEX0 := "0000000"
+ }
+}
+
+// The following defines the vhdl and verilog code generation
+object genverilog extends App {
+ Config.spinal.generateVerilog(top_count())
+}
+
+object genvhdl extends App {
+ Config.spinal.generateVhdl(top_count())
+}