Chisel是基于scala开发的,而scala是基于java的,因此我们先安装java再安装scala。
java
sudo apt install openjdk-11-jre-headless
javac
sudo apt install openjdk-11-jdk-headless
完成后查看版本以检查是否成功安装:java --version
javac --version
出现这样的版本号就说明java已经安装成功。
openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.21.04)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.21.04, mixed mode)
javac 11.0.13
到这个网址下载合适版本的scala,不建议使用scala3, 推荐2.12.x
下载.tgz文件,将其解压后移动到/usr/local/share
目录下
添加环境变量,在家目录下.bashrc
文件的最后添加:
export PATH="$PATH:/usr/local/share/scala-2.12.12/bin"
这句的含义是在PATH变量中加上你刚刚安装的scala内bin文件夹的目录,其中的scala-2.12.12取决于你下载的scala版本
最后source一下使其更新生效:
source ~/.bashrc
在任意目录下输入scala
,若出现如下的prompt,则说明scala安装成功。
Welcome to Scala 2.12.12 (OpenJDK 64-Bit Server VM, Java 11.0.13).
Type in expressions for evaluation. Or try :help.
scala>
scala> 1+1
res0: Int = 2
echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list
echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add
sudo apt-get update
sudo apt-get install sbt
vim ~/.bashrc
在最后添加:export SBT_HOME="安装路径/sbt"
export PATH="$SBT_HOME:$PATH"
source ~/.bashrc
更新。sbt sbtVersion
,若出现版本号说明安装成功。~/.sbt
,创建文件repositories,内容为[repositories]
local
huaweicloud-maven: https://repo.huaweicloud.com/repository/maven/
maven-central: https://repo1.maven.org/maven2/
huaweicloud-ivy: https://repo.huaweicloud.com/repository/ivy/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
git clone https://github.com/schoeberl/chisel-empty.git
build.sbt
Makefile
README.md
src/
quartus/
build.sbt 规定了scala版本,导入的包等:
scalaVersion := "2.12.12"
scalacOptions ++= Seq(
"-feature",
"-language:reflectiveCalls",
)
resolvers ++= Seq(
Resolver.sonatypeRepo("releases")
)
// Chisel 3.5
addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % "3.5.0" cross CrossVersion.full)
libraryDependencies += "edu.berkeley.cs" %% "chisel3" % "3.5.0"
libraryDependencies += "edu.berkeley.cs" %% "chiseltest" % "0.5.0"
Makefile 并不是必须的,里面实际上是sbt的命令,对sbt命令的进一步了解可以参考这篇博客。
quartus/ 与目前的关系不大,可以暂时不管。
src 用来存放代码。该模板中自带一个简单加法器的chisel实现,存放在src下。文件结构如下,这也是一般sbt工程文件的规范:
src/
main/
scala/
test/
scala/
make
或者实际上是sbt run
[info] Updated file /home/ckq/Documents/codes/CHISEL/chisel_proj/chisel-empty/project/build.properties: set sbt.version to 1.6.2
[info] welcome to sbt 1.6.2 (Ubuntu Java 11.0.13)
[info] loading project definition from /home/ckq/Documents/codes/CHISEL/chisel_proj/chisel-empty/project
[info] loading settings for project chisel-empty from build.sbt ...
[info] set current project to chisel-empty (in build file:/home/ckq/Documents/codes/CHISEL/chisel_proj/chisel-empty/)
[info] compiling 1 Scala source to /home/ckq/Documents/codes/CHISEL/chisel_proj/chisel-empty/target/scala-2.12/classes ..
[info] running empty.AddMain
Generating the adder hardware
[success] Total time: 7 s, completed May 2, 2022, 5:00:07 PM
也可以输入sbt test
跑一下test中的测试代码:
[info] AddTester:
[info] Add
[info] - should work
[info] Run completed in 2 seconds, 540 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 7 s, completed May 2, 2022, 5:02:39 PM
最后推荐一些入门chisel的学习资源:
本人也是小白一枚,难免整理不周,如有疑问可以进一步参考以下博客/专栏:
初学Chisel语言,看这篇就够了:最方便简洁的入门资料整理
详细介绍如何在linux中配置chisel环境
Ubuntu18安装Scala
SBT简介
sbt的安装及其配置
SBT无痛入门指南