From 64c599867ad532a815cef3df87777deac3211683 Mon Sep 17 00:00:00 2001 From: Andreas Wallner Date: Sat, 9 Dec 2023 13:42:22 +0100 Subject: [PATCH 1/3] Use standard SBT structure While we can easily change the source folder there is no such property for the test folder. It raises questions and the custom folder structure is IMO not worth it (deviating from normal sbt documentation like https://www.scala-sbt.org/1.x/docs/Directories.html) --- .gitignore | 8 +++-- build.sbt | 3 +- build.sc | 3 -- hw/verilog/.gitignore => gen/.keep | 0 hw/gen/.gitignore | 1 - hw/spinal/projectname/MyTopLevelSim.scala | 31 ---------------- .../main/scala}/projectname/Config.scala | 2 +- .../main/scala}/projectname/MyTopLevel.scala | 0 .../scala}/projectname/MyTopLevelFormal.scala | 0 .../scala/projectname/MyTopLevelSim.scala | 35 +++++++++++++++++++ .../main/scala/projectname/verilog/.keep | 0 src/main/scala/projectname/vhdl/.keep | 0 12 files changed, 42 insertions(+), 41 deletions(-) rename hw/verilog/.gitignore => gen/.keep (100%) delete mode 100644 hw/gen/.gitignore delete mode 100644 hw/spinal/projectname/MyTopLevelSim.scala rename {hw/spinal => src/main/scala}/projectname/Config.scala (90%) rename {hw/spinal => src/main/scala}/projectname/MyTopLevel.scala (100%) rename {hw/spinal => src/main/scala}/projectname/MyTopLevelFormal.scala (100%) create mode 100644 src/main/scala/projectname/MyTopLevelSim.scala rename hw/vhdl/.gitignore => src/main/scala/projectname/verilog/.keep (100%) create mode 100644 src/main/scala/projectname/vhdl/.keep diff --git a/.gitignore b/.gitignore index 8f0efb0..3532fc6 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ project/boot/ project/project project/plugins/project/ -# Scala-IDE specific +# IntelliJ specific .scala_dependencies .worksheet .bloop @@ -22,8 +22,10 @@ project/plugins/project/ .idea out -# Metals +# VSCode / Metals +.vscode .metals +.bsp project/metals.sbt # Eclipse @@ -41,7 +43,7 @@ bin/ *.vcd !tester/src/test/resources/*.vhd - +gen/ simWorkspace/ tmp/ null diff --git a/build.sbt b/build.sbt index f6b3739..6c0fc8d 100644 --- a/build.sbt +++ b/build.sbt @@ -9,8 +9,7 @@ val spinalIdslPlugin = compilerPlugin("com.github.spinalhdl" %% "spinalhdl-idsl- lazy val projectname = (project in file(".")) .settings( - Compile / scalaSource := baseDirectory.value / "hw" / "spinal", - libraryDependencies ++= Seq(spinalCore, spinalLib, spinalIdslPlugin) + libraryDependencies ++= Seq(spinalCore, spinalLib, spinalIdslPlugin, "org.scalatest"%%"scalatest"%"3.1.1") ) fork := true diff --git a/build.sc b/build.sc index 40680c1..a4e41eb 100644 --- a/build.sc +++ b/build.sc @@ -5,9 +5,6 @@ val spinalVersion = "1.9.0" object projectname extends SbtModule { def scalaVersion = "2.12.16" override def millSourcePath = os.pwd - def sources = T.sources( - millSourcePath / "hw" / "spinal" - ) def ivyDeps = Agg( ivy"com.github.spinalhdl::spinalhdl-core:$spinalVersion", ivy"com.github.spinalhdl::spinalhdl-lib:$spinalVersion" diff --git a/hw/verilog/.gitignore b/gen/.keep similarity index 100% rename from hw/verilog/.gitignore rename to gen/.keep diff --git a/hw/gen/.gitignore b/hw/gen/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/hw/gen/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/hw/spinal/projectname/MyTopLevelSim.scala b/hw/spinal/projectname/MyTopLevelSim.scala deleted file mode 100644 index d6cbb42..0000000 --- a/hw/spinal/projectname/MyTopLevelSim.scala +++ /dev/null @@ -1,31 +0,0 @@ -package projectname - -import spinal.core._ -import spinal.core.sim._ - -object MyTopLevelSim extends App { - Config.sim.compile(MyTopLevel()).doSim { 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() - - // Wait a rising edge on the clock - dut.clockDomain.waitRisingEdge() - - // 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 - } - } - } -} diff --git a/hw/spinal/projectname/Config.scala b/src/main/scala/projectname/Config.scala similarity index 90% rename from hw/spinal/projectname/Config.scala rename to src/main/scala/projectname/Config.scala index f3a2e3e..721f0a0 100644 --- a/hw/spinal/projectname/Config.scala +++ b/src/main/scala/projectname/Config.scala @@ -5,7 +5,7 @@ import spinal.core.sim._ object Config { def spinal = SpinalConfig( - targetDirectory = "hw/gen", + targetDirectory = "gen", defaultConfigForClockDomains = ClockDomainConfig( resetActiveLevel = HIGH ), diff --git a/hw/spinal/projectname/MyTopLevel.scala b/src/main/scala/projectname/MyTopLevel.scala similarity index 100% rename from hw/spinal/projectname/MyTopLevel.scala rename to src/main/scala/projectname/MyTopLevel.scala diff --git a/hw/spinal/projectname/MyTopLevelFormal.scala b/src/main/scala/projectname/MyTopLevelFormal.scala similarity index 100% rename from hw/spinal/projectname/MyTopLevelFormal.scala rename to src/main/scala/projectname/MyTopLevelFormal.scala diff --git a/src/main/scala/projectname/MyTopLevelSim.scala b/src/main/scala/projectname/MyTopLevelSim.scala new file mode 100644 index 0000000..b9d2278 --- /dev/null +++ b/src/main/scala/projectname/MyTopLevelSim.scala @@ -0,0 +1,35 @@ +package projectname + +import spinal.core._ +import spinal.core.sim._ + +import org.scalatest.funsuite.AnyFunSuite + +class MyTopLevelSim extends AnyFunSuite { + test("blub") { + Config.sim.compile(MyTopLevel()).doSim { 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() + + // Wait a rising edge on the clock + dut.clockDomain.waitRisingEdge() + + // 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 + } + } + } + } +} diff --git a/hw/vhdl/.gitignore b/src/main/scala/projectname/verilog/.keep similarity index 100% rename from hw/vhdl/.gitignore rename to src/main/scala/projectname/verilog/.keep diff --git a/src/main/scala/projectname/vhdl/.keep b/src/main/scala/projectname/vhdl/.keep new file mode 100644 index 0000000..e69de29 From cf459ecb4898fcbe95e620abaa44f841c2595597 Mon Sep 17 00:00:00 2001 From: Andreas Wallner Date: Sat, 9 Dec 2023 13:49:18 +0100 Subject: [PATCH 2/3] Update mill SpinalHDL version --- build.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sc b/build.sc index a4e41eb..8693cf6 100644 --- a/build.sc +++ b/build.sc @@ -1,6 +1,6 @@ import mill._, scalalib._ -val spinalVersion = "1.9.0" +val spinalVersion = "1.9.4" object projectname extends SbtModule { def scalaVersion = "2.12.16" From e934fee99ecc2537839ea753867a2d19b859097c Mon Sep 17 00:00:00 2001 From: Andreas Wallner Date: Sat, 9 Dec 2023 14:10:15 +0100 Subject: [PATCH 3/3] Adapt README to standard folder structure --- README.md | 38 ++++++++++++++++++-------------------- build.sbt | 4 ++-- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 4467457..183e1b5 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ sbt "runMain projectname.MyTopLevelVhdl" sbt "runMain projectname.MyTopLevelSim" ``` -* The example hardware description is into `hw/spinal/projectname/MyTopLevel.scala` -* The testbench is into `hw/spinal/projectname/MyTopLevelSim.scala` +* The example hardware description is in `src/main/scala/projectname/MyTopLevel.scala` +* The testbench is in `src/main/scala/spinal/projectname/MyTopLevelSim.scala` When you really start working with SpinalHDL, it is recommended (both for comfort and efficiency) to use an IDE, see the [Getting started](https://spinalhdl.github.io/SpinalDoc-RTD/master/SpinalHDL/Getting%20Started/index.html). @@ -38,34 +38,32 @@ When you really start working with SpinalHDL, it is recommended (both for comfor ### Change project name -You might want to change the project name, which is currently `projectname`. To do so (let's say your actual project name is `myproject`; it must be all lowercase with no separators): +You might want to change the project name, which is currently `projectname`. To do so (let's say your actual project name is `myproject`): -* Update `build.sbt` and/or `build.sc` by replacing `projectname` by the name of your project `myproject` (1 occurrence in each file). The better is to replace in both (it will always work), but in some contexts you can keep only one of these two files: +* Update `build.sbt` and/or `build.sc` by replacing `projectname` by the name of your project `myproject`. The better is to replace in both (it will always work), but in some contexts you can keep only one of these two files: * If you are sure all people only use `sbt`, you can replace only in `build.sbt` and remove `build.sc` * If you are sure all people only use `mill`, you can replace only in `build.sc` and remove `build.sbt` * Replace in both files for open-source project. -* Put all your scala files into `hw/spinal/myproject/` (remove the unused `hw/spinal/projectname/` folder) -* Start all your scala files with `package myproject` - - -### Change project structure - -You can change the project structure as you want. The only restrictions (from Scala environment) are (let's say your actual project name is `myproject`): - -* you must have a `myproject` folder and files in it must start with `package myproject` -* if you have a file in a subfolder `myproject/somepackage/MyElement.scala` it must start with `package myproject.somepackage`. -* `sbt` and `mill` must be run right in the folder containing their configurations (recommended to not move these files) - -Once the project structure is modified, update configurations: - -* In `build.sbt` and/or `build.sc` (see above) replace `/ "hw" / "spinal"` by the new path to the folder containing the `myproject` folder. -* In the spinal configuration file (if you kept it, by default it is in `projectname/Config.scala`) change the path in `targetDirectory = "hw/gen"` to the directory where you want generated files to be written. If you don't use a config or if it doesn't contain this element, generated files will be written in the root directory. +* Rename the `src/main/scala/spinal/projectname` folder to `src/main/scala/spinal/myproject` +* Replace `package projectname` all scala files with `package myproject` +If you want/need separators in the project name then a `.` can be used as a separator, but the folder structure/build files need to be adapted accordingly. +You'll need to follow the rules for Java package names / structure. ### Update this README Of course you can replace/modify this file to help people with your own project! +### Reinitialize repository + +There is no need to keep the git history of the template. The easiest is to remove the `.git` folder and initialize a clean repository: + +```sh +rm -rf .git +git init +git add . +git commit -m "Initial project setup" +``` ## Mill Support (Experimental) diff --git a/build.sbt b/build.sbt index 6c0fc8d..2f2354a 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ -ThisBuild / version := "1.0" +ThisBuild / version := "0.1" ThisBuild / scalaVersion := "2.12.18" -ThisBuild / organization := "org.example" +ThisBuild / organization := "projectname" val spinalVersion = "1.9.4" val spinalCore = "com.github.spinalhdl" %% "spinalhdl-core" % spinalVersion