8
8
9
9
10
10
class _RTIOBankO (Module ):
11
- def __init__ (self , rbus , counter_width , fine_ts_width ,
12
- fifo_depth , counter_init ):
11
+ def __init__ (self , rbus , counter , fine_ts_width , fifo_depth ):
12
+ counter_width = flen ( counter )
13
13
self .sel = Signal (max = len (rbus ))
14
14
self .timestamp = Signal (counter_width + fine_ts_width )
15
15
self .value = Signal (2 )
@@ -18,16 +18,13 @@ def __init__(self, rbus, counter_width, fine_ts_width,
18
18
self .replace = Signal ()
19
19
self .underflow = Signal ()
20
20
self .level = Signal (bits_for (fifo_depth ))
21
- self .counter = Signal (counter_width , reset = counter_init )
22
21
23
22
# # #
24
23
25
- self .sync += self .counter .eq (self .counter + 1 )
26
-
27
24
# detect underflows
28
25
self .sync += \
29
26
If ((self .we & self .writable ) | self .replace ,
30
- If (self .timestamp [fine_ts_width :] < self . counter + 2 ,
27
+ If (self .timestamp [fine_ts_width :] < counter + 2 ,
31
28
self .underflow .eq (1 ))
32
29
)
33
30
@@ -50,7 +47,7 @@ def __init__(self, rbus, counter_width, fine_ts_width,
50
47
# FIFO read
51
48
self .comb += [
52
49
chif .o_stb .eq (fifo .readable &
53
- (fifo .dout .timestamp [fine_ts_width :] == self . counter )),
50
+ (fifo .dout .timestamp [fine_ts_width :] == counter )),
54
51
chif .o_value .eq (fifo .dout .value ),
55
52
fifo .re .eq (chif .o_stb )
56
53
]
@@ -66,7 +63,8 @@ def __init__(self, rbus, counter_width, fine_ts_width,
66
63
67
64
68
65
class _RTIOBankI (Module ):
69
- def __init__ (self , rbus , counter_width , fine_ts_width , fifo_depth ):
66
+ def __init__ (self , rbus , counter , fine_ts_width , fifo_depth ):
67
+ counter_width = flen (counter )
70
68
self .sel = Signal (max = len (rbus ))
71
69
self .timestamp = Signal (counter_width + fine_ts_width )
72
70
self .value = Signal ()
@@ -75,10 +73,7 @@ def __init__(self, rbus, counter_width, fine_ts_width, fifo_depth):
75
73
self .overflow = Signal ()
76
74
self .pileup = Signal ()
77
75
78
- ###
79
-
80
- counter = Signal (counter_width )
81
- self .sync += counter .eq (counter + 1 )
76
+ # # #
82
77
83
78
timestamps = []
84
79
values = []
@@ -143,17 +138,30 @@ class RTIO(Module, AutoCSR):
143
138
def __init__ (self , phy , clk_freq , counter_width = 32 , ofifo_depth = 64 , ififo_depth = 64 ):
144
139
fine_ts_width = get_fine_ts_width (phy .rbus )
145
140
141
+ # Counters
142
+ reset_counter = Signal ()
143
+ o_counter = Signal (counter_width , reset = phy .loopback_latency )
144
+ i_counter = Signal (counter_width )
145
+ self .sync += \
146
+ If (reset_counter ,
147
+ o_counter .eq (o_counter .reset ),
148
+ i_counter .eq (i_counter .reset )
149
+ ).Else (
150
+ o_counter .eq (o_counter + 1 ),
151
+ i_counter .eq (i_counter + 1 )
152
+ )
153
+
146
154
# Submodules
147
155
self .submodules .bank_o = InsertReset (_RTIOBankO (
148
156
phy .rbus ,
149
- counter_width , fine_ts_width , ofifo_depth ,
150
- phy .loopback_latency ))
157
+ o_counter , fine_ts_width , ofifo_depth ))
151
158
self .submodules .bank_i = InsertReset (_RTIOBankI (
152
159
phy .rbus ,
153
- counter_width , fine_ts_width , ofifo_depth ))
160
+ i_counter , fine_ts_width , ofifo_depth ))
154
161
155
162
# CSRs
156
- self ._r_reset = CSRStorage (reset = 1 )
163
+ self ._r_reset_logic = CSRStorage (reset = 1 )
164
+ self ._r_reset_counter = CSRStorage (reset = 1 )
157
165
self ._r_chan_sel = CSRStorage (flen (self .bank_o .sel ))
158
166
159
167
self ._r_oe = CSR ()
@@ -194,7 +202,7 @@ def __init__(self, phy, clk_freq, counter_width=32, ofifo_depth=64, ififo_depth=
194
202
195
203
# Output/Gate
196
204
self .comb += [
197
- self .bank_o .reset .eq (self ._r_reset .storage ),
205
+ self .bank_o .reset .eq (self ._r_reset_logic .storage ),
198
206
self .bank_o .sel .eq (self ._r_chan_sel .storage ),
199
207
self .bank_o .timestamp .eq (self ._r_o_timestamp .storage ),
200
208
self .bank_o .value .eq (self ._r_o_value .storage ),
@@ -207,7 +215,7 @@ def __init__(self, phy, clk_freq, counter_width=32, ofifo_depth=64, ififo_depth=
207
215
208
216
# Input
209
217
self .comb += [
210
- self .bank_i .reset .eq (self ._r_reset .storage ),
218
+ self .bank_i .reset .eq (self ._r_reset_logic .storage ),
211
219
self .bank_i .sel .eq (self ._r_chan_sel .storage ),
212
220
self ._r_i_timestamp .status .eq (self .bank_i .timestamp ),
213
221
self ._r_i_value .status .eq (self .bank_i .value ),
@@ -217,11 +225,12 @@ def __init__(self, phy, clk_freq, counter_width=32, ofifo_depth=64, ififo_depth=
217
225
Cat (self .bank_i .overflow , self .bank_i .pileup ))
218
226
]
219
227
220
- # Counter
228
+ # Counter access
229
+ self .comb += reset_counter .eq (self ._r_reset_counter .storage )
221
230
self .sync += \
222
231
If (self ._r_counter_update .re ,
223
232
self ._r_counter .status .eq (Cat (Replicate (0 , fine_ts_width ),
224
- self . bank_o . counter ))
233
+ o_counter ))
225
234
)
226
235
227
236
# Frequency
0 commit comments