1
0
Fork 0

cxp pipeline: add code source

This commit is contained in:
morgan 2024-09-03 11:36:27 +08:00
parent 0aaf96a459
commit a358f1c930
1 changed files with 61 additions and 13 deletions

View File

@ -6,11 +6,54 @@ from misoc.cores.liteeth_mini.mac.crc import LiteEthMACCRCEngine, LiteEthMACCRCI
def K(x, y): def K(x, y):
return ((y << 5) | x) return ((y << 5) | x)
class Code_Source(Module):
def __init__(self, layout, counts=4):
self.source = stream.Endpoint(layout)
self.stb = Signal()
self.data = Signal.like(self.source.data)
self.k = Signal.like(self.source.k)
# # #
cnt = Signal(max=counts)
clr_cnt = Signal()
inc_cnt = Signal()
self.sync += [
If(clr_cnt,
cnt.eq(cnt.reset),
).Elif(inc_cnt,
cnt.eq(cnt + 1),
)
]
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
clr_cnt.eq(1),
If(self.stb,
NextState("WRITE")
)
)
fsm.act("WRITE",
self.source.stb.eq(1),
self.source.data.eq(self.data),
self.source.k.eq(self.k),
If(cnt == counts - 1,
self.source.eop.eq(1),
If(self.source.ack, NextState("IDLE"))
).Else(
inc_cnt.eq(self.source.ack)
)
)
class Trigger_ACK(Module): class Trigger_ACK(Module):
def __init__(self, layout): def __init__(self, layout):
self.ack = Signal() self.ack = Signal()
self.source = source = stream.Endpoint(layout) self.source = stream.Endpoint(layout)
# # # # # #
@ -39,26 +82,26 @@ class Trigger_ACK(Module):
) )
fsm.act("WRITE_ACK0", fsm.act("WRITE_ACK0",
source.stb.eq(1), self.source.stb.eq(1),
source.data.eq(K(28, 6)), self.source.data.eq(K(28, 6)),
source.k.eq(1), self.source.k.eq(1),
If(cnt == 3, If(cnt == 3,
clr_cnt.eq(1), clr_cnt.eq(1),
If(source.ack, NextState("WRITE_ACK1")) If(self.source.ack, NextState("WRITE_ACK1"))
).Else( ).Else(
inc_cnt.eq(source.ack) inc_cnt.eq(self.source.ack)
) )
) )
fsm.act("WRITE_ACK1", fsm.act("WRITE_ACK1",
source.stb.eq(1), self.source.stb.eq(1),
source.data.eq(0x01), self.source.data.eq(0x01),
source.k.eq(0), self.source.k.eq(0),
If(cnt == 3, If(cnt == 3,
source.eop.eq(1), self.source.eop.eq(1),
If(source.ack, NextState("IDLE")) If(self.source.ack, NextState("IDLE"))
).Else( ).Else(
inc_cnt.eq(source.ack) inc_cnt.eq(self.source.ack)
) )
) )
@ -74,7 +117,12 @@ class Code_Inserter(Module):
# # # # # #
cnt = Signal(max=counts) assert counts > 0
# TODO: make this cleaner
# FIX this to make it work for counts = 1
cnt = Signal() if counts == 1 else Signal(max=counts)
clr_cnt = Signal() clr_cnt = Signal()
inc_cnt = Signal() inc_cnt = Signal()