Debian Codegraph @

hdl/fpga/ip/nuand/simulation/fx3_model.vhd

raw
1 -- Copyright (c) 2013 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
32 entity fx3_model is
33 port (
34 fx3_pclk : buffer std_logic := '1';
35 fx3_gpif : inout std_logic_vector(31 downto 0);
36 fx3_ctl : inout std_logic_vector(12 downto 0);
37 fx3_uart_rxd : in std_logic;
38 fx3_uart_txd : buffer std_logic;
39 fx3_uart_cts : buffer std_logic;
40 fx3_rx_en : in std_logic;
41 fx3_rx_meta_en : in std_logic;
42 fx3_tx_en : in std_logic;
43 fx3_tx_meta_en : in std_logic;
44 eight_bit_mode_en : in std_logic := '0';
45 packed_mode_en : in std_logic := '0';
46 done : out boolean
47 );
48 end entity ; -- fx3_model
49
50 architecture dma of fx3_model is
51
52 constant PCLK_HALF_PERIOD : time := 1 sec * (1.0/100.0e6/2.0);
53 constant START_COUNT : natural := 32;
54 constant BLOCKS_PER_ITERATION : natural := 4;
55 constant ITERATIONS : natural := 4;
56
57 -- Control mapping
58 alias dma0_rx_ack is fx3_ctl( 0);
59 alias dma1_rx_ack is fx3_ctl( 1);
60 alias dma2_tx_ack is fx3_ctl( 2);
61 alias dma3_tx_ack is fx3_ctl( 3);
62 alias dma_rx_enable is fx3_ctl( 4);
63 alias dma_tx_enable is fx3_ctl( 5);
64 alias dma_idle is fx3_ctl( 6);
65 alias system_reset is fx3_ctl( 7);
66 alias dma0_rx_reqx is fx3_ctl( 8);
67 alias dma1_rx_reqx is fx3_ctl(12); -- due to 9 being connected to dclk
68 alias dma2_tx_reqx is fx3_ctl(10);
69 alias dma3_tx_reqx is fx3_ctl(11);
70
71 type gpif_state_t is (IDLE, TX_META, TX_SAMPLES, RX_SAMPLES);
72 signal gpif_state_rx, gpif_state_tx : gpif_state_t;
73
74 signal rx_done : boolean := false;
75 signal tx_done : boolean := false;
76
77 signal rx_data : std_logic_vector(31 downto 0);
78 signal tx_data : std_logic_vector(31 downto 0);
79
80 function data_gen (count : natural) return std_logic_vector is
81 variable msw, lsw : std_logic_vector(15 downto 0);
82 begin
83 msw := std_logic_vector(to_signed(count, 16));
84 lsw := std_logic_vector(to_signed(-count, 16));
85
86 return (msw & lsw);
87 end function data_gen;
88
89 function data_check (count : natural ; rxdata : std_logic_vector(31 downto 0)) return boolean is
90 begin
91 return (rxdata = data_gen(count));
92 end function data_check;
93
94 begin
95
96 -- DCLK which isn't used
97 fx3_ctl(9) <= '0';
98
99 fx3_ctl(3 downto 0) <= (others => 'Z');
100
101 -- Create a 100MHz clock output
102 fx3_pclk <= not fx3_pclk after PCLK_HALF_PERIOD when (not rx_done or not tx_done) else '0';
103
104 -- Doneness
105 done <= rx_done and tx_done;
106
107 rx_sample_stream : process
108 constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
109 variable count : natural := START_COUNT;
110 variable req_time : time;
111 begin
112 gpif_state_rx <= IDLE;
113 dma0_rx_reqx <= '1';
114 dma1_rx_reqx <= '1';
115 dma_rx_enable <= '0';
116 rx_data <= (others => 'U');
117
118 wait until rising_edge(fx3_pclk) and system_reset = '0';
119
120 nop(fx3_pclk, 1000);
121
122 wait until rising_edge(fx3_pclk) and fx3_rx_en = '1';
123
124 wait for 30 us;
125
126 for j in 1 to ITERATIONS loop
127 dma_rx_enable <= '1';
128
129 for i in 1 to BLOCKS_PER_ITERATION loop
130 dma0_rx_reqx <= '0';
131 req_time := now;
132 wait until rising_edge( fx3_pclk ) and dma0_rx_ack = '1';
133 wait until rising_edge( fx3_pclk );
134 dma0_rx_reqx <= '1';
135
136 report "RX iteration " & to_string(j) & " block " & to_string(i) & " delay " & to_string(now - req_time);
137
138 for i in 1 to BLOCK_SIZE loop
139 gpif_state_rx <= RX_SAMPLES;
140 rx_data <= fx3_gpif;
141 wait until rising_edge( fx3_pclk );
142
143 assert data_check(count, rx_data) severity failure;
144
145 count := (count + 1) mod 2048;
146 gpif_state_rx <= IDLE;
147 rx_data <= (others => 'X');
148 end loop;
149 end loop;
150
151 dma_rx_enable <= '0';
152 wait for 10 us;
153 end loop;
154
155 report "Done with RX sample stream";
156 rx_done <= true;
157 wait;
158 end process;
159
160 tx_sample_stream : process
161 constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
162 variable count : natural := START_COUNT;
163 variable timestamp_cntr : natural := 80;
164 variable header_len : natural := 0;
165 variable data_out : std_logic_vector(31 downto 0);
166 variable req_time : time;
167 begin
168 gpif_state_tx <= IDLE;
169 dma2_tx_reqx <= '1';
170 dma3_tx_reqx <= '1';
171 dma_tx_enable <= '0';
172 fx3_gpif <= (others =>'Z');
173
174 wait until rising_edge(fx3_pclk) and system_reset = '0';
175
176 nop(fx3_pclk, 1000);
177
178 wait until rising_edge(fx3_pclk) and fx3_tx_en = '1';
179
180 wait for 30 us;
181
182 for k in 1 to ITERATIONS loop
183 dma_tx_enable <= '1';
184
185 for j in 1 to BLOCKS_PER_ITERATION loop
186 header_len := 0;
187 dma3_tx_reqx <= '0';
188 req_time := now;
189 wait until rising_edge( fx3_pclk ) and dma3_tx_ack = '1';
190 wait until rising_edge( fx3_pclk );
191 wait until rising_edge( fx3_pclk );
192 wait until rising_edge( fx3_pclk );
193 dma3_tx_reqx <= '1';
194
195 report "TX iteration " & to_string(k) & " block " & to_string(j) & " delay " & to_string(now - req_time);
196
197
198 if( fx3_tx_meta_en = '1') then
199 header_len := 4;
200
201 for i in 1 to 4 loop
202 case (i) is
203 when 1 =>
204 data_out := x"12341234";
205 when 2 =>
206 data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32));
207 timestamp_cntr := timestamp_cntr + (GPIF_BUF_SIZE_SS-4) * 2;
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
224 for i in 1 to (BLOCK_SIZE - header_len) loop
225 gpif_state_tx <= TX_SAMPLES;
226 data_out := data_gen(count);
227 fx3_gpif <= data_out;
228 tx_data <= data_out;
229 wait until rising_edge( fx3_pclk );
230
231 count := (count + 1) mod 2048;
232 gpif_state_tx <= IDLE;
233 tx_data <= (others => 'X');
234 end loop;
235
236 fx3_gpif <= (others =>'Z');
237 nop(fx3_pclk, 10);
238 end loop;
239
240 dma_tx_enable <= '0';
241 wait for 10 us;
242 end loop;
243
244 report "Done with TX sample stream";
245 tx_done <= true;
246 wait;
247 end process;
248
249 reset_system : process
250 begin
251 system_reset <= '1';
252 dma_idle <= '0';
253 nop( fx3_pclk, 100 );
254 system_reset <= '0';
255 nop( fx3_pclk, 10 );
256 dma_idle <= '1';
257 wait;
258 end process;
259
260 -- TODO: UART Interface
261 fx3_uart_txd <= '1';
262 fx3_uart_cts <= '1';
263
264 assert (gpif_state_tx = IDLE and gpif_state_rx /= IDLE)
265 or (gpif_state_rx = IDLE and gpif_state_tx /= IDLE)
266 or (gpif_state_rx = IDLE and gpif_state_tx = IDLE)
267 report "gpif_state_rx and gpif_state_tx cannot both be non-idle"
268 severity failure;
269
270 end architecture dma;
271
272 architecture inband_scheduler of fx3_model is
273 begin
274 end architecture inband_scheduler;