当前位置:网站首页>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 .
边栏推荐
- MySQL8版本免安装步骤教程
- Introduction to reverse debugging PE structure resource table 07/07
- MongoDB常用28条查询语句(转)
- Unittest中的TestSuite和TestRunner
- 吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
- 使用默认路由作为指向Internet的路由
- 30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
- .Net之延迟队列
- Byte interview algorithm question
- gorm 之数据插入(转)
猜你喜欢

1200. Minimum absolute difference

Source code compilation and installation of MySQL

华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东

吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符

. Net delay queue
![[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect](/img/96/379d1692f9d3c05a7af2e938cbc5d7.png)
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect

Go 语言入门很简单:Go 实现凯撒密码

Introduction to reverse debugging PE structure resource table 07/07
![[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp](/img/eb/11e5da1c5e897c5f6a18d49125925f.png)
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp

硬件基础知识-二极管基础
随机推荐
1200. 最小绝对差
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
[C question set] of VII
Install Trinity and solve error reporting
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
读取 Excel 表数据
Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua
舔狗舔到最后一无所有(状态机)
近日小结(非技术文)
Understanding and difference between viewbinding and databinding
Node の MongoDB安装
程序员转方向
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
MySQL8版本免安装步骤教程
【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
【R语言数据科学】:交叉验证再回首
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法