1 from liteeth
.common
import *
2 from liteeth
.mac
.common
import *
4 class LiteEthMACPreambleInserter(Module
):
5 def __init__(self
, d_w
):
6 self
.sink
= Sink(eth_description(d_w
))
7 self
.source
= Source(eth_description(d_w
))
11 preamble
= Signal(64, reset
=eth_preamble
)
13 cnt
= Signal(max=cnt_max
+1)
24 fsm
= FSM(reset_state
="IDLE")
25 self
.submodules
+= fsm
29 If(self
.sink
.stb
& self
.sink
.sop
,
35 self
.source
.stb
.eq(1),
36 self
.source
.sop
.eq(cnt
==0),
37 chooser(preamble
, cnt
, self
.source
.d
),
39 If(self
.source
.ack
, NextState("COPY"))
41 inc_cnt
.eq(self
.source
.ack
)
45 Record
.connect(self
.sink
, self
.source
),
46 self
.source
.sop
.eq(0),
48 If(self
.sink
.stb
& self
.sink
.eop
& self
.source
.ack
,
53 class LiteEthMACPreambleChecker(Module
):
54 def __init__(self
, d_w
):
55 self
.sink
= Sink(eth_description(d_w
))
56 self
.source
= Source(eth_description(d_w
))
60 preamble
= Signal(64, reset
=eth_preamble
)
61 cnt_max
= (64//d_w
) - 1
62 cnt
= Signal(max=cnt_max
+1)
74 clr_discard
= Signal()
75 set_discard
= Signal()
97 chooser(preamble
, cnt
, ref
),
98 match
.eq(self
.sink
.d
== ref
)
101 fsm
= FSM(reset_state
="IDLE")
102 self
.submodules
+= fsm
108 If(self
.sink
.stb
& self
.sink
.sop
,
112 set_discard
.eq(~match
),
119 set_discard
.eq(~match
),
121 If(discard |
(~match
),
133 Record
.connect(self
.sink
, self
.source
),
134 self
.source
.sop
.eq(sop
),
135 clr_sop
.eq(self
.source
.stb
& self
.source
.ack
),
137 If(self
.source
.stb
& self
.source
.eop
& self
.source
.ack
,