Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use traits between KvTransfer and TopKvTransfer modules to manage IO fields duplicates #26

Open
VMois opened this issue Oct 9, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@VMois
Copy link
Owner

VMois commented Oct 9, 2023

Possible example of structure:

import chisel3._

trait KvTransferControlIOParams {
  val numberOfBuffers: Int
}

trait KvTransferControlIO extends KvTransferControlIOParams {
  val command = Input(UInt(2.W))
  val stop = Input(Bool())
  val bufferInputSelect = Input(UInt(log2Ceil(numberOfBuffers).W))
  val busy = Output(Bool())
}

trait KvTransferIOParams {
  val busWidth: Int
  val numberOfBuffers: Int
}

trait KvTransferIO extends KvTransferIOParams {
  val data = Output(UInt(busWidth.W))
  // Define other IO signals related to KvTransferIO here
}

class MyModule(params: KvTransferControlIOParams with KvTransferIOParams) extends Module {
  val io = IO(new Bundle with KvTransferControlIO with KvTransferIO {
    val numberOfBuffers = params.numberOfBuffers
    val busWidth = params.busWidth
  })

  // Module logic goes here, you can use io.command, io.stop, io.bufferInputSelect, io.busy, io.data, etc.
}

val numberOfBuffers = 4 // Example number of buffers
val busWidth = 32 // Example bus width

val myModuleInstance = Module(new MyModule(new KvTransferControlIOParams {
  val numberOfBuffers: Int = numberOfBuffers
} with KvTransferIOParams {
  val busWidth: Int = busWidth
  val numberOfBuffers: Int = numberOfBuffers
}))
@VMois VMois added the enhancement New feature or request label Oct 9, 2023
@VMois
Copy link
Owner Author

VMois commented Oct 18, 2023

axi-node project has a nice example of trait usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant