Verified Commit 112e5623 authored by Minyong Li's avatar Minyong Li 💬
Browse files

core.DataMemory{,Test}: add another read port

parent e2b4b324
Pipeline #7473 passed with stage
in 1 minute and 16 seconds
......@@ -11,10 +11,15 @@ class DataMemory(
size: Int,
syncMem: Boolean = true
) extends MultiIOModule {
val read = IO(new Bundle {
val addr = Input(UInt(addrWidth.W))
val data = Output(UInt(dataWidth.W))
})
val read = IO(
Vec(
2,
new Bundle {
val addr = Input(UInt(addrWidth.W))
val data = Output(UInt(dataWidth.W))
}
)
)
val write = IO(new Bundle {
val en = Input(Bool())
val addr = Input(UInt(addrWidth.W))
......@@ -25,7 +30,7 @@ class DataMemory(
if (syncMem) SyncReadMem(size, UInt(dataWidth.W))
else Mem(size, UInt(dataWidth.W))
read.data := mem(read.addr)
read.foreach(p => p.data := mem(p.addr))
when(write.en) {
mem(write.addr) := write.data
......
......@@ -21,18 +21,18 @@ class DataMemoryTest extends FlatSpec with ChiselScalatestTester {
c.write.en.poke(true.B)
c.clock.step()
c.write.en.poke(false.B)
c.read.addr.poke("h01".U(addrWidth.W))
c.read.foreach(_.addr.poke("h01".U(addrWidth.W)))
c.clock.step()
c.read.data.expect("h1234".U(dataWidth.W))
c.read.foreach(_.data.expect("h1234".U(dataWidth.W)))
c.write.addr.poke("h0a".U(addrWidth.W))
c.write.data.poke("hfefe".U(dataWidth.W))
c.write.en.poke(true.B)
c.clock.step()
c.write.en.poke(false.B)
c.read.addr.poke("h0a".U(addrWidth.W))
c.read.foreach(_.addr.poke("h0a".U(addrWidth.W)))
c.clock.step()
c.read.data.expect("hfefe".U(dataWidth.W))
c.read.foreach(_.data.expect("hfefe".U(dataWidth.W)))
}
}
......@@ -43,13 +43,13 @@ class DataMemoryTest extends FlatSpec with ChiselScalatestTester {
c.write.en.poke(true.B)
c.clock.step()
c.write.en.poke(false.B)
c.read.addr.poke("h06".U(addrWidth.W))
c.read.foreach(_.addr.poke("h06".U(addrWidth.W)))
c.clock.step()
c.read.data.expect("hcafe".U(dataWidth.W))
c.read.foreach(_.data.expect("hcafe".U(dataWidth.W)))
c.write.data.poke("hefac".U(dataWidth.W))
c.clock.step()
c.read.data.expect("hcafe".U(dataWidth.W))
c.read.foreach(_.data.expect("hcafe".U(dataWidth.W)))
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment