Chisel Tutorial (vii)--module

Source: Internet
Author: User

The following content is based on 2015-7-10 version of Chisel 2.2 Tutorial Finishing


the modules in the chisel are very similar to those in the Verilog HDL , which describe the circuit in a hierarchical structure. the module in Chisel is a class whose definition follows the following points:

    • Inherit from Module class
    • There is a port named io
    • Connecting a sub-circuit in its constructor

The following is a module definition for a 2-select 1 selector:

Class Mux2 extends module{  val io = new bundle{  val sel = UInt (input, 1)  val in0 = UInt (input, 1)  Val in1 = UINT (INPUT, 1)  val out = UINT (OUTPUT, 1)  }  io.out: = (Io.sel & io.in1) | (~io.sel & Io.in1)}

an Operator ": =" in chisel is used inside the module toconnect the right output to the input on the left.

Hierarchy of modules

You can now use submodule building blocks to implement the hierarchy of the circuit, and here is an example of a 4 input selector, built with three 2 input selectors.

Class Mux4 extends module{  val io = new bundle{  val in0 = UInt (input, 1)  val in1 = UINT (input, 1)  Val in2 = UINT (input, 1)  val in3 = UINT (input, 1)  val sel = UINT (input, 2)  val out = UINT (OUTPUT, 1)  }  Val M0 = Module (new Mux2 ())  M0.io.sel: = Io.sel (0)  m0.io.in0: = Io.in0 m0.io.in1  : = Io.in1  val m1 = module (NE W Mux2 ())  M1.io.sel: = Io.sel (0)  m1.io.in0: = io.in2 m1.io.in1  : = io.in3  val m2 = Module (new Mux2 ()) C17/>m2.io.sel: = Io.sel (1)  m2.io.in0: = M0.io.out  m2.io.in1: = M1.io.out  io.out: = m2.io.out}

In the example above, three Mux2 submodules were created, and then the three modules were joined together to form a 4 input selector.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Chisel Tutorial (vii)--module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.