joe 发表于 2021-8-20 08:55:48

chisel 4级移位寄存器

一个4级移位寄存器的图示如下:


从图中可以看到,电路形成了4级延迟,用这个简单移位寄存器做如下:
1)产生一个4位寄存器ShiftRegister
2)合并移位寄存器的低3位到输入din用于下一个寄存器的输入
3)使用最高位的寄存器用于输出
import chisel3._
import chisel3.util._
class ShiftRegModule extends Module{
val io = IO(new Bundle {
    val din = Input(UInt(1.W))
    val dout = Output(UInt(1.W))
})
val shiftReg = Reg(UInt(4.W)) //用chisel类型 UInt定义一个4bit普通寄存器
shiftReg := Cat(shiftReg(2,0),io.din)
//shiftReg其实从语法角度来说是UInt,而UInt的父Bits中有一个final def apply(x: Int, y: Int): UInt = macro SourceInfoTransform.xyArg
//用来返回从y开始到x为止的bit位的数据,也就是说取shiftReg的bit0到bit2共3位,Cat表示将这三位与io.din按高低顺序连接起来:
//shiftReg shifrReg shiftReg io.din
io.dout := shiftReg(3)
}
产生的verilog文件内容如下:
module ShiftRegModule(
input   clock,
input   reset,
input   io_din,
outputio_dout
);
reg shiftReg; // @
reg _RAND_0;
assign io_dout = shiftReg; // @
always @(posedge clock) begin
    shiftReg <= {shiftReg,io_din};
end
endmodule

页: [1]
查看完整版本: chisel 4级移位寄存器