Skip to content

Commit 11420c8

Browse files
committed
feat: first commit
1 parent 0c36970 commit 11420c8

File tree

9 files changed

+108
-152
lines changed

9 files changed

+108
-152
lines changed

.commitlintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
extends: ["@commitlint/config-conventional"]
3+
}

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,13 @@ target/
320320
lib_managed/
321321
src_managed/
322322
project/boot/
323+
project/project
323324
project/plugins/project/
324325

325326
# Scala-IDE specific
326327
.scala_dependencies
327328
.worksheet
329+
.bloop
328330
### Java template
329331
*.class
330332

@@ -339,3 +341,31 @@ project/plugins/project/
339341
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
340342
hs_err_pid*
341343

344+
345+
# Metals
346+
.metals
347+
project/metals.sbt
348+
349+
# Eclipse
350+
bin/
351+
.classpath
352+
.project
353+
.settings
354+
.cache-main
355+
356+
#User
357+
/*.vhd
358+
/*.v
359+
*.cf
360+
*.json
361+
*.vcd
362+
!tester/src/test/resources/*.vhd
363+
364+
gen/
365+
simWorkspace/
366+
tmp/
367+
null
368+
369+
book
370+
.DS_Store
371+
.DS_St

.mill-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-toml
9+
- id: check-added-large-files
10+
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
11+
rev: v9.16.0
12+
hooks:
13+
- id: commitlint
14+
stages: [commit-msg]
15+
additional_dependencies: ['@commitlint/config-conventional']
16+
- repo: local
17+
hooks:
18+
- id: scalafmt
19+
name: Run Scalafmt
20+
description: Formats Scala code using Scalafmt
21+
entry: scalafmt
22+
language: system
23+
types: [scala]

.scalafmt.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "3.7.15"
2+
runner.dialect = scala213

README.md

Lines changed: 4 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,7 @@
1-
Chisel Project Template
2-
=======================
1+
# Introduction
32

4-
You've done the [Chisel Bootcamp](https://github.com/freechipsproject/chisel-bootcamp), and now you
5-
are ready to start your own Chisel project. The following procedure should get you started
6-
with a clean running [Chisel3](https://www.chisel-lang.org/) project.
3+
This is a demo project using [Chisel](https://github.com/chipsalliance/chisel). It begins with the [Chisel template](https://github.com/chipsalliance/chisel-template) and includes additional **pre-commit** configuration.
74

8-
## Make your own Chisel3 project
5+
I have included several practice solutions in the `src/main/scala/hdlbits` folder. The generated simulation files and Verilog files will be placed in the `gen` and `simWorkspace` folders.
96

10-
### Dependencies
11-
12-
#### JDK 8 or newer
13-
14-
We recommend LTS releases Java 8 and Java 11. You can install the JDK as your operating system recommends, or use the prebuilt binaries from [AdoptOpenJDK](https://adoptopenjdk.net/).
15-
16-
#### SBT or mill
17-
18-
SBT is the most common build tool in the Scala community. You can download it [here](https://www.scala-sbt.org/download.html).
19-
mill is another Scala/Java build tool without obscure DSL like SBT. You can download it [here](https://github.com/com-lihaoyi/mill/releases)
20-
21-
#### Verilator
22-
23-
The test with `svsim` needs Verilator installed.
24-
See Verilator installation instructions [here](https://verilator.org/guide/latest/install.html).
25-
26-
### How to get started
27-
28-
#### Create a repository from the template
29-
30-
This repository is a Github template. You can create your own repository from it by clicking the green `Use this template` in the top right.
31-
Please leave `Include all branches` **unchecked**; checking it will pollute the history of your new repository.
32-
For more information, see ["Creating a repository from a template"](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template).
33-
34-
#### Wait for the template cleanup workflow to complete
35-
36-
After using the template to create your own blank project, please wait a minute or two for the `Template cleanup` workflow to run which will removes some template-specific stuff from the repository (like the LICENSE).
37-
Refresh the repository page in your browser until you see a 2nd commit by `actions-user` titled `Template cleanup`.
38-
39-
40-
#### Clone your repository
41-
42-
Once you have created a repository from this template and the `Template cleanup` workflow has completed, you can click the green button to get a link for cloning your repository.
43-
Note that it is easiest to push to a repository if you set up SSH with Github, please see the [related documentation](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/connecting-to-github-with-ssh). SSH is required for pushing to a Github repository when using two-factor authentication.
44-
45-
```sh
46-
git clone git@github.com:ttboma/chisel-hdlbits.git
47-
cd chisel-hdlbits
48-
```
49-
50-
#### Set project organization and name in build.sbt
51-
52-
The cleanup workflow will have attempted to provide sensible defaults for `ThisBuild / organization` and `name` in the `build.sbt`.
53-
Feel free to use your text editor of choice to change them as you see fit.
54-
55-
#### Clean up the README.md file
56-
57-
Again, use you editor of choice to make the README specific to your project.
58-
59-
#### Add a LICENSE file
60-
61-
It is important to have a LICENSE for open source (or closed source) code.
62-
This template repository has the Unlicense in order to allow users to add any license they want to derivative code.
63-
The Unlicense is stripped when creating a repository from this template so that users do not accidentally unlicense their own work.
64-
65-
For more information about a license, check out the [Github Docs](https://docs.github.com/en/free-pro-team@latest/github/building-a-strong-community/adding-a-license-to-a-repository).
66-
67-
#### Commit your changes
68-
```sh
69-
git commit -m 'Starting chisel-hdlbits'
70-
git push origin main
71-
```
72-
73-
### Did it work?
74-
75-
You should now have a working Chisel3 project.
76-
77-
You can run the included test with:
78-
```sh
79-
sbt test
80-
```
81-
82-
Alternatively, if you use Mill:
83-
```sh
84-
mill chisel-hdlbits.test
85-
```
86-
87-
You should see a whole bunch of output that ends with something like the following lines
88-
```
89-
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
90-
[info] All tests passed.
91-
[success] Total time: 5 s, completed Dec 16, 2020 12:18:44 PM
92-
```
93-
If you see the above then...
94-
95-
### It worked!
96-
97-
You are ready to go. We have a few recommended practices and things to do.
98-
99-
* Use packages and following conventions for [structure](https://www.scala-sbt.org/1.x/docs/Directories.html) and [naming](http://docs.scala-lang.org/style/naming-conventions.html)
100-
* Package names should be clearly reflected in the testing hierarchy
101-
* Build tests for all your work
102-
* Read more about testing in SBT in the [SBT docs](https://www.scala-sbt.org/1.x/docs/Testing.html)
103-
* This template includes a [test dependency](https://www.scala-sbt.org/1.x/docs/Library-Dependencies.html#Per-configuration+dependencies) on [ScalaTest](https://www.scalatest.org/). This, coupled with `svsim` (included with Chisel) and `verilator`, are a starting point for testing Chisel generators.
104-
* You can remove this dependency in the build.sbt file if you want to
105-
* Change the name of your project in the build.sbt file
106-
* Change your README.md
107-
108-
## Problems? Questions?
109-
110-
Check out the [Chisel Users Community](https://www.chisel-lang.org/community.html) page for links to get in contact!
7+
Please note that these solutions are not necessarily optimal, but rather intended to help you gradually work through the SpinalHDL language.

build.sc

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/main/scala/gcd/GCD.scala

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import chisel3._
66
// _root_ disambiguates from package chisel3.util.circt if user imports chisel3.util._
77
import _root_.circt.stage.ChiselStage
88

9-
/**
10-
* Compute GCD using subtraction method.
11-
* Subtracts the smaller from the larger until register y is zero.
12-
* value in register x is then the GCD
9+
/** Compute GCD using subtraction method. Subtracts the smaller from the larger
10+
* until register y is zero. value in register x is then the GCD
1311
*/
1412
class GCD extends Module {
1513
val io = IO(new Bundle {
16-
val value1 = Input(UInt(16.W))
17-
val value2 = Input(UInt(16.W))
14+
val value1 = Input(UInt(16.W))
15+
val value2 = Input(UInt(16.W))
1816
val loadingValues = Input(Bool())
19-
val outputGCD = Output(UInt(16.W))
20-
val outputValid = Output(Bool())
17+
val outputGCD = Output(UInt(16.W))
18+
val outputValid = Output(Bool())
2119
})
2220

23-
val x = Reg(UInt())
24-
val y = Reg(UInt())
21+
val x = Reg(UInt())
22+
val y = Reg(UInt())
2523

2624
when(x > y) { x := x - y }
2725
.otherwise { y := y - x }
@@ -35,12 +33,12 @@ class GCD extends Module {
3533
io.outputValid := y === 0.U
3634
}
3735

38-
/**
39-
* Generate Verilog sources and save it in file GCD.v
40-
*/
36+
/** Generate Verilog sources and save it in file GCD.v
37+
*/
4138
object GCD extends App {
4239
ChiselStage.emitSystemVerilogFile(
4340
new GCD,
44-
firtoolOpts = Array("-disable-all-randomization", "-strip-debug-info")
41+
firtoolOpts = Array("-disable-all-randomization", "-strip-debug-info"),
42+
args = Array("--target-dir", "gen/gcd")
4543
)
4644
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package hdlbits.verilog_language
2+
3+
import chisel3._
4+
5+
// _root_ disambiguates from package chisel3.util.circt if user imports chisel3.util._
6+
import _root_.circt.stage.ChiselStage
7+
8+
// https://hdlbits.01xz.net/wiki/7458
9+
case class HdlBits7458() extends Module {
10+
val p1a = IO(Input(Bool()))
11+
val p1b = IO(Input(Bool()))
12+
val p1c = IO(Input(Bool()))
13+
val p1d = IO(Input(Bool()))
14+
val p1e = IO(Input(Bool()))
15+
val p1f = IO(Input(Bool()))
16+
val p1y = IO(Output(Bool()))
17+
val p2a = IO(Input(Bool()))
18+
val p2b = IO(Input(Bool()))
19+
val p2c = IO(Input(Bool()))
20+
val p2d = IO(Input(Bool()))
21+
val p2y = IO(Output(Bool()))
22+
23+
p1y := (p1a & p1c & p1b) | (p1f & p1e & p1d)
24+
p2y := (p2a & p2b) | (p2c & p2d)
25+
}
26+
27+
// Generate Verilog sources and save it in file HdlBits7458.sv
28+
object HdlBits7458 extends App {
29+
ChiselStage.emitSystemVerilogFile(
30+
HdlBits7458(),
31+
firtoolOpts = Array("-disable-all-randomization", "-strip-debug-info"),
32+
args = Array("--target-dir", "gen/hdlbits/verilog_language")
33+
)
34+
}

0 commit comments

Comments
 (0)