joe 发表于 2021-8-17 23:04:09

用chisel做一个2-4译码器电路

import chisel3._
import chisel3.util._
class DeCoder extends RawModule{
val io = IO(new Bundle{
    val a = Input(UInt(1.W))
    val b = Input(UInt(1.W))
    val c = Output(UInt(4.W))
})
val sel = Cat(io.a,io.b)
io.c := 0.U //必须要有默认值 否则:firrtl.passes.CheckInitialization$RefNotInitializedException
switch(sel) {
    is(0.U) { io.c := 1.U}
    is(1.U) { io.c := 2.U}
    is(2.U) { io.c := 3.U}
    is(3.U) { io.c := 4.U}
}
}
对应的verilog文件内容如下:
module DeCoder(
input      io_a,
input      io_b,
output io_c
);
wire sel = {io_a,io_b}; // @
wire_T = 2'h0 == sel; // @
wire_T_1 = 2'h1 == sel; // @
wire_T_2 = 2'h2 == sel; // @
wire_T_3 = 2'h3 == sel; // @
wire _GEN_0 = _T_3 ? 3'h4 : 3'h0; // @
wire _GEN_1 = _T_2 ? 3'h3 : _GEN_0; // @
wire _GEN_2 = _T_1 ? 3'h2 : _GEN_1; // @
wire _GEN_3 = _T ? 3'h1 : _GEN_2; // @
assign io_c = {{1'd0}, _GEN_3}; // @
endmodule

joe 发表于 2021-8-17 23:05:00

可以看到用RawModule则生成的verilog中就没有clock和reset信号了
页: [1]
查看完整版本: 用chisel做一个2-4译码器电路