1 |
35 |
gedra |
----------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- WISHBONE SPDIF IP Core ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the SPDIF project ----
|
6 |
|
|
---- http://www.opencores.org/cores/spdif_interface/ ----
|
7 |
|
|
---- ----
|
8 |
|
|
---- Description ----
|
9 |
|
|
---- Test bench for SPDIF recevier. ----
|
10 |
|
|
---- ----
|
11 |
|
|
---- ----
|
12 |
|
|
---- To Do: ----
|
13 |
|
|
---- - ----
|
14 |
|
|
---- ----
|
15 |
|
|
---- Author(s): ----
|
16 |
|
|
---- - Geir Drange, gedra@opencores.org ----
|
17 |
|
|
---- ----
|
18 |
|
|
----------------------------------------------------------------------
|
19 |
|
|
---- ----
|
20 |
|
|
---- Copyright (C) 2004 Authors and OPENCORES.ORG ----
|
21 |
|
|
---- ----
|
22 |
|
|
---- This source file may be used and distributed without ----
|
23 |
|
|
---- restriction provided that this copyright statement is not ----
|
24 |
|
|
---- removed from the file and that any derivative work contains ----
|
25 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
26 |
|
|
---- ----
|
27 |
|
|
---- This source file is free software; you can redistribute it ----
|
28 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
29 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
30 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
31 |
|
|
---- later version. ----
|
32 |
|
|
---- ----
|
33 |
|
|
---- This source is distributed in the hope that it will be ----
|
34 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
35 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
36 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
37 |
|
|
---- details. ----
|
38 |
|
|
---- ----
|
39 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
40 |
|
|
---- Public License along with this source; if not, download it ----
|
41 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
42 |
|
|
---- ----
|
43 |
|
|
----------------------------------------------------------------------
|
44 |
|
|
--
|
45 |
|
|
-- CVS Revision History
|
46 |
|
|
--
|
47 |
|
|
-- $Log: not supported by cvs2svn $
|
48 |
41 |
gedra |
-- Revision 1.2 2004/07/11 16:20:16 gedra
|
49 |
|
|
-- Improved test bench.
|
50 |
|
|
--
|
51 |
40 |
gedra |
-- Revision 1.1 2004/06/26 14:12:51 gedra
|
52 |
|
|
-- Top level test bench for receiver. NB! Not complete.
|
53 |
35 |
gedra |
--
|
54 |
40 |
gedra |
--
|
55 |
35 |
gedra |
|
56 |
|
|
library ieee;
|
57 |
|
|
use ieee.std_logic_1164.all;
|
58 |
|
|
use work.wb_tb_pack.all;
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
entity tb_rx_spdif is
|
62 |
|
|
|
63 |
|
|
end tb_rx_spdif;
|
64 |
|
|
|
65 |
|
|
architecture behav of tb_rx_spdif is
|
66 |
|
|
|
67 |
|
|
component rx_spdif is
|
68 |
|
|
generic (DATA_WIDTH: integer range 16 to 32;
|
69 |
|
|
ADDR_WIDTH: integer range 8 to 64;
|
70 |
|
|
CH_ST_CAPTURE: integer range 0 to 8;
|
71 |
|
|
WISHBONE_FREQ: natural);
|
72 |
|
|
port (
|
73 |
|
|
-- Wishbone interface
|
74 |
|
|
wb_clk_i: in std_logic;
|
75 |
|
|
wb_rst_i: in std_logic;
|
76 |
|
|
wb_sel_i: in std_logic;
|
77 |
|
|
wb_stb_i: in std_logic;
|
78 |
|
|
wb_we_i: in std_logic;
|
79 |
|
|
wb_cyc_i: in std_logic;
|
80 |
|
|
wb_bte_i: in std_logic_vector(1 downto 0);
|
81 |
|
|
wb_cti_i: in std_logic_vector(2 downto 0);
|
82 |
|
|
wb_adr_i: in std_logic_vector(ADDR_WIDTH - 1 downto 0);
|
83 |
|
|
wb_dat_i: in std_logic_vector(DATA_WIDTH -1 downto 0);
|
84 |
|
|
wb_ack_o: out std_logic;
|
85 |
|
|
wb_dat_o: out std_logic_vector(DATA_WIDTH - 1 downto 0);
|
86 |
|
|
-- Interrupt line
|
87 |
|
|
rx_int_o: out std_logic;
|
88 |
|
|
-- SPDIF input signal
|
89 |
|
|
spdif_rx_i: in std_logic);
|
90 |
|
|
end component;
|
91 |
|
|
|
92 |
|
|
component gen_spdif
|
93 |
|
|
generic (Freq: natural); -- Sampling frequency in Hz
|
94 |
|
|
port ( -- Bitrate is 64x sampling frequency
|
95 |
|
|
reset: in std_logic;
|
96 |
|
|
spdif: out std_logic); -- Output bi-phase encoded signal
|
97 |
|
|
end component;
|
98 |
|
|
|
99 |
|
|
signal wb_clk_o, wb_rst_o, wb_sel_o, wb_stb_o, wb_we_o : std_logic;
|
100 |
|
|
signal wb_cyc_o, wb_ack_i, rx_int_o, spdif_rx_i : std_logic;
|
101 |
|
|
signal wb_bte_o : std_logic_vector(1 downto 0);
|
102 |
|
|
signal wb_cti_o : std_logic_vector(2 downto 0);
|
103 |
|
|
signal wb_adr_o : std_logic_vector(15 downto 0);
|
104 |
|
|
signal wb_dat_i, wb_dat_o : std_logic_vector(31 downto 0);
|
105 |
|
|
signal wb_stb_16bit_rx : std_logic;
|
106 |
40 |
gedra |
constant RX_VERSION : natural := 16#1000#;
|
107 |
|
|
constant RX_CONFIG : natural := 16#1001#;
|
108 |
|
|
constant RX_STATUS : natural := 16#1002#;
|
109 |
|
|
constant RX_INTMASK : natural := 16#1003#;
|
110 |
|
|
constant RX_INTSTAT : natural := 16#1004#;
|
111 |
|
|
|
112 |
35 |
gedra |
begin
|
113 |
|
|
|
114 |
|
|
-- Minimal SPDIF recevier in 16bit mode
|
115 |
|
|
SRX16: rx_spdif
|
116 |
|
|
generic map (
|
117 |
|
|
DATA_WIDTH => 16,
|
118 |
|
|
ADDR_WIDTH => 8, -- 128 byte sample buffer
|
119 |
|
|
CH_ST_CAPTURE => 0, -- no capture in 16bit mode
|
120 |
|
|
WISHBONE_FREQ => 33) -- 33 MHz
|
121 |
|
|
port map (
|
122 |
|
|
wb_clk_i => wb_clk_o,
|
123 |
|
|
wb_rst_i => wb_rst_o,
|
124 |
|
|
wb_sel_i => wb_sel_o,
|
125 |
|
|
wb_stb_i => wb_stb_16bit_rx,
|
126 |
|
|
wb_we_i => wb_we_o,
|
127 |
|
|
wb_cyc_i => wb_cyc_o,
|
128 |
|
|
wb_bte_i => wb_bte_o,
|
129 |
|
|
wb_cti_i => wb_cti_o,
|
130 |
|
|
wb_adr_i => wb_adr_o(7 downto 0),
|
131 |
|
|
wb_dat_i => wb_dat_o(15 downto 0),
|
132 |
|
|
wb_ack_o => wb_ack_i,
|
133 |
|
|
wb_dat_o => wb_dat_i(15 downto 0),
|
134 |
|
|
rx_int_o => rx_int_o,
|
135 |
|
|
spdif_rx_i => spdif_rx_i);
|
136 |
|
|
|
137 |
|
|
-- SPDIF 44.1kHz source
|
138 |
|
|
SP44: gen_spdif
|
139 |
40 |
gedra |
generic map (FREQ => 44100)
|
140 |
35 |
gedra |
port map (reset => wb_rst_o,
|
141 |
40 |
gedra |
spdif => spdif_rx_i);
|
142 |
35 |
gedra |
|
143 |
|
|
-- Main test process
|
144 |
|
|
MAIN: process
|
145 |
|
|
variable read_16bit : std_logic_vector(15 downto 0);
|
146 |
|
|
|
147 |
|
|
-- Make simplified versions of procedures in wb_tb_pack
|
148 |
|
|
procedure wb_write_16 (
|
149 |
|
|
constant ADDRESS: in natural;
|
150 |
|
|
constant DATA: in natural) is
|
151 |
|
|
begin
|
152 |
|
|
wb_write(ADDRESS, DATA, wb_adr_o, wb_dat_o(15 downto 0), wb_cyc_o,
|
153 |
|
|
wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);
|
154 |
|
|
end;
|
155 |
|
|
|
156 |
|
|
procedure wb_check_16 (
|
157 |
|
|
constant ADDRESS: in natural;
|
158 |
|
|
constant EXP_DATA : in natural) is
|
159 |
|
|
begin
|
160 |
|
|
wb_check(ADDRESS, EXP_DATA, wb_adr_o, wb_dat_i(15 downto 0), wb_cyc_o,
|
161 |
|
|
wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);
|
162 |
|
|
end;
|
163 |
|
|
|
164 |
|
|
procedure wb_read_16 (
|
165 |
|
|
constant ADDRESS: in natural;
|
166 |
|
|
variable READ_DATA : out std_logic_vector) is
|
167 |
|
|
begin
|
168 |
|
|
wb_read(ADDRESS, read_16bit, wb_adr_o, wb_dat_i(15 downto 0), wb_cyc_o,
|
169 |
|
|
wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);
|
170 |
|
|
end;
|
171 |
|
|
begin
|
172 |
|
|
message("Simulation start with system reset.");
|
173 |
|
|
wb_rst_o <= '1'; -- system reset
|
174 |
|
|
wb_sel_o <= '0';
|
175 |
|
|
wb_stb_o <= '0';
|
176 |
|
|
wb_sel_o <= '0';
|
177 |
|
|
wb_we_o <= '0';
|
178 |
|
|
wb_cyc_o <= '0';
|
179 |
|
|
wb_bte_o <= "00";
|
180 |
|
|
wb_cti_o <= "000";
|
181 |
|
|
wb_adr_o <= (others => '0');
|
182 |
|
|
wb_dat_o <= (others => '0');
|
183 |
40 |
gedra |
wait for 200 ns;
|
184 |
35 |
gedra |
wb_rst_o <= '0';
|
185 |
|
|
message("Start with checking version register for correct value:");
|
186 |
40 |
gedra |
wb_check_16(RX_VERSION, 16#0101#);
|
187 |
|
|
message("Enable interrupt on lock:");
|
188 |
|
|
wb_write_16(RX_INTMASK, 16#0001#);
|
189 |
35 |
gedra |
message("Enable receiver:");
|
190 |
40 |
gedra |
wb_write_16(RX_CONFIG, 16#0005#);
|
191 |
|
|
wb_read_16(RX_CONFIG, read_16bit);
|
192 |
|
|
wait_for_event("Wait for LOCK interrupt", 60 us, rx_int_o);
|
193 |
|
|
message("Check status register:");
|
194 |
|
|
wb_check_16(RX_STATUS, 16#0001#);
|
195 |
|
|
message("Clear interrupt:");
|
196 |
|
|
wb_write_16(RX_INTSTAT, 16#0001#);
|
197 |
|
|
wb_check_16(RX_INTSTAT, 16#0000#);
|
198 |
|
|
signal_check("rx_int_o", '0', rx_int_o);
|
199 |
|
|
message("Enable sample buffer");
|
200 |
|
|
wb_write_16(RX_CONFIG, 16#0007#);
|
201 |
|
|
message("Enable sample buffer interrupts");
|
202 |
|
|
wb_write_16(RX_INTMASK, 16#0007#);
|
203 |
|
|
wait_for_event("Wait for LSBF interrupt", 750 us, rx_int_o);
|
204 |
|
|
message("Check LSBF interrupt, and read some data");
|
205 |
|
|
wb_check_16(RX_INTSTAT, 16#0002#);
|
206 |
|
|
wb_write_16(RX_INTSTAT, 16#0002#);
|
207 |
|
|
wb_check_16(RX_INTSTAT, 16#0000#);
|
208 |
|
|
signal_check("rx_int_o", '0', rx_int_o);
|
209 |
|
|
wb_read_16(16#1080#, read_16bit);
|
210 |
|
|
wb_read_16(16#1081#, read_16bit);
|
211 |
|
|
wb_read_16(16#1082#, read_16bit);
|
212 |
|
|
wb_read_16(16#1083#, read_16bit);
|
213 |
41 |
gedra |
wait_for_event("Wait for HSBF interrupt", 750 us, rx_int_o);
|
214 |
|
|
message("Check HSBF interrupt, and read some data");
|
215 |
|
|
wb_check_16(RX_INTSTAT, 16#0004#);
|
216 |
|
|
wb_write_16(RX_INTSTAT, 16#0004#);
|
217 |
|
|
wb_check_16(RX_INTSTAT, 16#0000#);
|
218 |
|
|
signal_check("rx_int_o", '0', rx_int_o);
|
219 |
35 |
gedra |
|
220 |
41 |
gedra |
|
221 |
35 |
gedra |
report "End of simulation! (ignore this failure)"
|
222 |
|
|
severity failure;
|
223 |
|
|
wait;
|
224 |
|
|
|
225 |
|
|
end process MAIN;
|
226 |
|
|
|
227 |
|
|
-- Bus strobe generator based on address. 16bit recevier mapped to addr. 0x1000
|
228 |
|
|
wb_stb_16bit_rx <= '1' when wb_adr_o(15 downto 12) = "0001" else '0';
|
229 |
|
|
|
230 |
|
|
-- Clock process, 33Mhz Wishbone master freq.
|
231 |
|
|
CLKGEN: process
|
232 |
|
|
begin
|
233 |
|
|
wb_clk_o <= '0';
|
234 |
|
|
wait for 15.15 ns;
|
235 |
|
|
wb_clk_o <= '1';
|
236 |
|
|
wait for 15.15 ns;
|
237 |
|
|
end process CLKGEN;
|
238 |
|
|
|
239 |
|
|
end behav;
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|