当前位置:网站首页>Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware
Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware
2022-07-04 14:08:00 【github-3rr0r】
Chisel Basics ( 5、 ... and )——Wire、Reg and IO, And how to understand Chisel Build hardware
The conclusion of the previous article mentioned ,UInt
、SInt
and Bits
All are Chisel type , They themselves do not directly represent hardware , Only by encapsulating them into Wire
、Reg
or IO
Will generate a circuit . This matter can be understood in this way , Digital logic circuits are made up of wires 、 Logic gate 、 Registers and input / output ( Including clock and reset signal ) And so on , The connection corresponds to Wire
, Logic gate corresponding operator , Registers correspond to Reg
, Input output correspondence IO
. So in Chisel How can they be used in ? How to understand Chisel Generation circuit ? Learn this article together .
Wire
、Reg
and IO
stay Chisel in ,Wire
Used to represent combinatorial logic ,Reg
Used to represent registers (D- Set of triggers ), and IO
Is used to represent the interface of a module ( For example, the pin of a specific integrated circuit ). As mentioned earlier ,Wire
、Reg
and IO
Can encapsulate any Chisel type , And of course Bundle
and Vec
.
stay Scala in , Variables are divided into var
and val
Two types of , The former is variable , The latter is immutable . And in the Chisel in , We just need to use val
To describe the circuit , It's immutable Scala Variable , such as :
val number = Wire(UInt())
val reg = Reg(SInt())
We can assign or reassign the value or expression to Wire
、Reg
or IO
, Use of Chisel Operators are :=
:
number := 10.U
reg := value - 3.U
This is obviously the same as Scala The assignment operator in =
It's different . How to use these two operators ? It's simple , stay establish When we use a hardware object Scala The operator =
, And I'm giving What already exists When assigning or reassigning hardware objects , Just use Chisel The operator :=
.
Combinatorial logical values can also be conditionally assigned , But you need to assign values to each branch of the condition . Otherwise , A latch will be introduced (latch), This is a Chisel Compiler does not accept . The best way is to create Wire
A default value is given when , therefore , The previous code is better written like this :
val number = WireDefault(10.U(4.W))
Empathy , As mentioned before ,Chisel Will infer the required bit width for signals and registers , But it is better to specify the desired bit width when creating hardware objects . On most occasions , It is also best to give the register a known reset initialization value :
val reg = RegInit(0.S(8.W))
RegInit
and WireDefault
not quite the same , The former refers to the value at reset , The latter refers to the default connection .
as for IO
, Interface for declaring a module , The usage is usually as follows :
val io = IO(new Bundle {
val in_a = Input(UInt(8.W))
val out_b = Output(UInt(8.W))
})
IO()
It's a bundle Example ,bundle Inside is the input and output interface , Use them separately Input
and Output
encapsulation . Here is just a brief introduction , We will talk about it later .
How to understand Chisel Build hardware
We have so far , Some have been lifted Chisel The basic code of , It looks like traditional programming languages, such as C and Java This kind is almost . however ,Chisel Like other hardware description languages , It really defines hardware components . What's the difference ? In software , The code is executed line by line , In hardware, all lines of code are Parallel execution Of .
Write Chisel Be sure to keep in mind Chisel It's really hardware generation . You can imagine , Or draw on paper , We wrote them one by one Chisel Circuit description generated module . Create one component at a time , Will add a hardware , Each assignment statement , Will generate a gate circuit and / Or trigger .
So technically ,Chisel When executing code , It's Executive Scala Program , And then by executing Chisel sentence , aggregate (collect) All hardware components and connect these nodes . The network composed of these hardware nodes is Chisel Generated hardware , Can be born Verilog Code for ASIC or FPGA comprehensive , It can also be used. Chisel tester To test . The network composed of these hardware nodes is completely parallel !
It may be a little difficult for people who have written software before to understand this kind of parallel execution , Because it is different from the parallel program of software , Hardware is naturally parallel , There is no need to assign programs to threads , There is no need to lock the communication between threads , It is a very simple parallel execution , The current runs simultaneously in every part of the hardware , That's it .
Conclusion
When I first came into contact with hardware description language , I'm confused, too , Often use the thinking of writing software to write hardware , The last thing I wrote is not what I imagined . You can only stop thinking about writing software , Simply understand writing hardware as building blocks , What we need to do is to logically connect them .
up to now , We haven't run the code yet , Just learned the basics Chisel grammar . Next article , We will learn how to use sbt Build our Chisel Project and run , At the same time, it also briefly introduces Chisel Tool flow for , Coming soon .
边栏推荐
- golang fmt.printf()(转)
- 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
- 苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?
- 30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
- markdown 语法之字体标红
- Whether the loyalty agreement has legal effect
- MySQL8版本免安装步骤教程
- 自主工业软件的创新与发展
- find命令报错: paths must precede expression(转)
- Introduction to reverse debugging PE structure resource table 07/07
猜你喜欢
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
基于YOLOv1的口罩佩戴检测
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
markdown 语法之字体标红
MySQL version 8 installation Free Tutorial
一次 Keepalived 高可用的事故,让我重学了一遍它
MySQL 5 installation and modification free
.Net之延迟队列
Interviewer: what is the internal implementation of hash data type in redis?
Openharmony application development how to create dayu200 previewer
随机推荐
一次 Keepalived 高可用的事故,让我重学了一遍它
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
国内酒店交易DDD应用与实践——代码篇
近日小结(非技术文)
Unittest框架中引入TestFixture
Byte interview algorithm question
Basic mode of service mesh
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
[C question set] of VII
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
gorm 之数据插入(转)
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
#yyds干货盘点# 解决名企真题:连续最大和
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
基于YOLOv1的口罩佩戴检测
Summary of recent days (non-technical article)
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
WS2811 M是三通道LED驱动控制专用电路彩灯带方案开发
DGraph: 大规模动态图数据集