OpenCores
URL https://opencores.org/ocsvn/spdif_interface/spdif_interface/trunk

Subversion Repositories spdif_interface

[/] [spdif_interface/] [trunk/] [bench/] [vhdl/] [tb_spdif.vhd] - Blame information for rev 73

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 55 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
---- Top-level testbench for both receiver and transmitter.       ----
10
---- Output from the transmitter is connected to input of recevier----
11
---- and checking is done on data transfer and channel status     ----
12
---- capture.                                                     ----
13
----                                                              ----
14
----                                                              ----
15
---- To Do:                                                       ----
16
---- -                                                            ----
17
----                                                              ----
18
---- Author(s):                                                   ----
19
---- - Geir Drange, gedra@opencores.org                           ----
20
----                                                              ----
21
----------------------------------------------------------------------
22
----                                                              ----
23
---- Copyright (C) 2004 Authors and OPENCORES.ORG                 ----
24
----                                                              ----
25
---- This source file may be used and distributed without         ----
26
---- restriction provided that this copyright statement is not    ----
27
---- removed from the file and that any derivative work contains  ----
28
---- the original copyright notice and the associated disclaimer. ----
29
----                                                              ----
30
---- This source file is free software; you can redistribute it   ----
31
---- and/or modify it under the terms of the GNU Lesser General   ----
32
---- Public License as published by the Free Software Foundation; ----
33
---- either version 2.1 of the License, or (at your option) any   ----
34
---- later version.                                               ----
35
----                                                              ----
36
---- This source is distributed in the hope that it will be       ----
37
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
38
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
39
---- PURPOSE. See the GNU Lesser General Public License for more  ----
40
---- details.                                                     ----
41
----                                                              ----
42
---- You should have received a copy of the GNU Lesser General    ----
43
---- Public License along with this source; if not, download it   ----
44
---- from http://www.opencores.org/lgpl.shtml                     ----
45
----                                                              ----
46
----------------------------------------------------------------------
47
--
48
-- CVS Revision History
49
--
50
-- $Log: not supported by cvs2svn $
51 72 gedra
-- Revision 1.1  2004/07/19 16:58:01  gedra
52
-- Top level testbench for transmitter and receiver.
53 55 gedra
--
54
--
55 72 gedra
--
56
 
57 55 gedra
library ieee;
58
use ieee.std_logic_1164.all;
59
use work.wb_tb_pack.all;
60
 
61 72 gedra
entity tb_spdif is
62
 
63 55 gedra
end tb_spdif;
64
 
65
architecture behav of tb_spdif is
66
 
67 72 gedra
   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 55 gedra
 
92 72 gedra
   component tx_spdif
93
      generic (DATA_WIDTH    : integer range 16 to 32;
94
               ADDR_WIDTH    : integer range 8 to 64;
95
               USER_DATA_BUF : integer range 0 to 1;
96
               CH_STAT_BUF   : integer range 0 to 1);
97
      port (
98
         -- Wishbone interface
99
         wb_clk_i   : in  std_logic;
100
         wb_rst_i   : in  std_logic;
101
         wb_sel_i   : in  std_logic;
102
         wb_stb_i   : in  std_logic;
103
         wb_we_i    : in  std_logic;
104
         wb_cyc_i   : in  std_logic;
105
         wb_bte_i   : in  std_logic_vector(1 downto 0);
106
         wb_cti_i   : in  std_logic_vector(2 downto 0);
107
         wb_adr_i   : in  std_logic_vector(ADDR_WIDTH - 1 downto 0);
108
         wb_dat_i   : in  std_logic_vector(DATA_WIDTH -1 downto 0);
109
         wb_ack_o   : out std_logic;
110
         wb_dat_o   : out std_logic_vector(DATA_WIDTH - 1 downto 0);
111
         -- Interrupt line
112
         tx_int_o   : out std_logic;
113
         -- SPDIF output signal
114
         spdif_tx_o : out std_logic);
115
   end component;
116 55 gedra
 
117 72 gedra
   signal wb_clk_o, wb_rst_o, wb_sel_o, wb_stb_o, wb_we_o : std_logic;
118
   signal wb_cyc_o, wb_ack_i, rx_int_o, spdif_signal      : std_logic;
119
   signal tx_int_o, tx_ack, rx_ack                        : std_logic;
120
   signal wb_bte_o                                        : std_logic_vector(1 downto 0);
121
   signal wb_cti_o                                        : std_logic_vector(2 downto 0);
122
   signal wb_adr_o                                        : std_logic_vector(15 downto 0);
123
   signal wb_dat_i, wb_dat_o, rx_dat_i, tx_dat_i          : std_logic_vector(31 downto 0);
124
   signal wb_stb_32bit_rx, wb_stb_32bit_tx                : std_logic;
125
   constant RX_VERSION                                    : natural := 16#1000#;
126
   constant RX_CONFIG                                     : natural := 16#1001#;
127
   constant RX_STATUS                                     : natural := 16#1002#;
128
   constant RX_INTMASK                                    : natural := 16#1003#;
129
   constant RX_INTSTAT                                    : natural := 16#1004#;
130
   constant RX_CHSTCAP0                                   : natural := 16#1010#;
131
   constant RX_CHSTDAT0                                   : natural := 16#1011#;
132
   constant RX_CHSTCAP1                                   : natural := 16#1012#;
133
   constant RX_CHSTDAT1                                   : natural := 16#1013#;
134
   constant RX_BUF_BASE                                   : natural := 16#1080#;
135
   constant TX_VERSION                                    : natural := 16#2000#;
136
   constant TX_CONFIG                                     : natural := 16#2001#;
137
   constant TX_CHSTAT                                     : natural := 16#2002#;
138
   constant TX_INTMASK                                    : natural := 16#2003#;
139
   constant TX_INTSTAT                                    : natural := 16#2004#;
140
   constant TX_UD_BASE                                    : natural := 16#2020#;
141
   constant TX_CS_BASE                                    : natural := 16#2040#;
142
   constant TX_BUF_BASE                                   : natural := 16#2080#;
143
 
144
 
145 55 gedra
begin
146
 
147 72 gedra
   wb_ack_i <= rx_ack or tx_ack;
148
   wb_dat_i <= rx_dat_i or tx_dat_i;
149
 
150 55 gedra
-- SPDIF recevier in 32bit mode with two capture registers
151 72 gedra
   SRX32 : rx_spdif
152
      generic map (
153
         DATA_WIDTH    => 32,
154
         ADDR_WIDTH    => 8,            -- 128 byte sample buffer
155
         CH_ST_CAPTURE => 2,            -- two capture regs.
156
         WISHBONE_FREQ => 33)           -- 33 MHz
157
      port map (
158
         wb_clk_i   => wb_clk_o,
159
         wb_rst_i   => wb_rst_o,
160
         wb_sel_i   => wb_sel_o,
161
         wb_stb_i   => wb_stb_32bit_rx,
162
         wb_we_i    => wb_we_o,
163
         wb_cyc_i   => wb_cyc_o,
164
         wb_bte_i   => wb_bte_o,
165
         wb_cti_i   => wb_cti_o,
166
         wb_adr_i   => wb_adr_o(7 downto 0),
167
         wb_dat_i   => wb_dat_o(31 downto 0),
168
         wb_ack_o   => rx_ack,
169
         wb_dat_o   => rx_dat_i,
170
         rx_int_o   => rx_int_o,
171
         spdif_rx_i => spdif_signal);
172 55 gedra
 
173
-- SPDIF transmitter with all bells and whistles
174 72 gedra
   STX32 : tx_spdif
175
      generic map (DATA_WIDTH    => 32,
176
                   ADDR_WIDTH    => 8,
177
                   USER_DATA_BUF => 1,
178
                   CH_STAT_BUF   => 1)
179
      port map (
180
         -- Wishbone interface
181
         wb_clk_i   => wb_clk_o,
182
         wb_rst_i   => wb_rst_o,
183
         wb_sel_i   => wb_sel_o,
184
         wb_stb_i   => wb_stb_32bit_tx,
185
         wb_we_i    => wb_we_o,
186
         wb_cyc_i   => wb_cyc_o,
187
         wb_bte_i   => wb_bte_o,
188
         wb_cti_i   => wb_cti_o,
189
         wb_adr_i   => wb_adr_o(7 downto 0),
190
         wb_dat_i   => wb_dat_o(31 downto 0),
191
         wb_ack_o   => tx_ack,
192
         wb_dat_o   => tx_dat_i,
193
         tx_int_o   => tx_int_o,
194
         spdif_tx_o => spdif_signal);
195
 
196 55 gedra
-- Main test process
197 72 gedra
   MAIN : process
198
      variable read_32bit : std_logic_vector(31 downto 0);
199 55 gedra
 
200 72 gedra
      -- Make simplified versions of procedures in wb_tb_pack
201
      procedure wb_write_32 (
202
         constant ADDRESS : in natural;
203
         constant DATA    : in natural) is
204
      begin
205
         wb_write(ADDRESS, DATA, wb_adr_o, wb_dat_o(31 downto 0), wb_cyc_o,
206
                  wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);
207
      end;
208
 
209
      procedure wb_check_32 (
210
         constant ADDRESS  : in natural;
211
         constant EXP_DATA : in natural) is
212
      begin
213
         wb_check(ADDRESS, EXP_DATA, wb_adr_o, wb_dat_i(31 downto 0), wb_cyc_o,
214
                  wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);
215
      end;
216
 
217
      procedure wb_read_32 (
218
         constant ADDRESS   : in  natural;
219
         variable READ_DATA : out std_logic_vector) is
220
      begin
221
         wb_read(ADDRESS, read_32bit, wb_adr_o, wb_dat_i(31 downto 0), wb_cyc_o,
222
                 wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);
223
      end;
224
   begin
225
      message("Simulation start with system reset.");
226
      wb_rst_o <= '1';                  -- system reset
227
      wb_sel_o <= '0';
228
      wb_stb_o <= '0';
229
      wb_sel_o <= '0';
230
      wb_we_o  <= '0';
231
      wb_cyc_o <= '0';
232
      wb_bte_o <= "00";
233
      wb_cti_o <= "000";
234
      wb_adr_o <= (others => '0');
235
      wb_dat_o <= (others => '0');
236
      wait for 200 ns;
237
      wb_rst_o <= '0';
238
      message("Start with checking version register for correct value:");
239
      wb_check_32(RX_VERSION, 16#00020111#);
240
      message("Check transmitter version register:");
241
      wb_check_32(TX_VERSION, 16#00003111#);
242
      message("Fill up sample buffer with test signal, ramp up in ch.A, ramp down in ch.B:");
243
      SGEN : for i in 0 to 63 loop
244
         wb_write_32(TX_BUF_BASE + 2*i, 32768 + i*497);      -- channel A
245
         wb_write_32(TX_BUF_BASE + 2*i + 1, 32768 - i*497);  -- channel B
246
      end loop;
247
      message("Setup some channel status and user data to be transmitted:");
248
      wb_write_32(TX_CS_BASE, 16#000000f8#);
249
      wb_write_32(TX_UD_BASE + 5, 16#000000a2#);
250
      message("Enable transmitter:");
251
      wb_write_32(TX_CONFIG, 16#00000851#);
252
      wait for 4 us;
253
      message("Enable receiver, interrupt on lock:");
254
      wb_write_32(RX_INTMASK, 16#00000001#);
255
      wb_write_32(RX_CONFIG, 16#00000005#);
256
      wait_for_event("Wait for LOCK interrupt", 120 us, rx_int_o);
257
      message("Check status register:");
258
      wb_check_32(RX_STATUS, 16#00000001#);
259
      message("Clear LOCK interrupt:");
260
      wb_write_32(RX_INTSTAT, 16#00000001#);
261
      wb_check_32(RX_INTSTAT, 16#00000000#);
262
      signal_check("rx_int_o", '0', rx_int_o);
263
      message("Enable recevier sample buffer:");
264
      wb_write_32(RX_CONFIG, 16#00000017#);
265
      wait for 20 us;
266
      message("Enable audio transmission:");
267
      wb_write_32(TX_CONFIG, 16#00000853#);
268
      message("Enable receiver LSBF/HSBF interrupts:");
269
      wb_write_32(RX_INTMASK, 16#00000006#);
270
      wait_for_event("Wait for recevier LSBF interrupt", 1.8 ms, rx_int_o);
271
      message("Clear LSBF interrupt:");
272
      wb_write_32(RX_INTSTAT, 16#00000002#);
273
      wb_check_32(RX_INTSTAT, 16#00000000#);
274
      signal_check("rx_int_o", '0', rx_int_o);
275
      message("Check receiver buffer for correct sample data:");
276
      SCHK : for i in 0 to 31 loop
277
         wb_check_32(RX_BUF_BASE + 2*i, 32768 + i*497);      -- channel A
278
         wb_check_32(RX_BUF_BASE + 2*i + 1, 32768 - i*497);  -- channel B
279
      end loop;
280
      wait_for_event("Wait for recevier HSBF interrupt", 1.8 ms, rx_int_o);
281
      message("Clear HSBF interrupt:");
282
      wb_write_32(RX_INTSTAT, 16#00000004#);
283
      wb_check_32(RX_INTSTAT, 16#00000000#);
284
      signal_check("rx_int_o", '0', rx_int_o);
285
      message("Check receiver buffer for correct sample data:");
286
      SCHK2 : for i in 32 to 63 loop
287
         wb_check_32(RX_BUF_BASE + 2*i, 32768 + i*497);      -- channel A
288
         wb_check_32(RX_BUF_BASE + 2*i + 1, 32768 - i*497);  -- channel B
289
      end loop;
290
      message("Setup receiver capture register for channel status capture:");
291
      wb_write_32(RX_CHSTCAP0, 16#00000286#);  -- 6 bits from bit 2
292
      wb_check_32(RX_CHSTCAP0, 16#00000286#);
293
      message("Setup receiver capture register for user data capture:");
294
      wb_write_32(RX_CHSTCAP1, 16#00002808#);  -- 8 bits from bit 40
295
      message("Enable capture interrupts:");
296
      wb_write_32(RX_INTMASK, 16#00030000#);
297
      wait_for_event("Wait for receiver CAP0 interrupt", 6 ms, rx_int_o);
298
      message("Check captured bits and clear interrupt:");
299
      wb_check_32(RX_CHSTDAT0, 16#0000003e#);
300
      wb_write_32(RX_INTSTAT, 16#00010006#);
301
      wb_check_32(RX_INTSTAT, 16#00000000#);
302
      signal_check("rx_int_o", '0', rx_int_o);
303
      wait_for_event("Wait for receiver CAP1 interrupt", 4 ms, rx_int_o);
304
      message("Check captured bits and clear interrupt:");
305
      wb_check_32(RX_CHSTDAT1, 16#000000a2#);
306
      wb_write_32(RX_INTSTAT, 16#00020006#);
307
      wb_check_32(RX_INTSTAT, 16#00000000#);
308
      signal_check("rx_int_o", '0', rx_int_o);
309
      message("Check that transmitter buffer events were generated:");
310
      wb_check_32(TX_INTSTAT, 16#0000001e#);
311
      wb_write_32(TX_INTSTAT, 16#0000001e#);
312
      wb_check_32(TX_INTSTAT, 16#00000000#);
313
 
314
      sim_report("");
315
      report "End of simulation! (ignore this failure)"
316
         severity failure;
317
      wait;
318
   end process MAIN;
319
 
320 55 gedra
-- Bus strobe generator based on address. 32bit recevier mapped to addr. 0x1000
321
-- 32bit transmitter mapped to address 0x2000
322 72 gedra
   wb_stb_32bit_rx <= '1' when wb_adr_o(15 downto 12) = "0001" else '0';
323
   wb_stb_32bit_tx <= '1' when wb_adr_o(15 downto 12) = "0010" else '0';
324
 
325 55 gedra
-- Clock process, 33Mhz Wishbone master freq.
326 72 gedra
   CLKGEN : process
327
   begin
328
      wb_clk_o <= '0';
329
      wait for 15.15 ns;
330
      wb_clk_o <= '1';
331
      wait for 15.15 ns;
332
   end process CLKGEN;
333
 
334 55 gedra
end behav;
335
 
336
 
337
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.