https://mp.weixin.qq.com/s/RQg2ca1rwfVHx_QG-IOV-w

 
字节选择器。
 
参考链接:
https://github.com/ucb-bar/chisel-tutorial/blob/release/src/main/scala/examples/ByteSelector.scala
 
1. 引入Chisel3
 
 
2. 继承自Module类
 
 
3. 定义输入输出接口
 
创建各项输入输出接口。
 
这些接口都是无符号整型数:val in = Input(UInt(32.W))
a. 使用32.W表示位宽为32位;
b. 使用UInt创建无符号整型数;
c. 使用Input/Output表示接口方向;
d. val 关键字表明定义的变量是所属匿名Bundle子类的数据成员;
 
4. 内部连接
 
 
使用when/elsewhen/otherwise表达判断逻辑。
 
1) when()()可以理解为一个有三个参数列表的函数
 
函数签名如下,返回一个WhenContext对象:
 
Scala中,允许使用{}代替()来包围参数列表。所以when()()可以改成when(){}的形式。
 
最后一个参数列表忽略。
 
2) elsewhen()()
 
 
elsewhen/otherwise都是WhenContext的方法。所以可以直接调用。elsewhen如同when,接收两个参数列表。
 
3) otherwise()
 
最后一个判断分支。
 
5. 生成Verilog
 
 
可以直接点运行符号运行。
 
也可以使用sbt shell执行:
 
生成Verilog如下:
 
6. 测试
 
 
 
7. 附录
 
ByteSelector.scala:
import chisel3._

class ByteSelector extends Module {
val io = IO(new Bundle {
val in = Input(UInt(32.W))
val offset = Input(UInt(2.W))
val out = Output(UInt(8.W))
})
io.out := 0.U(8.W)
when (io.offset === 0.U(2.W)) {
io.out := io.in(7, 0)
}.elsewhen(io.offset === 1.U) {
io.out := io.in(15, 8)
}.elsewhen(io.offset === 2.U) {
io.out := io.in(23, 16)
}.otherwise {
io.out := io.in(31, 24)
}
} object ByteSelectorMain {
def main(args: Array[String]): Unit = {
chisel3.Driver.execute(Array("--target-dir", "generated/ByteSelector"), () => new ByteSelector)
}
}

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

  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 - Functionality

    https://mp.weixin.qq.com/s/3hDzpJiANdwp07hO03psyA   演示使用函数进行代码复用的方法.   参考链接: https://github.com/ucb- ...

  6. Chisel3 - Tutorial - Parity

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

  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. Java 四种权限修饰符

    Java 四种权限修饰符访问权限 public protected (default) private 同一个类(我自己) yes yes yes yes 同一包(我邻居) yes yes yes n ...

  2. search(10)- elastic4s-multi_match:多字段全文搜索

    在全文搜索中我们常常会在多个字段中匹配同一个查询条件或者在不同的字段中匹配不同的条件.比如下面这个例子: GET /books/_search { "query": { " ...

  3. redis文章汇总

    方便集群管理时的查看操作 http://www.cnblogs.com/mushroom/p/4738170.html http://www.cnblogs.com/hjwublog/p/568170 ...

  4. python之导入模块的方法

    一.导入标准库模块 1.第一种方式: 可以通过以下方法导入 import time 当使用时间模块的sleep方法时可以使用 time.sleep(2) 2.第二种方式: 当只想使用sleep函数时, ...

  5. MYsql 8 连接报错 MySQLNonTransientConnectionException: Could not create connection to database server.

    本地安装mysql 是8 项目中数据驱动 也要求是 8 <dependency> <groupId>mysql</groupId> <artifactId&g ...

  6. css段落样式

    字间距 letter-spacing 首行缩进 text-indent

  7. putty、pscp、psftp 使用教程

    如何从安装了Windows的工作电脑连远程接到Linux服务器?其实有很多软件,比如 PuTTY.XShell.CRT.MobaXterm等等.不过还是 PuTTY最简单易用.无需安装.并且开源免费. ...

  8. Spring全家桶之springMVC(二)

    spring mvc中url-pattern的写法 1.设置url-pattern为*.do 之前我们在web.xml文件中配置DispatcherServlet的时候,将url-pattern配置为 ...

  9. spark机器学习从0到1特征提取 TF-IDF(十二)

        一.概念 “词频-逆向文件频率”(TF-IDF)是一种在文本挖掘中广泛使用的特征向量化方法,它可以体现一个文档中词语在语料库中的重要程度. 词语由t表示,文档由d表示,语料库由D表示.词频TF ...

  10. NodeJS的概述

    1.NodeJS概述 基于谷歌V8引擎,运行在服务器端的环境 对比JS和NodeJS (1)JS运行在浏览器端,存在多种浏览器解释器,容易产生兼容性的问题:而NodeJS运行在服务器端,只有V8引擎一 ...