Skip to content

Instantly share code, notes, and snippets.

@kammoh
Created May 15, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kammoh/ceafdc3c0ce50cd236ca41dfe671495c to your computer and use it in GitHub Desktop.
Save kammoh/ceafdc3c0ce50cd236ca41dfe671495c to your computer and use it in GitHub Desktop.
import chisel3._
import chisel3.util._
import chisel3.ExplicitCompileOptions.Strict
import chisel3.internal.naming.chiselName
@chiselName
class Ram[T <: Data](size: Int, elType: T, numPorts: Int = 2) extends Module {
val io = IO(new Bundle {
val port = Vec(numPorts, new Bundle {
val req = Flipped(Valid(new Bundle {
val addr = UInt(log2Ceil(size).W)
val write = Valid(elType.cloneType)
}))
val resp = Valid(elType.cloneType)
})
})
private val ram = SyncReadMem(size, elType).suggestName(name)
io.port.foreach(port => {
val mkPort = ram(port.req.bits.addr)
mkPort.suggestName(name + "Port")
port.resp.valid := RegNext(port.req.valid, 0.B)
port.resp.bits := DontCare
when(port.req.valid) {
port.resp.bits := mkPort
when(port.req.bits.write.valid) {
mkPort := port.req.bits.write.bits
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment