-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/main/scala/chisel3/util/experimental/CIRCTSRAMInterface.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package chisel3.util.experimental | ||
|
||
import chisel3._ | ||
import chisel3.experimental.BaseModule | ||
import chisel3.experimental.hierarchy.Instance | ||
import chisel3.util.log2Ceil | ||
|
||
import scala.collection.immutable.SeqMap | ||
|
||
object CIRCTSRAMParameter { | ||
implicit val rw: upickle.default.ReadWriter[CIRCTSRAMParameter] = upickle.default.macroRW | ||
} | ||
|
||
case class CIRCTSRAMParameter( | ||
moduleName: String, | ||
read: Int, | ||
write: Int, | ||
readwrite: Int, | ||
depth: Int, | ||
width: Int, | ||
maskGranularity: Int) { | ||
def masked: Boolean = maskGranularity != 0 | ||
} | ||
|
||
class CIRCTSRAMInterface(memoryParameter: CIRCTSRAMParameter) extends Record { | ||
|
||
class R extends Record { | ||
lazy val clock = Input(Clock()) | ||
lazy val address = Input(UInt(log2Ceil(memoryParameter.depth).W)) | ||
lazy val data = Output(UInt(memoryParameter.width.W)) | ||
lazy val enable = Input(Bool()) | ||
|
||
val elements: SeqMap[String, Data] = SeqMap( | ||
"clk" -> clock, | ||
"addr" -> address, | ||
"data" -> data, | ||
"en" -> enable | ||
) | ||
} | ||
class W extends Record { | ||
lazy val clock = Input(Clock()) | ||
lazy val address = Input(UInt(log2Ceil(memoryParameter.depth).W)) | ||
lazy val data = Input(UInt(memoryParameter.width.W)) | ||
lazy val mask = Input(UInt(memoryParameter.width.W)) | ||
lazy val enable = Input(Bool()) | ||
|
||
val elements: SeqMap[String, Data] = SeqMap( | ||
"clk" -> clock, | ||
"addr" -> address, | ||
"data" -> data, | ||
"en" -> enable | ||
) ++ Option.when(memoryParameter.masked)("mask" -> mask) | ||
} | ||
class RW extends Record { | ||
lazy val clock = Input(Clock()) | ||
lazy val address = Input(UInt(log2Ceil(memoryParameter.depth).W)) | ||
lazy val writeData = Input(UInt(memoryParameter.width.W)) | ||
lazy val writeMask = Input(UInt(memoryParameter.width.W)) | ||
lazy val writeEnable = Input(Bool()) | ||
lazy val readData = Output(UInt(memoryParameter.width.W)) | ||
lazy val enable = Input(Bool()) | ||
|
||
val elements: SeqMap[String, Data] = SeqMap( | ||
"clk" -> clock, | ||
"addr" -> address, | ||
"wdata" -> writeData, | ||
"wmode" -> writeEnable, | ||
"rdata" -> readData, | ||
"en" -> enable | ||
) ++ Option.when(memoryParameter.masked)("wmask" -> writeMask) | ||
} | ||
|
||
def R(idx: Int): R = elements(s"R$idx").asInstanceOf[R] | ||
def W(idx: Int): W = elements(s"W$idx").asInstanceOf[W] | ||
def RW(idx: Int): RW = elements(s"RW$idx").asInstanceOf[RW] | ||
|
||
val elements: SeqMap[String, Data] = | ||
(Seq.tabulate(memoryParameter.read)(i => s"R$i" -> new R) ++ | ||
Seq.tabulate(memoryParameter.write)(i => s"W$i" -> new W) ++ | ||
Seq.tabulate(memoryParameter.readwrite)(i => s"RW$i" -> new RW)) | ||
.to(SeqMap) | ||
} | ||
|
||
abstract class CIRCTSRAM[T <: RawModule](memoryParameter: CIRCTSRAMParameter) | ||
extends FixedIORawModule[CIRCTSRAMInterface](new CIRCTSRAMInterface(memoryParameter)) { | ||
override def desiredName: String = memoryParameter.moduleName | ||
val memoryInstance: Instance[_ <: BaseModule] | ||
} |