Chisel Decoupled
Decoupled 即为接口包装一层valid 和 ready ,decoupled 默认方向为输出,如果需要输入,可以加.flip, Decoupled 可以直接调用Bundle或者Bits,Bundle 内的端口也应该用bits定义
example1 :
class testIO extends Bundle {
val a = Bits(3.W)
val b = Bits(2.W)
}
class testmodule extends Module{
val io = IO( new Bundle{
val test = Decoupled(new testIO)
})
io.test.valid := io.test.ready
io.test.bits.a := 1.U
io.test.bits.b := 1.U
}
println(getVerilog(new testmodule))
生成的verilog为:
module cmd5Helpertestmodule(
input clock,
input reset,
input io_test_ready,
output io_test_valid,
output [2:0] io_test_bits_a,
output [1:0] io_test_bits_b
);
assign io_test_valid = io_test_ready; // @[cmd5.sc 10:15]
assign io_test_bits_a = 3'h1; // @[cmd5.sc 11:16]
assign io_test_bits_b = 2'h1; // @[cmd5.sc 12:16]
endmodule
example2 :
class testmodule extends Module{
val io = IO( new Bundle{
val test = Decoupled(Bits(3.W))
val a = Input(UInt(2.W))
})
io.test.valid := io.test.ready
io.test.bits := 1.U
}
println(getVerilog(new testmodule))
生成的verilog:
module cmd7Helpertestmodule(
input clock,
input reset,
input io_test_ready,
output io_test_valid,
output [2:0] io_test_bits,
input [1:0] io_a
);
assign io_test_valid = io_test_ready; // @[cmd7.sc 6:15]
assign io_test_bits = 3'h1; // @[cmd7.sc 7:14]
endmodule