当前位置:网站首页>Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
Understand chisel language thoroughly 10. Chisel project construction, operation and testing (II) -- Verilog code generation in chisel & chisel development process
2022-07-04 14:09:00 【github-3rr0r】
Chisel The project build 、 Run and test ( Two )——Chisel In the middle of Verilog Code &Chisel Development process
In the last article, we mentioned how to use sbt structure Chisel Project and run Chisel Code , But after all, it still runs on the computer . In practice , We wrote Chisel The code should eventually be integrated into FPGA or ASIC On , So we must put Chisel Translate to a hardware description language that an integrated tool can handle , such as Verilog. How to use it? Chisel Code generation Verilog What about code? ?Chisel What is the development process of ? Let's learn from this article .
Chisel Generate Verilog Code
Chisel It can generate and synthesize Verilog Code , The generation Verilog Just put your code in an application entry . This application portal is a Scala object , It's from App
Extended , As mentioned in the previous section , It will implicitly generate the main function when the program starts . There is only one line of code in this application entry , It creates a new Hello
object , And pass it to Chisel Of emitVerilog()
function , It will generate Hello
The module corresponds to Verilog file Hello.v
. The code is as follows :
object Hello extends App {
emitVerilog(new Hello())
}
But this call emitVerilog
The method of writing will put the generated file into the project root directory by default , Which is running sbt
Path to command . If you want to put the generated files in the specified folder , You need to emitVerilog()
Specify the options . The build options can be set to emitVerilog()
Second parameter of , The parameter type is an array of strings . The last article said Chisel The project directory structure mentioned , It is recommended to put the generated file into generated
Under the folder , The following code can realize this requirement :
object HelloOption extends App {
emitVerilog(new Hello(), Array("--target-dir", "generated"))
}
If we don't want to Verilog The code is output as a file , I just want to regard it as Scala If the string is output on the command line , Just use getVerilogString()
Function :
object HelloString extends App {
val s = getVerilogString(new Hello())
println(s)
}
This generation method is used in small Chisel It is easy to use in projects , For example, on this web page Led Examples of flashing lights Hello World - Scastie (scala-lang.org), use getVerilogString
Function outputs the corresponding Verilog Code .
And this one Scastie It's actually online Scala development environment , If there is no local environment, we can also use this online environment for simple Chisel Development , It can avoid the trouble of matching the environment .
Chisel Tool flow development process
Let's run a simple but complete build Verilog Example , The corresponding circuit is a direct four bit signed input connected to a four bit signed output :
package my.hello
import chisel3._
class ModuleSample extends Module {
val io = IO(new Bundle {
val in_a = Input(SInt(4.W))
val out_b = Output(SInt(4.W))
})
io.out_b := io.in_a
}
object MyModule extends App {
emitVerilog(new ModuleSample(), Array("--target-dir", "generated"))
}
But we can be surprised to see ,generated
Except for *.v
Of Verilog file , also *.fir
Document and *.anno.json
file :
That is, it is not only generated Verilog Code , Other files are also generated , When it comes to the reason, it involves Chisel Our tools are flowing .Chisel The tool flow of is shown in the figure below :
The digital circuit we write is actually Chisel Class , That's what this is Hello.scala
, The essence is Scala Source code . but Chisel The difference in Scala The reason is that it is not only used when compiling Scala The library of scala.lib
, Also used. Chisel The library of chisel3.lib
.
With Chisel Source code ,Scala The compiler of is based on Chisel、Scala Our library generates our code Java Class file Hello.class
, That is, bytecode file . Such documents can be found in the standard JVM(Java Virtual Machine,Java virtual machine ) Directly executed on .
use Chisel When the driver executes this bytecode file, it will generate FIRRTL file Hello.fir
. This FIRRTL Its full name is Flexible Intermediate Representation for RTL, namely RTL Variable intermediate representation of , Is the middle representation of a digital circuit .FIRRTL The compiler can perform some transformations on the circuit , yes Chisel A key bridge to other hardware description languages , If you want to understand higher order Chisel The content of is even Chisel Open source code to contribute , Then we need to study deeply FIRRTL 了 .
Down again Treadle It's a FIRRTL Interpreter , For circuit simulation . coordination Chisel Tester , It can be used for debugging and testing Chisel circuit . According to the output assertion information, we can get the test results .Treadle You can also generate waveform files , namely Hello.vcd
, This waveform file can be viewed with the waveform viewer , For example, you can GTKWare or Modelsim Wait and see .
go back to FIRRTL Compiler part ,Verilog Emitter It's also FIRRTL Transform one , It can be used Hello.fir
Generate integrable Verilog Code Hello.v
. Then we can use a circuit synthesis tool ( such as Intel Of Quartus,Xilinx Of Vivado Or something else ASIC Tools ) To integrate circuits . stay FPGA Design workflow , The integrated tool will generate FPGA Bitstreams are used to configure FPGA, namely Hello.bit
.
Conclusion
Now we have learned how to Chisel In the middle of Verilog Code , Also useful Chisel Have a basic understanding of the tool flow for development . Learned how to compile 、 How to run , Next, you have to learn how to test . We can't try and make mistakes every time we debug , For example, it is generated every time the code is modified FPGA Test the bit stream , In this way, we can't find the error , Second, it takes too long . So it has to be in Chisel Test at stage , This is true for small modules , For larger scale digital circuits, we have to do better testing . The following articles will talk about several Chisel How to use the testing framework , How to write the test code .
边栏推荐
- Read excel table data
- 学习项目是自己找的,成长机会是自己创造的
- 逆向调试入门-PE结构-资源表07/07
- 【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
- 舔狗舔到最后一无所有(状态机)
- 一次 Keepalived 高可用的事故,让我重学了一遍它
- 2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
- Huahao Zhongtian sprint Technology Innovation Board: perte annuelle de 280 millions de RMB, projet de collecte de fonds de 1,5 milliard de Beida Pharmaceutical est actionnaire
- Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
- 源码编译安装MySQL
猜你喜欢
1200. Minimum absolute difference
[R language data science]: cross validation and looking back
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
字节面试算法题
Haproxy high availability solution
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
Byte interview algorithm question
随机推荐
2022年山东省安全员C证考试题库及在线模拟考试
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
Node の MongoDB安装
How to choose a technology stack for web applications in 2022
Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
2022 practice questions and mock exams for the main principals of hazardous chemical business units
MySQL version 8 installation Free Tutorial
Fisher信息量检测对抗样本代码详解
Animation and transition effects
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
2022危险化学品经营单位主要负责人练习题及模拟考试
Source code compilation and installation of MySQL
近日小结(非技术文)
Unity shader learning (3) try to draw a circle
Unittest框架中引入TestFixture
吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
Unity Shader学习(三)试着绘制一个圆
舔狗舔到最后一无所有(状态机)
PHP log debugging
[R language data science]: cross validation and looking back