Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/tb/atsc_tx_tb.vhd

raw
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use ieee.math_real.all;
5 use ieee.math_complex.all;
6
7 library std;
8 use std.env.all;
9
10 library work;
11 use work.nco_p.all;
12
13 library nuand;
14 use nuand.util.all;
15 use nuand.constellation_mapper_p.all;
16
17 entity atsc_tx_tb is
18 end entity;
19
20 architecture arch of atsc_tx_tb is
21
22 signal clock : std_logic := '1';
23 signal reset : std_logic := '1';
24
25 signal nco_inputs : nco_input_t;
26 signal nco_outputs : nco_output_t;
27
28
29 --fifo management
30 type fifo_t is record
31 aclr : std_logic ;
32
33 wclock : std_logic ;
34 wdata : std_logic_vector(31 downto 0) ;
35 wreq : std_logic ;
36 wempty : std_logic ;
37 wfull : std_logic ;
38 wused : std_logic_vector(11 downto 0) ;
39
40 rclock : std_logic ;
41 rdata : std_logic_vector(31 downto 0) ;
42 rreq : std_logic ;
43 rempty : std_logic ;
44 rfull : std_logic ;
45 rused : std_logic_vector(11 downto 0) ;
46 end record ;
47
48 signal tx_sample_fifo :fifo_t;
49
50 signal tx_enable : std_logic;
51 signal tx_valid : std_logic;
52
53 --filtered signal
54 signal tx_symbol : complex_fixed_t;
55 signal tx_symbol_valid : std_logic;
56
57 --
58 constant vsb_mix_table : complex_fixed_array_t := ( (to_signed(4096,16), to_signed(0,16)),
59 (to_signed(0,16), to_signed(-4096,16)),
60 (to_signed(-4096,16), to_signed(0,16)),
61 (to_signed(0,16), to_signed(4096,16) ));
62
63 function cmult( a, b : complex_fixed_t; q : natural ) return complex_fixed_t is
64 variable rv : complex_fixed_t := (to_signed(0,16),to_signed(0,16));
65 begin
66 rv.re := resize(shift_right(a.re * b.re,q) - shift_right(a.im * b.im, q),rv.re'length);
67 rv.re := resize(shift_right(a.re * b.re,q) + shift_right(a.im * b.re, q),rv.im'length);
68 return rv;
69 end function;
70
71 function cmult_fs4(a : complex_fixed_t; fs_4 : natural) return complex_fixed_t is
72 begin
73 case fs_4 is
74 when 0 => return (a.re,a.im);
75 when 1 => return (a.im,-a.re);
76 when 2 => return (-a.re,-a.im);
77 when 3 => return (-a.im, a.re);
78 when others => return a;
79 end case;
80 end function;
81
82
83
84 procedure nop( signal clock : in std_logic; count : in natural) is
85 begin
86 for i in 1 to count loop
87 wait until rising_edge(clock);
88 end loop;
89 end procedure;
90
91 constant SPS : natural := 3;
92
93 constant RANDOM_MULT : unsigned(63 downto 0) := x"2545f4914f6cdd1d";
94
95 function random_xor (old : unsigned) return unsigned is
96 variable x : unsigned(old'range) := (others=>'0');
97 variable y : unsigned(old'range) := (others=>'0');
98 variable z : unsigned(old'range) := (others=>'0');
99 begin
100 x := old xor shift_right(old,12);
101 y := x xor shift_left(x,25);
102 z := y xor shift_right(y,27);
103 return resize( shift_right(z * RANDOM_MULT,z'length),z'length);
104 end function;
105
106 signal data_request_reader : std_logic;
107 signal delay_request_reader : std_logic;
108 begin
109
110 clock <= not clock after 1 ns;
111
112 --construct fir filter under test
113 --U_filter : entity work.fir_filter(systolic)
114 -- generic map()
115 -- port map();
116
117 tb : process
118 variable delta : signed(15 downto 0);
119
120 begin
121 reset <= '1';
122 delay_request_reader <='0';
123 --setup nco input
124 delta := to_signed(1,delta'length);
125 nco_inputs.valid <= '0';
126 nco_inputs.dphase <= (others => '0');
127
128 nop(clock, 10);
129
130 --setup state
131
132 --release reset;
133 reset <= '0';
134 nop(clock, 10);
135
136 delay_request_reader <='1';
137
138 --clock in data
139 for i in 0 to 100000 loop
140
141
142
143 if (nco_inputs.dphase = 4096) then
144 delta := to_signed(-1,delta'length);
145 elsif(nco_inputs.dphase = -4096) then
146 delta := to_signed(1,delta'length);
147 end if;
148
149 nco_inputs.dphase <= nco_inputs.dphase + delta;
150 nco_inputs.valid <= '1' ;
151 wait until rising_edge(clock);
152 nco_inputs.valid <= '0';
153
154 nop(clock,10);
155 end loop;
156 --save result
157
158
159 end process;
160
161 data_request_reader <= '1' when ((unsigned(tx_sample_fifo.wused) < to_unsigned(2048,tx_sample_fifo.wused'length)) and delay_request_reader ='1' )else '0';
162
163 U_file_reader : entity work.data_reader
164 generic map (
165 FILENAME => "input.dat",
166 DATA_WIDTH => 32
167 )
168 port map (
169 reset => reset,
170 clock => clock,
171
172 data_request => data_request_reader,
173 data => tx_sample_fifo.wdata,
174 data_valid => tx_sample_fifo.wreq
175 );
176
177
178 feed_fifo: process
179 variable in_data: unsigned(31 downto 0) := x"1337cafe";
180 begin
181 tx_enable <= '0';
182 --tx_sample_fifo.wdata <= (others => '0');
183 --tx_sample_fifo.wreq <= '0';
184 nop(clock,10);
185
186
187
188 for i in 0 to 10 loop
189 --tx_sample_fifo.wdata <= std_logic_vector(in_data);
190 --tx_sample_fifo.wreq <= '1';
191 in_data :=random_xor(in_data);
192
193 wait until rising_edge(clock);
194 --tx_sample_fifo.wreq <= '0';
195 nop(clock,10);
196 end loop;
197
198 tx_enable <= '1';
199
200 for i in 0 to 100000 loop
201 --tx_sample_fifo.wdata <= std_logic_vector(in_data);
202 --tx_sample_fifo.wreq <= '1';
203 in_data :=random_xor(in_data);
204
205 wait until rising_edge(clock);
206 --tx_sample_fifo.wreq <= '0';
207 nop(clock,20);
208 end loop;
209 end process;
210
211 --tmp
212 tx_sample_fifo.aclr <= reset ;
213 tx_sample_fifo.rclock <= clock ;
214 tx_sample_fifo.wclock <= clock ;
215
216 U_bit_fifo : entity work.tx_fifo
217 port map (
218 aclr => tx_sample_fifo.aclr,
219 data => tx_sample_fifo.wdata,
220 rdclk => tx_sample_fifo.rclock,
221 rdreq => tx_sample_fifo.rreq,
222 wrclk => tx_sample_fifo.wclock,
223 wrreq => tx_sample_fifo.wreq,
224 q => tx_sample_fifo.rdata,
225 rdempty => tx_sample_fifo.rempty,
226 rdfull => tx_sample_fifo.rfull,
227 rdusedw => tx_sample_fifo.rused,
228 wrempty => tx_sample_fifo.wempty,
229 wrfull => tx_sample_fifo.wfull,
230 wrusedw => tx_sample_fifo.wused
231 );
232
233 tx_valid_register : process(reset, clock)
234 begin
235 if (reset = '1') then
236 tx_valid <= '0';
237 elsif rising_edge(clock) then
238 tx_valid <= tx_sample_fifo.rreq;
239 end if;
240 end process;
241
242 U_atsc_transmitter : entity work.atsc_tx(arch)
243 generic map(
244 INPUT_WIDTH => tx_sample_fifo.rdata'length,
245 OUTPUT_WIDTH => tx_symbol.re'length
246 )
247 port map (
248 reset => reset,
249 clock => clock,
250
251 tx_enable => tx_enable,
252 data_in => tx_sample_fifo.rdata,
253 data_in_request => tx_sample_fifo.rreq,
254 data_in_valid => tx_valid,
255
256 sample_out_i => tx_symbol.re,
257 sample_out_q => tx_symbol.im,
258 sample_out_valid => tx_symbol_valid
259
260 );
261
262
263 U_data_saver_im : entity work.signed_saver(arch)
264 generic map (
265 FILENAME => "tx_sym.im"
266 )
267 port map(
268 clock => clock,
269 reset => reset,
270 data => (tx_symbol.im),
271 data_valid => tx_symbol_valid
272 );
273
274 U_data_saver_re : entity work.signed_saver(arch)
275 generic map (
276 FILENAME => "tx_sym.re"
277 )
278 port map(
279 clock => clock,
280 reset => reset,
281 data => (tx_symbol.re),
282 data_valid => tx_symbol_valid
283 );
284
285 --U_nco_test : entity work.nco(arch)
286 -- port map (
287 -- clock => clock,
288 -- reset => reset,
289
290 -- inputs => nco_inputs,
291 -- outputs => nco_outputs
292 -- );
293
294
295 end architecture;