https://mp.weixin.qq.com/s/3hDzpJiANdwp07hO03psyA

 
演示使用函数进行代码复用的方法。
 
参考链接:
https://github.com/ucb-bar/chisel-tutorial/blob/release/src/main/scala/examples/.scala
 
1. 引入Chisel3
 
 
2. 继承自Module类
 
 
3. 定义输入输出接口
 
创建各项输入输出接口。
 
这些接口都是无符号整型数:val x = Input(UInt(16.W))
a. 使用16.W表示位宽为16位;
b. 使用UInt创建无符号整型数;
c. 使用Input/Output表示接口方向;
d. val 关键字表明定义的变量是所属匿名Bundle子类的数据成员;
 
4. 内部连接
 
 
这里使用了函数来定义一个可以复用的逻辑。
 
1) def关键字定义一个函数名为clb
函数签名为:
def clb(a: UInt, b: UInt, c: UInt, d: UInt)
接收四个参数,返回值从函数定义中推断。
 
函数实现为:
(a & b) | (~c & d)
可以推断出返回值类型为UInt。
 
2) io.z直接连接到clb函数的返回值:
io.z := clb(io.x, io.y, io.x, io.y)
 
5. 生成Verilog
 
 
可以直接点运行符号运行。
 
也可以使用sbt shell执行:
 
生成Verilog如下:
 
6. 测试
 
 
 
7. 附录
 
Functionality.scala:
import chisel3._

class Functionality extends Module {
val io = IO(new Bundle {
val x = Input(UInt(16.W))
val y = Input(UInt(16.W))
val z = Output(UInt(16.W))
})
def clb(a: UInt, b: UInt, c: UInt, d: UInt) =
(a & b) | (~c & d)
io.z := clb(io.x, io.y, io.x, io.y)
} object FunctionalityMain {
def main(args: Array[String]): Unit = {
chisel3.Driver.execute(Array("--target-dir", "generated/Functionality"), () => new Functionality)
}
}
 

Chisel3 - Tutorial - Functionality的更多相关文章

  1. Chisel3 - Tutorial - VendingMachine

    https://mp.weixin.qq.com/s/tDpUe9yhwC-2c1VqisFzMw   演示如何使用状态机.   参考链接: https://github.com/ucb-bar/ch ...

  2. Chisel3 - Tutorial - VendingMachineSwitch

    https://mp.weixin.qq.com/s/5lcMkenM2zTy-pYOXfRjyA   演示如何使用switch/is来实现状态机.   参考链接: https://github.co ...

  3. Chisel3 - Tutorial - Tbl

    https://mp.weixin.qq.com/s/e8vJ8claauBtiuedxYYaJw   实现可以动态索引的表.   参考链接: https://github.com/ucb-bar/c ...

  4. Chisel3 - Tutorial - Stack

    https://mp.weixin.qq.com/s/-AVJD1IfvNIJhmZM40DemA   实现后入先出(last in, first out)的栈.   参考链接: https://gi ...

  5. Chisel3 - Tutorial - Parity

    https://mp.weixin.qq.com/s/OtiQnE52PwdCpvmzJ6VFnA   奇偶发生器.统计输入中1的个数,如果为偶数则输出0,奇数则输出1.   参考链接: https: ...

  6. Chisel3 - Tutorial - ByteSelector

    https://mp.weixin.qq.com/s/RQg2ca1rwfVHx_QG-IOV-w   字节选择器.   参考链接: https://github.com/ucb-bar/chisel ...

  7. Chisel3 - Tutorial - ShiftRegister

    https://mp.weixin.qq.com/s/LKiXUgSnt3DzgFLa9zLCmQ   简单的寄存器在时钟的驱动下,逐个往下传值.   参考链接: https://github.com ...

  8. Chisel3 - Tutorial - Adder

    https://mp.weixin.qq.com/s/SEcVjGRL1YloGlEPSoHr3A   位数为参数的加法器.通过FullAdder级联实现.   参考链接: https://githu ...

  9. Chisel3 - Tutorial - Adder4

    https://mp.weixin.qq.com/s/X5EStKor2DU0-vS_wIO-fg   四位加法器.通过FullAdder级联实现.   参考链接: https://github.co ...

随机推荐

  1. 网上流行护眼色的RGB值和颜色代码

    网上流行护眼色的RGB值和颜色代码   绿豆沙色能有效的减轻长时间用电脑的用眼疲劳!色调:85,饱和度:123,亮度:205: RGB颜色红:199,绿:237,蓝:204:十六进制颜色:#C7EDC ...

  2. SpringBoot系列(十四)集成邮件发送服务及邮件发送的几种方式

    往期推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件详解 SpringBoot系列(四)web静 ...

  3. 《C程序设计语言》 练习2-6 及 位运算总结

    问题描述 2.6 编写一个函数setbits(x, p ,n, y),该函数返回对x执行下列操作后的结果值: 将x中从第p位开始的n个(二进制)位设置为y中最右边n位的值,x的其余各位保持不变. Wr ...

  4. 1013 Battle Over Cities (25分) 图的连通分量+DFS

    题目 It is vitally important to have all the cities connected by highways in a war. If a city is occup ...

  5. js Date对象日期格式化

    dateFormat(d, fmt) { var o = { 'M+': d.getMonth() + 1, 'd+': d.getDate(), 'h+': d.getHours(), 'm+': ...

  6. AOP行为日志

    最近新项目要记录行为日志,很久没有用AOP,研究了一下. 废话补多少,先上个流程图: 数据库日志表设计 字段名称 字段类型 注释 LOG_ID VARCHAR2(255)   LOG_LEVEL  N ...

  7. hadoop与spark的处理技巧(四)推荐引擎处理技巧

    经常一起购买的商品 scala> var file=sc.textFile("/user/ghj/togeterBought") file: org.apache.spark ...

  8. 读懂这几个关键词,你就能了解 Docker 啦

    基于高度虚拟化所诞生的容器技术,如今已经走向大规模应用.那么容器.虚拟机.Docker.Openstack.Kubernetes 之间又有什么关系,对现在的选择有什么影响呢? 上世纪 60 年代,计算 ...

  9. 微信小程序前端与myeclipse的数据交换过程(SSH)

    这是我个人探究微信小程序前端与后端之间的数据交换的过程,再结合个人所学的SSH框架, 编程工具用myEclipse2014工具.当然,前提是后台的项目要部署到tomcat服务器上才行, 然后总结了从后 ...

  10. MySQL索引及优化(1)存储引擎和底层数据结构

    在昨天的面试中问到了MySQL索引怎么优化(查询很慢怎么办),回答的很不理想,所以今天来总结几篇关于MySQL索引的知识. 1.什么是索引? 首先我们一定要明确什么是索引?我自己的总结就是索引是一种数 ...