mirror of
https://github.com/SpinalHDL/SpinalTemplateSbt.git
synced 2025-10-24 16:38:43 +08:00
big update
- remove not supported anymore procedural syntax for main functions - use App instead of main - auto format - move comments to have more user-friendly access to "run" and "debug" button for Apps - move generators to dedicated new file
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,17 +11,20 @@ target
|
|||||||
lib_managed/
|
lib_managed/
|
||||||
src_managed/
|
src_managed/
|
||||||
project/boot/
|
project/boot/
|
||||||
|
project/project
|
||||||
project/plugins/project/
|
project/plugins/project/
|
||||||
|
|
||||||
# Scala-IDE specific
|
# Scala-IDE specific
|
||||||
.scala_dependencies
|
.scala_dependencies
|
||||||
.worksheet
|
.worksheet
|
||||||
|
.bloop
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
out
|
out
|
||||||
|
|
||||||
# Metals
|
# Metals
|
||||||
.metals
|
.metals
|
||||||
|
project/metals.sbt
|
||||||
|
|
||||||
# Eclipse
|
# Eclipse
|
||||||
bin/
|
bin/
|
||||||
|
|||||||
@@ -1,27 +1,6 @@
|
|||||||
/*
|
|
||||||
* SpinalHDL
|
|
||||||
* Copyright (c) Dolu, All rights reserved.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 3.0 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package mylib
|
package mylib
|
||||||
|
|
||||||
import spinal.core._
|
import spinal.core._
|
||||||
import spinal.lib._
|
|
||||||
|
|
||||||
import scala.util.Random
|
|
||||||
|
|
||||||
// Hardware definition
|
// Hardware definition
|
||||||
class MyTopLevel extends Component {
|
class MyTopLevel extends Component {
|
||||||
@@ -31,7 +10,8 @@ class MyTopLevel extends Component {
|
|||||||
val flag = out Bool ()
|
val flag = out Bool ()
|
||||||
val state = out UInt (8 bits)
|
val state = out UInt (8 bits)
|
||||||
}
|
}
|
||||||
val counter = Reg(UInt(8 bits)) init(0)
|
|
||||||
|
val counter = Reg(UInt(8 bits)) init 0
|
||||||
|
|
||||||
when(io.cond0) {
|
when(io.cond0) {
|
||||||
counter := counter + 1
|
counter := counter + 1
|
||||||
@@ -40,28 +20,3 @@ class MyTopLevel extends Component {
|
|||||||
io.state := counter
|
io.state := counter
|
||||||
io.flag := (counter === 0) | io.cond1
|
io.flag := (counter === 0) | io.cond1
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generate the MyTopLevel's Verilog
|
|
||||||
object MyTopLevelVerilog {
|
|
||||||
def main(args: Array[String]) {
|
|
||||||
SpinalVerilog(new MyTopLevel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Generate the MyTopLevel's VHDL
|
|
||||||
object MyTopLevelVhdl {
|
|
||||||
def main(args: Array[String]) {
|
|
||||||
SpinalVhdl(new MyTopLevel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Define a custom SpinalHDL configuration with synchronous reset instead of the default asynchronous one. This configuration can be resued everywhere
|
|
||||||
object MySpinalConfig extends SpinalConfig(defaultConfigForClockDomains = ClockDomainConfig(resetKind = SYNC))
|
|
||||||
|
|
||||||
//Generate the MyTopLevel's Verilog using the above custom configuration.
|
|
||||||
object MyTopLevelVerilogWithCustomConfig {
|
|
||||||
def main(args: Array[String]) {
|
|
||||||
MySpinalConfig.generateVerilog(new MyTopLevel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,9 +5,10 @@ import spinal.core.formal._
|
|||||||
|
|
||||||
// You need SymbiYosys to be installed.
|
// You need SymbiYosys to be installed.
|
||||||
// See https://spinalhdl.github.io/SpinalDoc-RTD/master/SpinalHDL/Formal%20verification/index.html#installing-requirements
|
// See https://spinalhdl.github.io/SpinalDoc-RTD/master/SpinalHDL/Formal%20verification/index.html#installing-requirements
|
||||||
object MyTopLevelFormal {
|
object MyTopLevelFormal extends App {
|
||||||
def main(args: Array[String]) {
|
FormalConfig
|
||||||
FormalConfig.withBMC(10).doVerify(new Component {
|
.withBMC(10)
|
||||||
|
.doVerify(new Component {
|
||||||
val dut = FormalDut(new MyTopLevel)
|
val dut = FormalDut(new MyTopLevel)
|
||||||
|
|
||||||
// Ensure the formal test start with a reset
|
// Ensure the formal test start with a reset
|
||||||
@@ -21,4 +22,3 @@ object MyTopLevelFormal {
|
|||||||
assert(dut.io.state === past(dut.io.state + U(dut.io.cond0)).init(0))
|
assert(dut.io.state === past(dut.io.state + U(dut.io.cond0)).init(0))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
25
src/main/scala/mylib/MyTopLevelGen.scala
Normal file
25
src/main/scala/mylib/MyTopLevelGen.scala
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package mylib
|
||||||
|
|
||||||
|
import spinal.core._
|
||||||
|
|
||||||
|
object MyTopLevelVerilog extends App {
|
||||||
|
// Generate the MyTopLevel's Verilog
|
||||||
|
SpinalVerilog(new MyTopLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
object MyTopLevelVhdl extends App {
|
||||||
|
// Generate the MyTopLevel's VHDL
|
||||||
|
SpinalVhdl(new MyTopLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom SpinalHDL configuration with synchronous reset instead of the default asynchronous one
|
||||||
|
// This configuration can be resued everywhere
|
||||||
|
object MySpinalConfig
|
||||||
|
extends SpinalConfig(
|
||||||
|
defaultConfigForClockDomains = ClockDomainConfig(resetKind = SYNC)
|
||||||
|
)
|
||||||
|
|
||||||
|
object MyTopLevelVerilogWithCustomConfig extends App {
|
||||||
|
// Generate the MyTopLevel's Verilog using the above custom configuration.
|
||||||
|
MySpinalConfig.generateVerilog(new MyTopLevel)
|
||||||
|
}
|
||||||
@@ -1,15 +1,9 @@
|
|||||||
package mylib
|
package mylib
|
||||||
|
|
||||||
import spinal.core._
|
import spinal.core._
|
||||||
import spinal.sim._
|
|
||||||
import spinal.core.sim._
|
import spinal.core.sim._
|
||||||
|
|
||||||
import scala.util.Random
|
object MyTopLevelSim extends App {
|
||||||
|
|
||||||
|
|
||||||
//MyTopLevel's testbench
|
|
||||||
object MyTopLevelSim {
|
|
||||||
def main(args: Array[String]) {
|
|
||||||
SimConfig.withWave.doSim(new MyTopLevel) { dut =>
|
SimConfig.withWave.doSim(new MyTopLevel) { dut =>
|
||||||
// Fork a process to generate the reset and the clock on the dut
|
// Fork a process to generate the reset and the clock on the dut
|
||||||
dut.clockDomain.forkStimulus(period = 10)
|
dut.clockDomain.forkStimulus(period = 10)
|
||||||
@@ -17,8 +11,8 @@ object MyTopLevelSim {
|
|||||||
var modelState = 0
|
var modelState = 0
|
||||||
for (idx <- 0 to 99) {
|
for (idx <- 0 to 99) {
|
||||||
// Drive the dut inputs with random values
|
// Drive the dut inputs with random values
|
||||||
dut.io.cond0 #= Random.nextBoolean()
|
dut.io.cond0.randomize()
|
||||||
dut.io.cond1 #= Random.nextBoolean()
|
dut.io.cond1.randomize()
|
||||||
|
|
||||||
// Wait a rising edge on the clock
|
// Wait a rising edge on the clock
|
||||||
dut.clockDomain.waitRisingEdge()
|
dut.clockDomain.waitRisingEdge()
|
||||||
@@ -30,8 +24,7 @@ object MyTopLevelSim {
|
|||||||
|
|
||||||
// Update the reference model value
|
// Update the reference model value
|
||||||
if (dut.io.cond0.toBoolean) {
|
if (dut.io.cond0.toBoolean) {
|
||||||
modelState = (modelState + 1) & 0xFF
|
modelState = (modelState + 1) & 0xff
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user