Skip to content

Commit 25e46eb

Browse files
committed
feat: add tcl3 processor module
1 parent d1a5ab2 commit 25e46eb

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package treecorel3
2+
3+
import chisel._
4+
import chisel.uitl._
5+
6+
class MemArbiterIO(implicit val p: Parameters) extends Bundle {
7+
val icache = Flipped(new NastiIO)
8+
val dcache = Flipped(new NastiIO)
9+
val nasti = new NastiIO
10+
}
11+
12+
class MemArbiter(implicit p: Parameters) extends Module {
13+
val io = IO(new MemArbiterIO)
14+
15+
val s_IDLE :: s_ICACHE_READ :: s_DCACHE_READ :: s_DCACHE_WRITE :: s_DCACHE_ACK :: Nil = Enum(5)
16+
val state = RegInit(s_IDLE)
17+
18+
// write address
19+
io.nasti.aw.bits := io.dcache.aw.bits
20+
io.nasti.aw.valid := io.dcache.aw.valid && state === s_IDLE
21+
io.dcache.aw.ready := io.nasti.aw.ready && state === s_IDLE
22+
io.icache.aw := DontCare
23+
24+
// write data
25+
io.nasti.w.bits := io.dcache.w.bits
26+
io.nasti.w.valid := io.dcache.w.valid && state === s_DCACHE_WRITE
27+
io.dcache.w.ready := io.nasti.w.ready && state === s_DCACHE_WRITE
28+
io.icache.w := DontCare
29+
30+
// write ack
31+
io.dcache.b.bits := io.nasti.b.bits
32+
io.dcache.b.valid := io.nasti.b.valid && state === s_DCACHE_ACK
33+
io.nasti.b.ready := io.dcache.b.ready && state === s_DCACHE_ACK
34+
io.icache.b := DontCare
35+
36+
// Read Address
37+
io.nasti.ar.bits := NastiReadAddressChannel(
38+
Mux(io.dcache.ar.valid, io.dcache.ar.bits.id, io.icache.ar.bits.id),
39+
Mux(io.dcache.ar.valid, io.dcache.ar.bits.addr, io.icache.ar.bits.addr),
40+
Mux(io.dcache.ar.valid, io.dcache.ar.bits.size, io.icache.ar.bits.size),
41+
Mux(io.dcache.ar.valid, io.dcache.ar.bits.len, io.icache.ar.bits.len)
42+
)
43+
io.nasti.ar.valid := (io.icache.ar.valid || io.dcache.ar.valid) &&
44+
!io.nasti.aw.valid && state === s_IDLE
45+
io.dcache.ar.ready := io.nasti.ar.ready && !io.nasti.aw.valid && state === s_IDLE
46+
io.icache.ar.ready := io.dcache.ar.ready && !io.dcache.ar.valid
47+
48+
// Read Data
49+
io.icache.r.bits := io.nasti.r.bits
50+
io.dcache.r.bits := io.nasti.r.bits
51+
io.icache.r.valid := io.nasti.r.valid && state === s_ICACHE_READ
52+
io.dcache.r.valid := io.nasti.r.valid && state === s_DCACHE_READ
53+
io.nasti.r.ready := io.icache.r.ready && state === s_ICACHE_READ ||
54+
io.dcache.r.ready && state === s_DCACHE_READ
55+
56+
switch(state) {
57+
is(s_IDLE) {
58+
when(io.dcache.aw.fire()) {
59+
state := s_DCACHE_WRITE
60+
}.elsewhen(io.dcache.ar.fire()) {
61+
state := s_DCACHE_READ
62+
}.elsewhen(io.icache.ar.fire()) {
63+
state := s_ICACHE_READ
64+
}
65+
}
66+
is(s_ICACHE_READ) {
67+
when(io.nasti.r.fire() && io.nasti.r.bits.last) {
68+
state := s_IDLE
69+
}
70+
}
71+
is(s_DCACHE_READ) {
72+
when(io.nasti.r.fire() && io.nasti.r.bits.last) {
73+
state := s_IDLE
74+
}
75+
}
76+
is(s_DCACHE_WRITE) {
77+
when(io.dcache.w.fire() && io.dcache.w.bits.last) {
78+
state := s_DCACHE_ACK
79+
}
80+
}
81+
is(s_DCACHE_ACK) {
82+
when(io.nasti.b.fire()) {
83+
state := s_IDLE
84+
}
85+
}
86+
}
87+
}
88+
89+
class ProcessorIO(implicit val p: Parameters) extends Bundle {
90+
val host = new HostIO
91+
val nasti = new NastiIO
92+
}
93+
94+
class Processor(implicit p: Parameters) extends Module {
95+
val io = IO(new ProcessorIO)
96+
val core = Module(new Core)
97+
val icache = Module(new Cache)
98+
val dcache = Module(new Cache)
99+
val arb = Module(new MemArbiter)
100+
101+
io.host <> core.io.host
102+
core.io.icache <> icache.io.cpu
103+
core.io.dcache <> dcache.io.cpu
104+
arb.io.icache <> icache.io.nasti
105+
arb.io.dcache <> dcache.io.nasti
106+
io.nasti <> arb.io.nasti
107+
}

0 commit comments

Comments
 (0)