Spinal HDL
git clone https://github.com/SpinalHDL/SpinalTemplateSbt
SpinalTemplateSbt
package mylib
import spinal.core._
import spinal.lib._
import scala.util.Random
//Hardware definition
class MyTopLevel extends Component {
val io = new Bundle {
val cond0 = in Bool
val cond1 = in Bool
val flag = out Bool
val state = out UInt(8 bits)
}
val counter = Reg(UInt(8 bits)) init(0)
when(io.cond0){
counter := counter + 1
}
io.state := counter
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)
}
}
sbt "runMain mylib.MyTopLevelVerilog"
// Generator : SpinalHDL v1.4.0 git head : ecb5a80b713566f417ea3ea061f9969e73770a7f
// Date : 10/08/2020, 00:04:58
// Component : MyTopLevel
module MyTopLevel (
input io_cond0,
input io_cond1,
output io_flag,
output [7:0] io_state,
input clk,
input reset
);
reg [7:0] counter;
assign io_state = counter;
assign io_flag = ((counter == 8'h0) || io_cond1);
always @ (posedge clk or posedge reset) begin
if (reset) begin
counter <= 8'h0;
end else begin
if(io_cond0)begin
counter <= (counter + 8'h01);
end
end
end
endmodule
vhdl
sbt run
Multiple main classes detected, select one to run:
[1] mylib.MyTopLevelSim
[2] mylib.MyTopLevelVerilog
[3] mylib.MyTopLevelVerilogWithCustomConfigss 0s
[4] mylib.MyTopLevelVhdl
Select 4
sdk java
https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Linux.html
# https://sdkman.io/install
curl -s "https://get.sdkman.io" | bash
export SDKMAN_DIR="/usr/local/sdkman" && curl -s "https://get.sdkman.io" | bash
$ sdk list java
$ sdk install java 11.0.4.hs-adpt
$ sdk install sbt
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk version
% sdk version
SDKMAN 5.8.3+506
manual install sbt
download 1.3.3 version
../sbt-1.3.3/bin/sbt --version
sbt version in this project: 1.3.3
sbt script version: 1.3.3
Why does sbt report “Error: Could not retrieve sbt 0.13.11”? https://stackoverflow.com/questions/37613421/why-does-sbt-report-error-could-not-retrieve-sbt-0-13-11 ~/.sbt/repositories https://spinalhdl.github.io/SpinalDoc-RTD/SpinalHDL/Getting%20Started/getting_started.html#the-sbt-way https://www.scala-sbt.org/download.html
.sbt
cd ~ ; rm -rf .sbt; cd mkdir .sbt
sbt run
[info] [launcher] getting org.scala-sbt sbt 1.3.3 (this may take some time)...
misc
https://spinalhdl.github.io/SpinalDoc-RTD/SpinalHDL/Getting%20Started/getting_started.html https://github.com/SpinalHDL/SpinalTemplateSbt
Just one important note, you need a java JDK >= 8
//generate the Verilog of your design sbt "runMain mylib.MyTopLevelVerilog"
https://github.com/jijingg/Spinal-bootcamp