@@ -21,8 +21,8 @@ architecture arch of sample_stream_tb is
21
21
22
22
-- Clock half periods
23
23
constant FX3_HALF_PERIOD : time := 1.0 / (100.0e6 )/ 2.0 * 1 sec ;
24
- constant TX_HALF_PERIOD : time := 1.0 / (40 .0e6 )/ 2.0 * 1 sec ;
25
- constant RX_HALF_PERIOD : time := 1.0 / (40 .0e6 )/ 2.0 * 1 sec ;
24
+ constant TX_HALF_PERIOD : time := 1.0 / (9 .0e6 )/ 2.0 * 1 sec ;
25
+ constant RX_HALF_PERIOD : time := 1.0 / (9 .0e6 )/ 2.0 * 1 sec ;
26
26
27
27
-- Clocks
28
28
signal fx3_clock : std_logic := '1' ;
@@ -31,6 +31,12 @@ architecture arch of sample_stream_tb is
31
31
32
32
signal reset : std_logic := '1' ;
33
33
34
+ -- Configuration
35
+ signal usb_speed : std_logic ;
36
+ signal meta_en : std_logic ;
37
+ signal rx_timestamp : unsigned (63 downto 0 ) := (others => '0' ) ;
38
+ signal tx_timestamp : unsigned (63 downto 0 ) := (others => '0' ) ;
39
+
34
40
-- TX Signalling
35
41
signal tx_enable : std_logic ;
36
42
signal tx_native_i : signed (11 downto 0 ) ;
@@ -69,12 +75,12 @@ architecture arch of sample_stream_tb is
69
75
-- FIFO type
70
76
type fifo_t is record
71
77
aclr : std_logic ;
72
- data : std_logic_vector ( 31 downto 0 ) ;
78
+ data : std_logic_vector ;
73
79
rdclk : std_logic ;
74
80
rdreq : std_logic ;
75
81
wrclk : std_logic ;
76
82
wrreq : std_logic ;
77
- q : std_logic_vector ( 31 downto 0 ) ;
83
+ q : std_logic_vector ;
78
84
rdempty : std_logic ;
79
85
rdfull : std_logic ;
80
86
rdusedw : std_logic_vector ;
@@ -83,15 +89,42 @@ architecture arch of sample_stream_tb is
83
89
wrusedw : std_logic_vector ;
84
90
end record ;
85
91
86
- -- TX FIFO
87
- signal txfifo : fifo_t( rdusedw(11 downto 0 ), wrusedw(11 downto 0 ) ) ;
88
- signal rxfifo : fifo_t( rdusedw( 9 downto 0 ), wrusedw( 9 downto 0 ) ) ;
92
+ -- FIFOs
93
+ signal txfifo : fifo_t( data( 31 downto 0 ), q( 31 downto 0 ), rdusedw(11 downto 0 ), wrusedw(11 downto 0 ) ) ;
94
+ signal rxfifo : fifo_t( data( 31 downto 0 ), q( 31 downto 0 ), rdusedw(11 downto 0 ), wrusedw(11 downto 0 ) ) ;
95
+ signal txmeta : fifo_t( data( 31 downto 0 ), q(127 downto 0 ), rdusedw( 2 downto 0 ), wrusedw( 4 downto 0 ) ) ;
96
+ signal rxmeta : fifo_t( data(127 downto 0 ), q( 31 downto 0 ), rdusedw( 6 downto 0 ), wrusedw( 4 downto 0 ) ) ;
89
97
90
98
alias lms_tx_clock : std_logic is tx_clock ;
91
99
alias lms_rx_clock : std_logic is rx_clock ;
92
100
93
101
begin
94
102
103
+ usb_speed <= '0' ;
104
+ meta_en <= '1' ;
105
+
106
+ increment_tx_ts : process (tx_clock)
107
+ variable ping : boolean := true ;
108
+ begin
109
+ if ( rising_edge (tx_clock) ) then
110
+ ping := not ping ;
111
+ if ( ping = true ) then
112
+ tx_timestamp <= tx_timestamp + 1 ;
113
+ end if ;
114
+ end if ;
115
+ end process ;
116
+
117
+ increment_rx_ts : process (rx_clock)
118
+ variable ping : boolean := true ;
119
+ begin
120
+ if ( rising_edge (rx_clock) ) then
121
+ ping := not ping ;
122
+ if ( ping = true ) then
123
+ rx_timestamp <= rx_timestamp + 1 ;
124
+ end if ;
125
+ end if ;
126
+ end process ;
127
+
95
128
-- Clock creation
96
129
fx3_clock <= not fx3_clock after FX3_HALF_PERIOD ;
97
130
tx_clock <= not tx_clock after TX_HALF_PERIOD ;
@@ -118,6 +151,26 @@ begin
118
151
wrusedw => txfifo.wrusedw
119
152
) ;
120
153
154
+ -- TX Meta FIFO
155
+ txmeta.rdclk <= tx_clock ;
156
+ txmeta.wrclk <= fx3_clock ;
157
+ U_tx_meta_fifo : entity work .tx_meta_fifo
158
+ port map (
159
+ aclr => txmeta.aclr,
160
+ data => txmeta.data,
161
+ rdclk => txmeta.rdclk,
162
+ rdreq => txmeta.rdreq,
163
+ wrclk => txmeta.wrclk,
164
+ wrreq => txmeta.wrreq,
165
+ q => txmeta.q,
166
+ rdempty => txmeta.rdempty,
167
+ rdfull => txmeta.rdfull,
168
+ rdusedw => txmeta.rdusedw,
169
+ wrempty => txmeta.wrempty,
170
+ wrfull => txmeta.wrfull,
171
+ wrusedw => txmeta.wrusedw
172
+ ) ;
173
+
121
174
-- RX FIFO
122
175
rxfifo.rdclk <= fx3_clock ;
123
176
rxfifo.wrclk <= rx_clock ;
@@ -138,17 +191,47 @@ begin
138
191
wrusedw => rxfifo.wrusedw
139
192
) ;
140
193
194
+ -- RX Meta FIFO
195
+ rxmeta.rdclk <= fx3_clock ;
196
+ rxmeta.wrclk <= rx_clock ;
197
+ U_rx_meta_fifo : entity work .rx_meta_fifo
198
+ port map (
199
+ aclr => rxmeta.aclr,
200
+ data => rxmeta.data,
201
+ rdclk => rxmeta.rdclk,
202
+ rdreq => rxmeta.rdreq,
203
+ wrclk => rxmeta.wrclk,
204
+ wrreq => rxmeta.wrreq,
205
+ q => rxmeta.q,
206
+ rdempty => rxmeta.rdempty,
207
+ rdfull => rxmeta.rdfull,
208
+ rdusedw => rxmeta.rdusedw,
209
+ wrempty => rxmeta.wrempty,
210
+ wrfull => rxmeta.wrfull,
211
+ wrusedw => rxmeta.wrusedw
212
+ ) ;
213
+
141
214
-- TX FIFO Reader
142
215
U_fifo_reader : entity work .fifo_reader
143
216
port map (
144
217
clock => tx_clock,
145
218
reset => reset,
146
219
enable => tx_enable,
147
220
221
+ usb_speed => usb_speed,
222
+ meta_en => meta_en,
223
+ timestamp => tx_timestamp,
224
+
225
+ fifo_usedw => txfifo.rdusedw,
148
226
fifo_read => txfifo.rdreq,
149
227
fifo_empty => txfifo.rdempty,
150
228
fifo_data => txfifo.q,
151
229
230
+ meta_fifo_usedw => txmeta.rdusedw,
231
+ meta_fifo_read => txmeta.rdreq,
232
+ meta_fifo_empty => txmeta.rdempty,
233
+ meta_fifo_data => txmeta.q,
234
+
152
235
out_i => tx_sample_i,
153
236
out_q => tx_sample_q,
154
237
out_valid => tx_sample_valid,
@@ -157,13 +240,18 @@ begin
157
240
underflow_count => underflow_count,
158
241
underflow_duration => underflow_duration
159
242
) ;
243
+
160
244
-- RX FIFO Writer
161
245
U_fifo_writer : entity work .fifo_writer
162
246
port map (
163
247
clock => rx_clock,
164
248
reset => reset,
165
249
enable => rx_enable,
166
250
251
+ usb_speed => usb_speed,
252
+ meta_en => meta_en,
253
+ timestamp => rx_timestamp,
254
+
167
255
in_i => rx_sample_i,
168
256
in_q => rx_sample_q,
169
257
in_valid => rx_sample_valid,
@@ -172,6 +260,12 @@ begin
172
260
fifo_write => rxfifo.wrreq,
173
261
fifo_full => rxfifo.wrfull,
174
262
fifo_data => rxfifo.data,
263
+ fifo_usedw => rxfifo.wrusedw,
264
+
265
+ meta_fifo_full => rxmeta.wrfull,
266
+ meta_fifo_usedw => rxmeta.wrusedw,
267
+ meta_fifo_data => rxmeta.data,
268
+ meta_fifo_write => rxmeta.wrreq,
175
269
176
270
overflow_led => overflow_led,
177
271
overflow_count => overflow_count,
@@ -243,27 +337,57 @@ begin
243
337
variable dang : real := MATH_PI / 100.0 ;
244
338
variable sample_i : signed (15 downto 0 ) ;
245
339
variable sample_q : signed (15 downto 0 ) ;
340
+ variable ts : integer ;
246
341
begin
247
342
if ( reset = '1' ) then
248
343
txfifo.data <= (others => '0' ) ;
249
344
txfifo.wrreq <= '0' ;
250
345
wait until reset = '0' ;
251
346
end if ;
252
- while true loop
253
- wait until rising_edge (fx3_clock) and unsigned (txfifo.wrusedw) < 512 ;
254
- for i in 1 to 512 loop
255
- sample_i := to_signed (integer (2047.0 * cos (ang)),sample_i'length );
256
- sample_q := to_signed (integer (2047.0 * sin (ang)),sample_q'length );
257
- txfifo.data <= std_logic_vector (sample_q & sample_i) ;
258
- txfifo.wrreq <= '1' ;
259
- nop( fx3_clock, 1 );
260
- ang := (ang + dang) mod MATH_2_PI ;
347
+ for i in 1 to 100 loop
348
+ wait until rising_edge (fx3_clock) ;
349
+ end loop ;
350
+ for j in 1 to 5 loop
351
+ ts := 16#1000# + (j- 1 )* 10000 ;
352
+ for i in 1 to 5 loop
353
+ wait until rising_edge (fx3_clock) and unsigned (txfifo.wrusedw) < 512 ;
354
+ txmeta.data <= (others => '0' ) ;
355
+ txmeta.data <= x"12345678" ;
356
+ txmeta.wrreq <= '1' ;
357
+ wait until rising_edge (fx3_clock) ;
358
+ txmeta.data <= x"00000000" ;
359
+ wait until rising_edge (fx3_clock) ;
360
+ txmeta.data <= std_logic_vector (to_unsigned (ts,txmeta.data'length )) ;
361
+ ts := ts + 508 ;
362
+ wait until rising_edge (fx3_clock) ;
363
+ txmeta.data <= x"00000000" ;
364
+ wait until rising_edge (fx3_clock) ;
365
+ txmeta.wrreq <= '0' ;
366
+ txmeta.data <= (others => '0' ) ;
367
+ for r in 1 to 508 loop
368
+ if ( r = 1 or r = 508 ) then
369
+ sample_i := (others => '0' ) ;
370
+ sample_q := (others => '0' ) ;
371
+ else
372
+ sample_i := to_signed (2047 , sample_i'length ) ;
373
+ sample_q := to_signed (2047 , sample_q'length ) ;
374
+ end if ;
375
+ -- sample_i := to_signed(integer(2047.0*cos(ang)),sample_i'length);
376
+ -- sample_q := to_signed(integer(2047.0*sin(ang)),sample_q'length);
377
+ txfifo.data <= std_logic_vector (sample_q & sample_i) after 0.1 ns ;
378
+ txfifo.wrreq <= '1' after 0.1 ns ;
379
+ nop( fx3_clock, 1 );
380
+ txfifo.wrreq <= '0' after 0.1 ns ;
381
+ ang := (ang + dang) mod MATH_2_PI ;
382
+ end loop ;
383
+ if ( CHECK_UNDERFLOW ) then
384
+ nop( fx3_clock, 3000 ) ;
385
+ end if ;
386
+ txfifo.data <= (others => 'X' ) after 0.1 ns ;
261
387
end loop ;
262
- txfifo.wrreq <= '0' ;
263
- if ( CHECK_UNDERFLOW ) then
264
- nop( fx3_clock, 3000 ) ;
265
- end if ;
388
+ nop(fx3_clock, 100000 ) ;
266
389
end loop ;
390
+ wait ;
267
391
end process ;
268
392
269
393
-- RX FIFO Reader
@@ -299,7 +423,7 @@ begin
299
423
nop( fx3_clock, 10 ) ;
300
424
rx_enable <= '1' ;
301
425
tx_enable <= '1' ;
302
- nop( fx3_clock, 100000 ) ;
426
+ nop( fx3_clock, 2000000 ) ;
303
427
report " -- End of Simulation --" ;
304
428
stop (2 ) ;
305
429
wait ;
0 commit comments