Debian Codegraph @

hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_model_fifo_stress.vhd

raw
1 -- Copyright (c) 2024 Nuand LLC
2 --
3 -- Permission is hereby granted, free of charge, to any person obtaining a copy
4 -- of this software and associated documentation files (the "Software"), to deal
5 -- in the Software without restriction, including without limitation the rights
6 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 -- copies of the Software, and to permit persons to whom the Software is
8 -- furnished to do so, subject to the following conditions:
9 --
10 -- The above copyright notice and this permission notice shall be included in
11 -- all copies or substantial portions of the Software.
12 --
13 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 -- THE SOFTWARE.
20
21 library ieee;
22 use ieee.std_logic_1164.all;
23 use ieee.numeric_std.all;
24 use ieee.math_real.all;
25 use ieee.math_complex.all;
26
27 library work;
28 use work.util.all;
29 use work.fx3_gpif_p.all;
30
31 architecture micro_dma_fifo_stress of fx3_model is
32
33 constant PCLK_HALF_PERIOD : time := 1 sec * (1.0/100.0e6/2.0);
34 constant START_COUNT : natural := 32;
35 constant BLOCKS_PER_ITERATION : natural := 7;
36 constant ITERATIONS : natural := 4;
37
38 -- Control mapping
39 alias dma0_rx_ack is fx3_ctl( 0);
40 alias dma1_rx_ack is fx3_ctl( 1);
41 alias dma2_tx_ack is fx3_ctl( 2);
42 alias dma3_tx_ack is fx3_ctl( 3);
43 alias dma_rx_enable is fx3_ctl( 4);
44 alias dma_tx_enable is fx3_ctl( 5);
45 alias dma_idle is fx3_ctl( 6);
46 alias system_reset is fx3_ctl( 7);
47 alias dma0_rx_reqx is fx3_ctl( 8);
48 alias dma1_rx_reqx is fx3_ctl(12); -- due to 9 being connected to dclk
49 alias dma2_tx_reqx is fx3_ctl(10);
50 alias dma3_tx_reqx is fx3_ctl(11);
51
52 type gpif_state_t is (IDLE, TX_META, TX_SAMPLES, RX_SAMPLES);
53 signal gpif_state_rx, gpif_state_tx : gpif_state_t;
54
55 signal rx_done : boolean := false;
56 signal tx_done : boolean := false;
57
58 signal rx_data : std_logic_vector(31 downto 0);
59 signal tx_data : std_logic_vector(31 downto 0);
60
61 impure function data_gen (count : natural) return std_logic_vector is
62 variable eight_bit_msw_i : std_logic_vector(7 downto 0);
63 variable eight_bit_msw_q : std_logic_vector(7 downto 0);
64 variable eight_bit_lsw_i : std_logic_vector(7 downto 0);
65 variable eight_bit_lsw_q : std_logic_vector(7 downto 0);
66 variable msw, lsw : std_logic_vector(15 downto 0);
67 begin
68 if( eight_bit_mode_en = '1' ) then
69 eight_bit_lsw_i := std_logic_vector(to_unsigned(count, 8));
70 eight_bit_lsw_q := std_logic_vector(to_unsigned(count+1, 8));
71 eight_bit_msw_i := std_logic_vector(to_unsigned(count+2, 8));
72 eight_bit_msw_q := std_logic_vector(to_unsigned(count+3, 8));
73 lsw := eight_bit_lsw_q & eight_bit_lsw_i;
74 msw := eight_bit_msw_q & eight_bit_msw_i;
75 else
76 msw := std_logic_vector(to_signed(count+1, 16));
77 lsw := std_logic_vector(to_signed(count, 16));
78 end if;
79
80 return (msw & lsw);
81 end function data_gen;
82
83 impure function data_check (count : natural ; rxdata : std_logic_vector(31 downto 0)) return boolean is
84 begin
85 return (rxdata = data_gen(count));
86 end function data_check;
87
88 begin
89
90 -- DCLK which isn't used
91 fx3_ctl(9) <= '0';
92
93 fx3_ctl(3 downto 0) <= (others => 'Z');
94
95 -- Create a 100MHz clock output
96 fx3_pclk <= not fx3_pclk after PCLK_HALF_PERIOD when (not rx_done or not tx_done) else '0';
97
98 -- Doneness
99 done <= rx_done and tx_done;
100
101 rx_sample_stream : process
102 constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
103 variable count : natural := START_COUNT;
104 variable req_time : time;
105 begin
106 gpif_state_rx <= IDLE;
107 dma0_rx_reqx <= '1';
108 dma1_rx_reqx <= '1';
109 dma_rx_enable <= '0';
110 rx_data <= (others => 'U');
111
112 wait until rising_edge(fx3_pclk) and system_reset = '0';
113
114 nop(fx3_pclk, 1000);
115
116 wait until rising_edge(fx3_pclk) and fx3_rx_en = '1';
117
118 wait for 30 us;
119
120 for j in 1 to ITERATIONS loop
121 dma_rx_enable <= '1';
122
123 for i in 1 to BLOCKS_PER_ITERATION loop
124 dma0_rx_reqx <= '0';
125 req_time := now;
126 wait until rising_edge( fx3_pclk ) and dma0_rx_ack = '1';
127 wait until rising_edge( fx3_pclk );
128 dma0_rx_reqx <= '1';
129
130 report "RX iteration " & to_string(j) & " block " & to_string(i) & " delay " & to_string(now - req_time);
131
132 for i in 1 to BLOCK_SIZE loop
133 gpif_state_rx <= RX_SAMPLES;
134 rx_data <= fx3_gpif;
135 wait until rising_edge( fx3_pclk );
136
137 --assert data_check(count, rx_data) severity failure;
138
139 count := (count + 1) mod 2048;
140 gpif_state_rx <= IDLE;
141 rx_data <= (others => 'X');
142 end loop;
143 end loop;
144
145 dma_rx_enable <= '0';
146 wait for 10 us;
147 end loop;
148
149 report "Done with RX sample stream";
150 rx_done <= true;
151 wait;
152 end process;
153
154 tx_sample_stream : process
155 constant TIME_BETWEEN_ITERATIONS : natural := 4593;
156 constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
157 variable count : natural := START_COUNT;
158 variable timestamp_cntr : natural := 400;
159 variable header_len : natural := 0;
160 variable data_out : std_logic_vector(31 downto 0);
161 variable req_time : time;
162 begin
163 gpif_state_tx <= IDLE;
164 dma2_tx_reqx <= '1';
165 dma3_tx_reqx <= '1';
166 dma_tx_enable <= '0';
167 fx3_gpif <= (others =>'Z');
168
169 wait until rising_edge(fx3_pclk) and system_reset = '0';
170
171 nop(fx3_pclk, 1000);
172
173 wait until rising_edge(fx3_pclk) and fx3_tx_en = '1';
174
175 wait for 30 us;
176
177 for k in 1 to ITERATIONS loop
178 dma_tx_enable <= '1';
179
180 for fifo_stress_idx in 1 to 3 loop
181 for j in 1 to BLOCKS_PER_ITERATION loop
182 header_len := 0;
183 dma3_tx_reqx <= '0';
184 req_time := now;
185 wait until rising_edge( fx3_pclk ) and dma3_tx_ack = '1';
186 wait until rising_edge( fx3_pclk );
187 wait until rising_edge( fx3_pclk );
188 wait until rising_edge( fx3_pclk );
189 dma3_tx_reqx <= '1';
190
191 report "TX iteration " & to_string(k) & " block " & to_string(j) & " delay " & to_string(now - req_time);
192
193
194 if( fx3_tx_meta_en = '1') then
195 header_len := 4;
196
197 for i in 1 to 4 loop
198 case (i) is
199 when 1 =>
200 data_out := x"00000000";
201 when 2 =>
202 data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32));
203 if (j = BLOCKS_PER_ITERATION) then
204 timestamp_cntr := timestamp_cntr + TIME_BETWEEN_ITERATIONS;
205 else
206 timestamp_cntr := timestamp_cntr + 254;
207 end if;
208 when 3 =>
209 data_out := (others => '0');
210 when 4 =>
211 data_out := (others => '1');
212 end case;
213
214 gpif_state_tx <= TX_META;
215 fx3_gpif <= data_out;
216 tx_data <= data_out;
217 wait until rising_edge( fx3_pclk );
218
219 gpif_state_tx <= IDLE;
220 tx_data <= (others => 'X');
221 end loop;
222 end if;
223 count := 0;
224
225 for i in 1 to (BLOCK_SIZE - header_len) loop
226 gpif_state_tx <= TX_SAMPLES;
227 data_out := data_gen(count);
228 if( eight_bit_mode_en = '1' ) then
229 fx3_gpif <= data_out;
230 tx_data <= data_out;
231 else
232 fx3_gpif <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0);
233 tx_data <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0);
234 end if;
235 wait until rising_edge( fx3_pclk );
236
237 count := (count + 4) mod 128 when eight_bit_mode_en = '1' else
238 (count + 2) mod 2048;
239 gpif_state_tx <= IDLE;
240 tx_data <= (others => 'X');
241 end loop;
242
243 fx3_gpif <= (others =>'Z');
244 nop(fx3_pclk, 10);
245 end loop;
246 wait for 10 us;
247 end loop;
248
249 wait for 2 ms;
250 dma_tx_enable <= '0';
251 wait for 10 us;
252 end loop;
253
254 report "Done with TX sample stream";
255 tx_done <= true;
256 wait;
257 end process;
258
259 reset_system : process
260 begin
261 system_reset <= '1';
262 dma_idle <= '0';
263 nop( fx3_pclk, 100 );
264 system_reset <= '0';
265 nop( fx3_pclk, 10 );
266 dma_idle <= '1';
267 wait;
268 end process;
269
270 -- TODO: UART Interface
271 fx3_uart_txd <= '1';
272 fx3_uart_cts <= '1';
273
274 assert (gpif_state_tx = IDLE and gpif_state_rx /= IDLE)
275 or (gpif_state_rx = IDLE and gpif_state_tx /= IDLE)
276 or (gpif_state_rx = IDLE and gpif_state_tx = IDLE)
277 report "gpif_state_rx and gpif_state_tx cannot both be non-idle"
278 severity failure;
279
280 end architecture micro_dma_fifo_stress;