chisel toolchain - lu-ping/chisel3 GitHub Wiki
How to build and test in simulation an interesting chisel circuit.
The Cast
There are three kinds of players here
- The Chisel developers: People who invented and built the toolchain
- The Chisel Library Developers: People who have added functionality and domain specific utilities, e.g. DSP tools for chisel
- The Circuit Developer: Will assume for the moment this means you. You have a circuit you want to build.
The Tools
- Chisel: A front-end circuit generator that implements an embedded Scala circuit DSL which compiles into a Firrtl file
- Firrtl: An extensible multi-pass compiler that lowers high level firrtl into lower firrtl or to verilog
- Firrtl Interpreter: A Scala level simulator that executes low firrtl.
- chisel-
The Circuit and Its tests
- Device Under Test or the DUT: written using Chisel in Scala
- Device Tester: an subclass of PeekPokeTester that allows setting DUT's inputs, testing its outputs and stepping the clock
- Device Launcher: Most commonly done in the form of a class that extends a scalatest
Act 1. Preparing to test
- ChiselerX checkouts the ucb-bar/chisel-template and follows the instructions, renaming it and changing it to be a new git project
- They decide to use the ucb-bar/dsptools library, which simply requires that they add a new dependency line in their
build.sbt
file in the root directory - They create a DUT.scala and in it create a DUT Chisel Module, using constructs from the dsp library, including:
- annotations
- instances of black boxes
- They create a device tester which takes a DUT and pokes its input and outputs and steps it
- They create a launcher for the tester based on the Scalatest library
- They execute the launcher which kicks off the following flurry of activity
Act 2. Execution
- Options for the execution are parsed and assembled into individual configurations for each part of the execution toolchain
- The circuit is elaborated.
- The circuit is parsed
- An internal graph of the circuit is generated
- Annotations of circuit components are collected
- References to black boxes are checked.
- firrtl interpreter requires blackbox implementations be scala classes contained in black box factories
- verilator requires black boxes be made available as a directory of verilog implementation files
- The library registers any custom passes it requires with a firrtl configuration object
- The circuit is emitted, i.e. serialized as text. That text may be saved to disk
- The firrtl compiler is launched
- flags indicating whether it should produces low firrtl or verilog
- custom passes must be available as transformation passes
- annotations must be available as firrtl annotation classes
Act 2 with firrtl backend
- A firrtl interpreter is created
- blackbox factories must be passed as Seq of blackbox factories
- various other flags come in as interpreter specific options for things like verbosity, and whether to log as a vcd file
- The DUTTester communicates with the interpreter instance
Act 2. with verilator
- verilator is called to build the verilog generated by the firrtl compiler
- blackbox factories must be passed as directory of black box implementations written in verilog
- numberous other flags that control compilation options to verilator
- verilator builds one or more c++ files that implement a simulator
- c++ is called to compile the simulator into an executable binary
- A separate process is launched with the simulator connected to tester process via IPC
- The DUTTester communicates with the simulator instance over the IPC channels