@@ -25,40 +25,25 @@ def __init__(self, dw, depth, nslots=2):
25
25
sink .ack .reset = 1
26
26
27
27
# length computation
28
- cnt = Signal (lengthbits )
29
- clr_cnt = Signal ()
30
- inc_cnt = Signal ()
31
- inc_val = Signal (3 )
28
+ increment = Signal (3 )
32
29
self .comb += \
33
30
If (sink .last_be [3 ],
34
- inc_val .eq (1 )
31
+ increment .eq (1 )
35
32
).Elif (sink .last_be [2 ],
36
- inc_val .eq (2 )
33
+ increment .eq (2 )
37
34
).Elif (sink .last_be [1 ],
38
- inc_val .eq (3 )
35
+ increment .eq (3 )
39
36
).Else (
40
- inc_val .eq (4 )
41
- )
42
- self .sync += \
43
- If (clr_cnt ,
44
- cnt .eq (0 )
45
- ).Elif (inc_cnt ,
46
- cnt .eq (cnt + inc_val )
37
+ increment .eq (4 )
47
38
)
39
+ counter = Counter (lengthbits , increment = increment )
40
+ self .submodules += counter
48
41
49
42
# slot computation
50
- slot = Signal (slotbits )
51
- inc_slot = Signal ()
52
- self .sync += \
53
- If (inc_slot ,
54
- If (slot == nslots - 1 ,
55
- slot .eq (0 ),
56
- ).Else (
57
- slot .eq (slot + 1 )
58
- )
59
- )
43
+ slot = Counter (slotbits )
44
+ self .submodules += slot
45
+
60
46
ongoing = Signal ()
61
- discard = Signal ()
62
47
63
48
# status fifo
64
49
fifo = SyncFIFO ([("slot" , slotbits ), ("length" , lengthbits )], nslots )
@@ -72,13 +57,13 @@ def __init__(self, dw, depth, nslots=2):
72
57
If (sink .stb & sink .sop ,
73
58
If (fifo .sink .ack ,
74
59
ongoing .eq (1 ),
75
- inc_cnt .eq (1 ),
60
+ counter . ce .eq (1 ),
76
61
NextState ("WRITE" )
77
62
)
78
63
)
79
64
)
80
65
fsm .act ("WRITE" ,
81
- inc_cnt .eq (sink .stb ),
66
+ counter . ce .eq (sink .stb ),
82
67
ongoing .eq (1 ),
83
68
If (sink .stb & sink .eop ,
84
69
If ((sink .error & sink .last_be ) != 0 ,
@@ -89,18 +74,19 @@ def __init__(self, dw, depth, nslots=2):
89
74
)
90
75
)
91
76
fsm .act ("DISCARD" ,
92
- clr_cnt .eq (1 ),
77
+ counter . reset .eq (1 ),
93
78
NextState ("IDLE" )
94
79
)
80
+ self .comb += [
81
+ fifo .sink .slot .eq (slot .value ),
82
+ fifo .sink .length .eq (counter .value )
83
+ ]
95
84
fsm .act ("TERMINATE" ,
96
- clr_cnt .eq (1 ),
97
- inc_slot .eq (1 ),
85
+ counter . reset .eq (1 ),
86
+ slot . ce .eq (1 ),
98
87
fifo .sink .stb .eq (1 ),
99
- fifo .sink .slot .eq (slot ),
100
- fifo .sink .length .eq (cnt ),
101
88
NextState ("IDLE" )
102
89
)
103
-
104
90
self .comb += [
105
91
fifo .source .ack .eq (self .ev .available .clear ),
106
92
self .ev .available .trigger .eq (fifo .source .stb ),
@@ -120,13 +106,13 @@ def __init__(self, dw, depth, nslots=2):
120
106
cases = {}
121
107
for n , port in enumerate (ports ):
122
108
cases [n ] = [
123
- ports [n ].adr .eq (cnt [2 :]),
109
+ ports [n ].adr .eq (counter . value [2 :]),
124
110
ports [n ].dat_w .eq (sink .data ),
125
111
If (sink .stb & ongoing ,
126
112
ports [n ].we .eq (0xf )
127
113
)
128
114
]
129
- self .comb += Case (slot , cases )
115
+ self .comb += Case (slot . value , cases )
130
116
131
117
132
118
class LiteEthMACSRAMReader (Module , AutoCSR ):
@@ -159,16 +145,7 @@ def __init__(self, dw, depth, nslots=2):
159
145
]
160
146
161
147
# length computation
162
- cnt = Signal (lengthbits )
163
- clr_cnt = Signal ()
164
- inc_cnt = Signal ()
165
-
166
- self .sync += \
167
- If (clr_cnt ,
168
- cnt .eq (0 )
169
- ).Elif (inc_cnt ,
170
- cnt .eq (cnt + 4 )
171
- )
148
+ self .submodules .counter = counter = Counter (lengthbits , increment = 4 )
172
149
173
150
# fsm
174
151
first = Signal ()
@@ -179,7 +156,7 @@ def __init__(self, dw, depth, nslots=2):
179
156
self .submodules += fsm
180
157
181
158
fsm .act ("IDLE" ,
182
- clr_cnt .eq (1 ),
159
+ counter . reset .eq (1 ),
183
160
If (fifo .source .stb ,
184
161
NextState ("CHECK" )
185
162
)
@@ -192,10 +169,7 @@ def __init__(self, dw, depth, nslots=2):
192
169
)
193
170
)
194
171
length_lsb = fifo .source .length [0 :2 ]
195
- fsm .act ("SEND" ,
196
- source .stb .eq (1 ),
197
- source .sop .eq (first ),
198
- source .eop .eq (last ),
172
+ self .comb += [
199
173
If (last ,
200
174
If (length_lsb == 3 ,
201
175
source .last_be .eq (0b0010 )
@@ -206,9 +180,14 @@ def __init__(self, dw, depth, nslots=2):
206
180
).Else (
207
181
source .last_be .eq (0b0001 )
208
182
)
209
- ),
183
+ )
184
+ ]
185
+ fsm .act ("SEND" ,
186
+ source .stb .eq (1 ),
187
+ source .sop .eq (first ),
188
+ source .eop .eq (last ),
210
189
If (source .ack ,
211
- inc_cnt .eq (~ last ),
190
+ counter . ce .eq (~ last ),
212
191
NextState ("CHECK" )
213
192
)
214
193
)
@@ -226,7 +205,7 @@ def __init__(self, dw, depth, nslots=2):
226
205
first .eq (0 )
227
206
)
228
207
]
229
- self .comb += last .eq (cnt + 4 >= fifo .source .length )
208
+ self .comb += last .eq (( counter . value + 4 ) >= fifo .source .length )
230
209
self .sync += last_d .eq (last )
231
210
232
211
# memory
@@ -242,7 +221,7 @@ def __init__(self, dw, depth, nslots=2):
242
221
243
222
cases = {}
244
223
for n , port in enumerate (ports ):
245
- self .comb += ports [n ].adr .eq (cnt [2 :])
224
+ self .comb += ports [n ].adr .eq (counter . value [2 :])
246
225
cases [n ] = [source .data .eq (port .dat_r )]
247
226
self .comb += Case (rd_slot , cases )
248
227
0 commit comments