Chisel实验笔记(三)
来源:互联网 发布:淘宝订单贷款突然关闭 编辑:程序博客网 时间:2024/05/20 02:56
在《Chisel实验笔记(一)》中我们得到了verilog文件,在《Chisel实验笔记(二)》中我们使用Icarus Verilog、GtkWave对的道德verilog文件进行了仿真测试,实际上,时欧诺个Chisel可以得到对应的C++文件,从而可以直接进行仿真,本文就介绍产生C++文件,进行测试的实验过程。
1、修改Max2.scala文件如下:
import Chisel._class Max2 extends Module { val io = new Bundle { val in0 = UInt(INPUT, 8) val in1 = UInt(INPUT, 8) val out = UInt(OUTPUT, 8) } io.out := Mux(io.in0 > io.in1, io.in0, io.in1) }class Max2Tests(c: Max2) extends Tester(c) { for (i <- 0 until 10) { // FILL THIS IN HERE val in0 = rnd.nextInt(1 << 8) val in1 = rnd.nextInt(1 << 8) poke(c.io.in0, in0) poke(c.io.in1, in1) // FILL THIS IN HERE step(1) expect(c.io.out, if(in0 > in1) in0 else in1) }}object max2 { def main(args: Array[String]) : Unit={ val margs=Array("--backend","c","--genHarness","--compile","--test") chiselMainTest(margs, () => Module(new Max2())){c => new Max2Tests(c)} }}相比《Chisel实验笔记(一)》中的Max2.scala代码,其中增加了Max2Tests类,这是专门用来测试的,相当于verilog中的testbench,在这个Max2Test类中,进行了10次循环,每次测试,都随机得到两个8位的数,使用poke将这两个随机数分别赋值给Max2的in0、in1,然后使用expect判断Max2的输出out是否是是in0、in1中较大的那个值。
除了增加Max2Test类,还修改了main中的margs,将其中的“v”改为了“c”,还增加了参数“--genHarness”、“--test”。
然后打开终端,进入chisel_max的目录,输入sbt,再输入run,可以得到如下结果:
> run[info] Compiling 1 Scala source to /home/riscv/Documents/chisel_max/target/scala-2.10/classes...[warn] there were 8 feature warning(s); re-run with -feature for details[warn] one warning found[info] Running max2 CPP elaborate[info] [0.025] // COMPILING < (class Max2)>(0)[info] [0.028] giving names[info] [0.034] executing custom transforms[info] [0.034] adding clocks and resets[info] [0.038] inferring widths[info] [0.042] checking widths[info] [0.043] lowering complex nodes to primitives[info] [0.043] removing type nodes[info] [0.043] compiling 5 nodes[info] [0.044] computing memory ports[info] [0.044] resolving nodes to the components[info] [0.049] creating clock domains[info] [0.050] pruning unconnected IOs[info] [0.051] checking for combinational loops[info] [0.052] NO COMBINATIONAL LOOP FOUND[info] [0.058] populating clock domainsCppBackend::elaborate: need 0, redundant 0 shadow registers[info] [0.067] generating cpp filesCppBackend: createCppFile Max2.cpp[info] [1.729] g++ -c -o ./Max2-emulator.o -I../ -Inull/csrc/ ./Max2-emulator.cpp RET 0[info] [2.155] g++ -c -o ./Max2.o -I../ -Inull/csrc/ ./Max2.cpp RET 0[info] [2.302] g++ -o ./Max2 ./Max2.o ./Max2-emulator.o RET 0SEED 1432871199400STARTING ./Max2RESET 5 POKE Max2.io_in0 <- 0x6b POKE Max2.io_in1 <- 0x99STEP 1 -> 1 PEEK Max2.io_out -> 0x99EXPECT Max2.io_out <- 153 == 153 PASS POKE Max2.io_in0 <- 0xc POKE Max2.io_in1 <- 0xa7STEP 1 -> 2 PEEK Max2.io_out -> 0xa7EXPECT Max2.io_out <- 167 == 167 PASS POKE Max2.io_in0 <- 0x51 POKE Max2.io_in1 <- 0x80STEP 1 -> 3 PEEK Max2.io_out -> 0x80EXPECT Max2.io_out <- 128 == 128 PASS POKE Max2.io_in0 <- 0xc7 POKE Max2.io_in1 <- 0x8fSTEP 1 -> 4 PEEK Max2.io_out -> 0xc7EXPECT Max2.io_out <- 199 == 199 PASS POKE Max2.io_in0 <- 0x21 POKE Max2.io_in1 <- 0x60STEP 1 -> 5 PEEK Max2.io_out -> 0x60EXPECT Max2.io_out <- 96 == 96 PASS POKE Max2.io_in0 <- 0xd6 POKE Max2.io_in1 <- 0xafSTEP 1 -> 6 PEEK Max2.io_out -> 0xd6EXPECT Max2.io_out <- 214 == 214 PASS POKE Max2.io_in0 <- 0x96 POKE Max2.io_in1 <- 0x98STEP 1 -> 7 PEEK Max2.io_out -> 0x98EXPECT Max2.io_out <- 152 == 152 PASS POKE Max2.io_in0 <- 0xa4 POKE Max2.io_in1 <- 0x6bSTEP 1 -> 8 PEEK Max2.io_out -> 0xa4EXPECT Max2.io_out <- 164 == 164 PASS POKE Max2.io_in0 <- 0xe6 POKE Max2.io_in1 <- 0x6cSTEP 1 -> 9 PEEK Max2.io_out -> 0xe6EXPECT Max2.io_out <- 230 == 230 PASS POKE Max2.io_in0 <- 0x7b POKE Max2.io_in1 <- 0x3cSTEP 1 -> 10 PEEK Max2.io_out -> 0x7bEXPECT Max2.io_out <- 123 == 123 PASSRAN 10 CYCLES PASSEDPASSED[success] Total time: 3 s, completed May 29, 2015 11:46:41 AM
在终端中输出了10次模拟结果,PASS表示通过测试。
0 0
- Chisel实验笔记(三)
- Chisel实验笔记(一)
- Chisel实验笔记(二)
- Chisel实验笔记(四)
- Chisel Tutorial(三)——组合电路
- chisel
- Chisel Tutorial(一)——Chisel介绍
- Chisel Tutorial(二)——Chisel的数据类型
- Chisel 专题(一) 安装
- ZigBee组网学习笔记(三 )--协议栈串口实验
- stm32学习笔记(三)串口通讯实验
- Chisel Tutorial(四)——函数
- Chisel Tutorial(六)——端口
- Chisel Tutorial(七)——模块
- 汇编实验(三)
- Hadoop笔记之三:WordCount实验续
- STM8学习笔记三----按键实验
- 《数据结构》实验三:栈和队列实验 (实验报告)
- win7 安装oracle 11g R2
- UISearchDisplayController的searchResultsTableView的Contentsize不正确的问题
- 序列化和反序列化
- DDoS攻击和IP欺骗
- 邢台自闭症能治好吗
- Chisel实验笔记(三)
- 如何使用程序代码设定偏好应用
- 为什么使用preparedstatement
- 邢台自闭症哪里治最好
- eclipse luna 4.2 svn 检出 web项目
- 邢台自闭症哪里治疗最好
- 保存应用程序上下文
- SSH问题解决办法之重定向问题
- HDU ACM 2489 Minimal Ratio Tree