Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call the variable defined inside withClockAndReset

Tags:

chisel

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?

like image 814
Self-Motivated Wu Avatar asked Oct 30 '25 08:10

Self-Motivated Wu


1 Answers

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.

like image 129
seldridge Avatar answered Nov 02 '25 08:11

seldridge