aboutsummaryrefslogtreecommitdiff
path: root/top_count/src/top_count.scala
blob: ff2e54a6900130e56b42ad5a9eead959a5fa1e1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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())
}