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:
Côme ALLART
2022-11-16 18:32:24 +01:00
parent 8e8b22f6ec
commit ed51a92116
5 changed files with 59 additions and 83 deletions

3
.gitignore vendored
View File

@@ -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/

View File

@@ -1,67 +1,22 @@
/*
* 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 {
val io = new Bundle { val io = new Bundle {
val cond0 = in Bool() val cond0 = in Bool ()
val cond1 = in Bool() val cond1 = in Bool ()
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)
when(io.cond0){ val counter = Reg(UInt(8 bits)) init 0
when(io.cond0) {
counter := counter + 1 counter := counter + 1
} }
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)
}
}

View File

@@ -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
@@ -20,5 +21,4 @@ object MyTopLevelFormal {
// Check the state initial value and increment // Check the state initial value and increment
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))
}) })
}
} }

View 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)
}

View File

@@ -1,37 +1,30 @@
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 {
SimConfig.withWave.doSim(new MyTopLevel) { dut =>
// Fork a process to generate the reset and the clock on the dut
dut.clockDomain.forkStimulus(period = 10)
var modelState = 0
for (idx <- 0 to 99) {
// Drive the dut inputs with random values
dut.io.cond0.randomize()
dut.io.cond1.randomize()
//MyTopLevel's testbench // Wait a rising edge on the clock
object MyTopLevelSim { dut.clockDomain.waitRisingEdge()
def main(args: Array[String]) {
SimConfig.withWave.doSim(new MyTopLevel){dut =>
//Fork a process to generate the reset and the clock on the dut
dut.clockDomain.forkStimulus(period = 10)
var modelState = 0 // Check that the dut values match with the reference model ones
for(idx <- 0 to 99){ val modelFlag = modelState == 0 || dut.io.cond1.toBoolean
//Drive the dut inputs with random values assert(dut.io.state.toInt == modelState)
dut.io.cond0 #= Random.nextBoolean() assert(dut.io.flag.toBoolean == modelFlag)
dut.io.cond1 #= Random.nextBoolean()
//Wait a rising edge on the clock // Update the reference model value
dut.clockDomain.waitRisingEdge() if (dut.io.cond0.toBoolean) {
modelState = (modelState + 1) & 0xff
//Check that the dut values match with the reference model ones
val modelFlag = modelState == 0 || dut.io.cond1.toBoolean
assert(dut.io.state.toInt == modelState)
assert(dut.io.flag.toBoolean == modelFlag)
//Update the reference model value
if(dut.io.cond0.toBoolean) {
modelState = (modelState + 1) & 0xFF
}
} }
} }
} }