Skip to content

Commit d583266

Browse files
Define OCP interfaces locally
1 parent 8b20367 commit d583266

File tree

13 files changed

+169
-83
lines changed

13 files changed

+169
-83
lines changed

quartus/SharedPipelinedCacheDe2115Top/.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
# a cloned repository to be used (usually) immediately without regenerating
66
# Altera IP blocks.
77

8-
# Need to keep all HDL files and timing constraint files
9-
# *.vhd
10-
# *.v
11-
# *.sdc
8+
# Ignore HDL files since these are always generated by chisel
9+
*.vhd
10+
*.v
1211

1312
# ignore Quartus II generated folders
1413
*_sim

quartus/SharedPipelinedCacheSynthTop/.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
# a cloned repository to be used (usually) immediately without regenerating
66
# Altera IP blocks.
77

8-
# Need to keep all HDL files and timing constraint files
9-
# *.vhd
10-
# *.v
11-
# *.sdc
8+
# Ignore HDL files since these are always generated by chisel
9+
*.vhd
10+
*.v
1211

1312
# ignore Quartus II generated folders
1413
*_sim
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package caches.hardware.ocp
2+
3+
import chisel3._
4+
5+
// Constants for MCmd
6+
object OcpCmd {
7+
val IDLE = "b000".U(3.W)
8+
val WR = "b001".U(3.W)
9+
val RD = "b010".U(3.W)
10+
}
11+
12+
// Constants for SResp
13+
object OcpResp {
14+
val NULL = "b00".U(2.W)
15+
val DVA = "b01".U(2.W)
16+
val FAIL = "b10".U(2.W)
17+
val ERR = "b11".U(2.W)
18+
}
19+
20+
// Signals generated by master
21+
class OcpMasterSignals(val addrWidth: Int, val dataWidth: Int) extends Bundle() {
22+
val Cmd = Output(UInt(3.W))
23+
val Addr = Output(UInt(addrWidth.W))
24+
val Data = Output(UInt(dataWidth.W))
25+
}
26+
27+
// Signals generated by slave
28+
class OcpSlaveSignals(val dataWidth: Int) extends Bundle() {
29+
val Resp = Input(UInt(2.W))
30+
val Data = Input(UInt(dataWidth.W))
31+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package caches.hardware.ocp
2+
3+
import chisel3._
4+
5+
// Burst masters provide handshake signals
6+
class OcpBurstMasterSignals(addrWidth: Int, dataWidth: Int)
7+
extends OcpMasterSignals(addrWidth, dataWidth) {
8+
val DataValid = Output(UInt(1.W))
9+
val DataByteEn = Output(UInt((dataWidth / 8).W))
10+
11+
// This does not really clone, but Data.clone doesn't either
12+
override def clone() = {
13+
val res = new OcpBurstMasterSignals(addrWidth, dataWidth)
14+
res.asInstanceOf[this.type]
15+
}
16+
}
17+
18+
// Burst slaves provide handshake signal
19+
class OcpBurstSlaveSignals(dataWidth: Int)
20+
extends OcpSlaveSignals(dataWidth) {
21+
val CmdAccept = Input(UInt(1.W))
22+
val DataAccept = Input(UInt(1.W))
23+
}
24+
25+
// Master port
26+
class OcpBurstMasterPort(addrWidth: Int, dataWidth: Int, burstLen: Int) extends Bundle() {
27+
val burstLength = burstLen
28+
// Clk is implicit in Chisel
29+
val M = Output(new OcpBurstMasterSignals(addrWidth, dataWidth))
30+
val S = Input(new OcpBurstSlaveSignals(dataWidth))
31+
}
32+
33+
// Slave port is reverse of master port
34+
class OcpBurstSlavePort(val addrWidth: Int, val dataWidth: Int, val burstLen: Int) extends Bundle() {
35+
val burstLength = burstLen
36+
// Clk is implicit in Chisel
37+
val M = Input(new OcpBurstMasterSignals(addrWidth, dataWidth))
38+
val S = Output(new OcpBurstSlaveSignals(dataWidth))
39+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package caches.hardware.ocp
2+
3+
import chisel3._
4+
5+
// Masters include a byte-enable signal
6+
class OcpCoreMasterSignals(override val addrWidth: Int, override val dataWidth: Int)
7+
extends OcpMasterSignals(addrWidth, dataWidth) {
8+
val ByteEn = UInt((dataWidth / 8).W)
9+
}
10+
11+
// Slave port is reverse of master port
12+
class OcpCoreSlavePort(val addrWidth: Int, val dataWidth: Int) extends Bundle() {
13+
val M = Input(new OcpCoreMasterSignals(addrWidth, dataWidth))
14+
val S = Output(new OcpSlaveSignals(dataWidth))
15+
}
16+

src/main/scala/caches/hardware/pipelined/CacheMemToOcpBurstMasterAdapter.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package caches.hardware.pipelined
22

3-
import ocp._
3+
import caches.hardware.ocp._
44
import chisel3._
55
import chisel3.util._
66

@@ -22,7 +22,7 @@ class CacheMemToOcpBurstMasterAdapter(addrWidth: Int, dataWidth: Int, burstLen:
2222
val wBurstCountReg = RegInit(0.U(log2Up(burstLen).W))
2323
val wAddrDelayReg = RegInit(0.U(addrWidth.W))
2424

25-
val mCmd = WireDefault(ocp.OcpCmd.IDLE)
25+
val mCmd = WireDefault(OcpCmd.IDLE)
2626
val mAddr = WireDefault(0.U(addrWidth.W))
2727
val mDataByteEn = WireDefault(0.U((dataWidth / 8).W))
2828
val rAddrReady = WireDefault(false.B)
@@ -33,14 +33,14 @@ class CacheMemToOcpBurstMasterAdapter(addrWidth: Int, dataWidth: Int, burstLen:
3333
is(sIdle) {
3434

3535
when(io.cache.rChannel.rAddr.valid) {
36-
mCmd := ocp.OcpCmd.RD
36+
mCmd := OcpCmd.RD
3737
mAddr := io.cache.rChannel.rAddr.bits
3838

3939
when(io.ocpBurst.S.CmdAccept.asBool) {
4040
rAddrReady := true.B
4141
stateReg := sReadBurst
4242
}
43-
} .elsewhen (io.cache.wChannel.wAddr.valid) {
43+
}.elsewhen(io.cache.wChannel.wAddr.valid) {
4444
wAddrReady := true.B // Need to force the memory interface to enter a state where it provides valid data
4545
wAddrDelayReg := io.cache.wChannel.wAddr.bits
4646

@@ -50,7 +50,7 @@ class CacheMemToOcpBurstMasterAdapter(addrWidth: Int, dataWidth: Int, burstLen:
5050

5151
is(sReadBurst) {
5252
val nextBurstCount = WireDefault(0.U(log2Up(burstLen).W))
53-
nextBurstCount := Mux(io.ocpBurst.S.Resp === ocp.OcpResp.DVA, rBurstCountReg + 1.U, rBurstCountReg)
53+
nextBurstCount := Mux(io.ocpBurst.S.Resp === OcpResp.DVA, rBurstCountReg + 1.U, rBurstCountReg)
5454

5555
when(rBurstCountReg === (burstLen - 1).U) {
5656
rLast := true.B
@@ -62,7 +62,7 @@ class CacheMemToOcpBurstMasterAdapter(addrWidth: Int, dataWidth: Int, burstLen:
6262
}
6363

6464
is(sWriteDelay) {
65-
mCmd := ocp.OcpCmd.WR
65+
mCmd := OcpCmd.WR
6666
mAddr := wAddrDelayReg
6767
mDataByteEn := (math.pow(2, dataWidth / 8) - 1).toInt.U
6868

@@ -86,7 +86,7 @@ class CacheMemToOcpBurstMasterAdapter(addrWidth: Int, dataWidth: Int, burstLen:
8686
}
8787

8888
is(sWriteAccept) {
89-
when(io.ocpBurst.S.Resp === ocp.OcpResp.DVA) {
89+
when(io.ocpBurst.S.Resp === OcpResp.DVA) {
9090
stateReg := sIdle
9191
}
9292
}
@@ -99,7 +99,7 @@ class CacheMemToOcpBurstMasterAdapter(addrWidth: Int, dataWidth: Int, burstLen:
9999
io.ocpBurst.M.DataValid := io.cache.wChannel.wData.valid
100100

101101
io.cache.rChannel.rAddr.ready := rAddrReady
102-
io.cache.rChannel.rData.valid := io.ocpBurst.S.Resp === ocp.OcpResp.DVA
102+
io.cache.rChannel.rData.valid := io.ocpBurst.S.Resp === OcpResp.DVA
103103
io.cache.rChannel.rData.bits := io.ocpBurst.S.Data
104104
io.cache.rChannel.rLast := rLast
105105

src/main/scala/caches/hardware/pipelined/OcpBurstSlaveToCacheRequestAdapter.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package caches.hardware.pipelined
22

3-
import ocp._
3+
import caches.hardware.ocp._
44
import chisel3._
55
import chisel3.util._
66

77
class OcpBurstSlaveToCacheRequestAdapter(addrWidth: Int, dataWidth: Int, burstLen: Int) extends Module {
8-
val io = IO(new Bundle{
8+
val io = IO(new Bundle {
99
val ocpBurst = new OcpBurstSlavePort(addrWidth, dataWidth, burstLen)
1010
val corePort = Flipped(new CacheCorePortIO(addrWidth, dataWidth * burstLen, reqIdWidth = 1))
1111
})
@@ -22,7 +22,7 @@ class OcpBurstSlaveToCacheRequestAdapter(addrWidth: Int, dataWidth: Int, burstLe
2222
val dateByteEnRegs = RegInit(VecInit(Seq.fill(burstLen)(0.U((dataWidth / 8).W))))
2323

2424
// Default signal assignments
25-
val ocpSResp = WireDefault(ocp.OcpResp.NULL)
25+
val ocpSResp = WireDefault(OcpResp.NULL)
2626
val ocpSData = WireDefault(0.U(dataWidth.W))
2727
val ocpSCmdAccept = WireDefault(0.U(1.W))
2828
val ocpSDataAccept = WireDefault(0.U(1.W))
@@ -35,11 +35,11 @@ class OcpBurstSlaveToCacheRequestAdapter(addrWidth: Int, dataWidth: Int, burstLe
3535
switch(stateReg) {
3636
is(sIdle) {
3737

38-
when(io.ocpBurst.M.Cmd === ocp.OcpCmd.RD) {
38+
when(io.ocpBurst.M.Cmd === OcpCmd.RD) {
3939
ocpSCmdAccept := 1.U
4040
addrReg := io.ocpBurst.M.Addr
4141
stateReg := sWaitReadAccept
42-
} .elsewhen (io.ocpBurst.M.Cmd === ocp.OcpCmd.WR) {
42+
}.elsewhen(io.ocpBurst.M.Cmd === OcpCmd.WR) {
4343
// Need to latch rest of the data over multiple cycles
4444
ocpSDataAccept := 1.U
4545
ocpSCmdAccept := 1.U
@@ -79,7 +79,7 @@ class OcpBurstSlaveToCacheRequestAdapter(addrWidth: Int, dataWidth: Int, burstLe
7979
nextDataCount := 0.U
8080
}
8181

82-
ocpSResp := ocp.OcpResp.DVA
82+
ocpSResp := OcpResp.DVA
8383
ocpSData := dataRegs(dataCountReg)
8484
dataCountReg := nextDataCount
8585
}
@@ -113,9 +113,9 @@ class OcpBurstSlaveToCacheRequestAdapter(addrWidth: Int, dataWidth: Int, burstLe
113113
}
114114
}
115115

116-
is (sWaitWriteResp) {
116+
is(sWaitWriteResp) {
117117
when(io.corePort.resp.reqId.valid) {
118-
ocpSResp := ocp.OcpResp.DVA
118+
ocpSResp := OcpResp.DVA
119119
stateReg := sIdle
120120
}
121121
}

src/main/scala/caches/hardware/pipelined/OcpCacheWrapper.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package caches.hardware.pipelined
22

3-
import ocp._
3+
import caches.hardware.ocp._
44
import chisel3._
55
import chisel3.util._
6-
import caches.hardware.util.Constants.CONTENTION_LIMIT_WIDTH
76

87
class OcpCacheWrapperPort(
98
nCores: Int,
@@ -20,14 +19,14 @@ class OcpCacheWrapperPort(
2019
}
2120

2221
class OcpCacheWrapper(
23-
nCores: Int,
24-
addrWidth: Int,
25-
coreDataWidth: Int,
26-
coreBurstLen: Int,
27-
memDataWidth: Int,
28-
memBurstLen: Int,
29-
l2Cache: () => SharedPipelinedCache
30-
) extends Module {
22+
nCores: Int,
23+
addrWidth: Int,
24+
coreDataWidth: Int,
25+
coreBurstLen: Int,
26+
memDataWidth: Int,
27+
memBurstLen: Int,
28+
l2Cache: () => SharedPipelinedCache
29+
) extends Module {
3130

3231
val cache = Module(l2Cache())
3332
val l2SchedulerDataWidth = cache.schedulerDataWidth

src/main/scala/caches/hardware/pipelined/OcpCoreSlaveToSchedulerAdapter.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package caches.hardware.pipelined
22

3-
import caches.hardware.reppol.{SchedulerCmd, SchedulerControlIO}
3+
import caches.hardware.ocp._
4+
import caches.hardware.reppol._
45
import chisel3._
56
import chisel3.util._
6-
import ocp.OcpCoreSlavePort
77

88
class OcpCoreSlaveToSchedulerAdapter(nCores: Int, dataWidth: Int) extends Module() {
99
val io = IO(new Bundle {
@@ -15,22 +15,22 @@ class OcpCoreSlaveToSchedulerAdapter(nCores: Int, dataWidth: Int) extends Module
1515
val addr = RegNext(io.core.M.Addr, 0.U)
1616
val wData = RegNext(io.core.M.Data, 0.U)
1717

18-
val sResp = WireDefault(ocp.OcpResp.NULL)
18+
val sResp = WireDefault(OcpResp.NULL)
1919
val sData = WireDefault(0.U(dataWidth.W))
2020

21-
when(cmd === ocp.OcpCmd.WR || cmd === ocp.OcpCmd.RD) {
22-
sResp := ocp.OcpResp.DVA
21+
when(cmd === OcpCmd.WR || cmd === OcpCmd.RD) {
22+
sResp := OcpResp.DVA
2323
}
2424

2525
val schCmd = WireDefault(SchedulerCmd.NULL)
2626
switch(cmd) {
27-
is(ocp.OcpCmd.IDLE) {
27+
is(OcpCmd.IDLE) {
2828
schCmd := SchedulerCmd.NULL
2929
}
30-
is(ocp.OcpCmd.WR) {
30+
is(OcpCmd.WR) {
3131
schCmd := SchedulerCmd.WR
3232
}
33-
is(ocp.OcpCmd.RD) {
33+
is(OcpCmd.RD) {
3434
schCmd := SchedulerCmd.RD
3535
}
3636
}

0 commit comments

Comments
 (0)