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

 
演示使用函数进行代码复用的方法。
 
参考链接:
.scala
 
1. 引入Chisel3
 
 
2. 继承自Module类
 
 
3. 定义输入输出接口
 
创建各项输入输出接口。
 
.W))
a. 使用16.W表示位宽为16位;
b. 使用UInt创建无符号整型数;
c. 使用Input/Output表示接口方向;
关键字表明定义的变量是所属匿名Bundle子类的数据成员;
 
4. 内部连接
 
 
这里使用了函数来定义一个可以复用的逻辑。
 
1) def关键字定义一个函数名为clb
函数签名为:
)
接收四个参数,返回值从函数定义中推断。
 
函数实现为:
(a & b) | (~c & d)
可以推断出返回值类型为UInt。
 
2) io.z直接连接到clb函数的返回值:
)
 
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)
}
}

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案