@@ -21,8 +21,8 @@ architecture arch of sample_stream_tb is
2121
2222 -- Clock half periods
2323 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 ;
2626
2727 -- Clocks
2828 signal fx3_clock : std_logic := '1' ;
@@ -31,6 +31,12 @@ architecture arch of sample_stream_tb is
3131
3232 signal reset : std_logic := '1' ;
3333
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+
3440 -- TX Signalling
3541 signal tx_enable : std_logic ;
3642 signal tx_native_i : signed (11 downto 0 ) ;
@@ -69,12 +75,12 @@ architecture arch of sample_stream_tb is
6975 -- FIFO type
7076 type fifo_t is record
7177 aclr : std_logic ;
72- data : std_logic_vector ( 31 downto 0 ) ;
78+ data : std_logic_vector ;
7379 rdclk : std_logic ;
7480 rdreq : std_logic ;
7581 wrclk : std_logic ;
7682 wrreq : std_logic ;
77- q : std_logic_vector ( 31 downto 0 ) ;
83+ q : std_logic_vector ;
7884 rdempty : std_logic ;
7985 rdfull : std_logic ;
8086 rdusedw : std_logic_vector ;
@@ -83,15 +89,42 @@ architecture arch of sample_stream_tb is
8389 wrusedw : std_logic_vector ;
8490 end record ;
8591
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 ) ) ;
8997
9098 alias lms_tx_clock : std_logic is tx_clock ;
9199 alias lms_rx_clock : std_logic is rx_clock ;
92100
93101begin
94102
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+
95128 -- Clock creation
96129 fx3_clock <= not fx3_clock after FX3_HALF_PERIOD ;
97130 tx_clock <= not tx_clock after TX_HALF_PERIOD ;
@@ -118,6 +151,26 @@ begin
118151 wrusedw => txfifo.wrusedw
119152 ) ;
120153
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+
121174 -- RX FIFO
122175 rxfifo.rdclk <= fx3_clock ;
123176 rxfifo.wrclk <= rx_clock ;
@@ -138,17 +191,47 @@ begin
138191 wrusedw => rxfifo.wrusedw
139192 ) ;
140193
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+
141214 -- TX FIFO Reader
142215 U_fifo_reader : entity work.fifo_reader
143216 port map (
144217 clock => tx_clock,
145218 reset => reset,
146219 enable => tx_enable,
147220
221+ usb_speed => usb_speed,
222+ meta_en => meta_en,
223+ timestamp => tx_timestamp,
224+
225+ fifo_usedw => txfifo.rdusedw,
148226 fifo_read => txfifo.rdreq,
149227 fifo_empty => txfifo.rdempty,
150228 fifo_data => txfifo.q,
151229
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+
152235 out_i => tx_sample_i,
153236 out_q => tx_sample_q,
154237 out_valid => tx_sample_valid,
@@ -157,13 +240,18 @@ begin
157240 underflow_count => underflow_count,
158241 underflow_duration => underflow_duration
159242 ) ;
243+
160244 -- RX FIFO Writer
161245 U_fifo_writer : entity work.fifo_writer
162246 port map (
163247 clock => rx_clock,
164248 reset => reset,
165249 enable => rx_enable,
166250
251+ usb_speed => usb_speed,
252+ meta_en => meta_en,
253+ timestamp => rx_timestamp,
254+
167255 in_i => rx_sample_i,
168256 in_q => rx_sample_q,
169257 in_valid => rx_sample_valid,
@@ -172,6 +260,12 @@ begin
172260 fifo_write => rxfifo.wrreq,
173261 fifo_full => rxfifo.wrfull,
174262 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,
175269
176270 overflow_led => overflow_led,
177271 overflow_count => overflow_count,
@@ -243,27 +337,57 @@ begin
243337 variable dang : real := MATH_PI / 100.0 ;
244338 variable sample_i : signed (15 downto 0 ) ;
245339 variable sample_q : signed (15 downto 0 ) ;
340+ variable ts : integer ;
246341 begin
247342 if ( reset = '1' ) then
248343 txfifo.data <= (others => '0' ) ;
249344 txfifo.wrreq <= '0' ;
250345 wait until reset = '0' ;
251346 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 ;
261387 end loop ;
262- txfifo.wrreq <= '0' ;
263- if ( CHECK_UNDERFLOW ) then
264- nop( fx3_clock, 3000 ) ;
265- end if ;
388+ nop(fx3_clock, 100000 ) ;
266389 end loop ;
390+ wait ;
267391 end process ;
268392
269393 -- RX FIFO Reader
@@ -299,7 +423,7 @@ begin
299423 nop( fx3_clock, 10 ) ;
300424 rx_enable <= '1' ;
301425 tx_enable <= '1' ;
302- nop( fx3_clock, 100000 ) ;
426+ nop( fx3_clock, 2000000 ) ;
303427 report " -- End of Simulation --" ;
304428 stop (2 ) ;
305429 wait ;
0 commit comments