2

I am new to chisel and I have designed basic circuits and a simple risc-v processor with it but I still can't figure out how the scope works in Scala/ Chisel. Considering the following simple counter:

package example

import chisel3._

class GenericCounter(n: Int) extends Module {
  val io = IO(new Bundle {
    val ld   = Input(UInt(1.W))
    val cld  = Input(UInt(log2Ceil(n).W))
    val cout = Output(UInt(log2Ceil(n).W))
  })

  val cnt = RegInit(0.asUInt(n.W))

  when(io.ld === 1.U){
    cnt := io.cld
  } .otherwise{
    cnt :=  Mux(cnt===100.U, 0.U, cnt + 1.U)
  }
  io.cout := cnt
}

While trying to compile the above code, the compiler give an error that log2ceil is not defined. But if I use util.log2ceil it works fine. This is true for all util functions such as Cat, isPow2 etc. I know that the import chisel3._ should have imported all the necessary functions but it seems that I am missing something here. Can someone help me out?

4

1 回答 1

4

在 Scala 中,导入包的所有内容不会导入任何子包的内容。因此,如果你想导入你的内容,chisel.util你也应该写import chisel3.util._

于 2017-05-24T03:57:35.103 回答