Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
emulate BRAM one clock cycle delay
Browse files Browse the repository at this point in the history
  • Loading branch information
SinaKarvandi committed May 1, 2024
1 parent 247f017 commit 9e1f85d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/scala/hwdbg/configs/configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ object DebuggerConfigurations {
*/
object MemoryCommunicationConfigurations {

//
// Emulate block RAM by inferring a register to delay one clock cycle
//
val ENABLE_BLOCK_RAM_DELAY: Boolean = true

//
// Default number of bytes used in initialized SRAM memory
//
Expand Down
19 changes: 17 additions & 2 deletions src/main/scala/hwdbg/libs/mem/init_reg_mem_from_file.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object InitRegMemFromFileTools {

class InitRegMemFromFile(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
emulateBlockRamDelay: Boolean = MemoryCommunicationConfigurations.ENABLE_BLOCK_RAM_DELAY,
memoryFile: String = TestingConfigurations.BRAM_INITIALIZATION_FILE_PATH,
addrWidth: Int = DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
width: Int = DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
Expand All @@ -72,18 +73,30 @@ class InitRegMemFromFile(

val mem = RegInit(VecInit(InitRegMemFromFileTools.readmemh(debug, memoryFile, width)))

val actualAddr = Wire(UInt(addrWidth.W))
val actualData = Wire(UInt(width.W))

//
// This because the address of the saved registers are using 4 bytes granularities
// E.g., 4 Rsh 2 = 1 | 8 Rsh 2 = 2 | 12 Rsh 2 = 3
//
val actualAddr = io.addr >> 2
if (emulateBlockRamDelay) {
//
// In case, if it is an emulation of BRAM, a one clock delay is injected
//
actualAddr := RegNext(io.addr >> 2)
actualData := RegNext(io.dataIn)
} else {
actualAddr := io.addr >> 2
actualData := io.dataIn
}

when(io.enable) {
val rdwrPort = mem(actualAddr)
io.dataOut := rdwrPort

when(io.write) {
mem(actualAddr) := io.dataIn
mem(actualAddr) := actualData
}
}.otherwise {
io.dataOut := 0.U
Expand All @@ -94,6 +107,7 @@ object InitRegMemFromFile {

def apply(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
emulateBlockRamDelay: Boolean = MemoryCommunicationConfigurations.ENABLE_BLOCK_RAM_DELAY,
memoryFile: String = TestingConfigurations.BRAM_INITIALIZATION_FILE_PATH,
addrWidth: Int = DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
width: Int = DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
Expand All @@ -108,6 +122,7 @@ object InitRegMemFromFile {
val initRegMemFromFileModule = Module(
new InitRegMemFromFile(
debug,
emulateBlockRamDelay,
memoryFile,
addrWidth,
width,
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/top_test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class DebuggerModuleTestingBRAM(
val dataOut =
InitRegMemFromFile(
debug,
MemoryCommunicationConfigurations.ENABLE_BLOCK_RAM_DELAY,
TestingConfigurations.BRAM_INITIALIZATION_FILE_PATH,
bramAddrWidth,
bramDataWidth,
Expand Down

0 comments on commit 9e1f85d

Please sign in to comment.