3
votes

I am using multiple clock in chisel.

In chisel3, I write following codes.

withClockAndReset(A_clk, A_rst) {
    val data_a = RegInit(0.U(4.W))
}
withClockAndReset(B_clk, B_rst) {
    val data_b = RegInit(0.U(4.W))
}
data_b := data_a
data_a := io.data

The compiler reported that the variable data_a could not be found. The variable data_a is defined inside withClockAndReset, and I can't use this variable outside.

What can I do?

1
A_clk, B_clk, A_rst and B_rst is ok. The variable data_a which defined inside the withClockAndReset is not found, when I try to use it outside withClockAndReset. - Self-Motivated Wu

1 Answers

3
votes

Try:

val data_a = withClockAndReset(A_clk, A_rst) {
    RegInit(0.U(4.W))
}

The issue is that you're defining a val in a separate scope.

Whatever the second argument list of withClockAndReset (what is put in the { \* ... *\ }) returns. So, you can use this to return the register, module, etc. that you construct in the other clock/reset scope.