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

Subversion Repositories i2s_to_parallel

[/] [i2s_to_parallel/] [trunk/] [i2s_to_parallelTEST.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 primiano
 
2
--------------------------------------------------------------------------------
3
-- Engineer: Primiano Tucci
4
--
5
-- Create Date:   17:26:41 12/19/2008
6
-- Design Name:   i2s_to_parallel
7
-- Description:   
8
-- 
9
-- VHDL Test Bench for module: i2s_to_parallel
10
--
11
--
12
--------------------------------------------------------------------------------
13
LIBRARY ieee;
14
USE ieee.std_logic_1164.ALL;
15
USE ieee.std_logic_unsigned.all;
16
USE ieee.numeric_std.ALL;
17
 
18
ENTITY i2s_to_parallel_tb_vhd IS
19
END i2s_to_parallel_tb_vhd;
20
 
21
ARCHITECTURE behavior OF i2s_to_parallel_tb_vhd IS
22
        constant width : integer := 24;
23
        -- Component Declaration for the Unit Under Test (UUT)
24
        COMPONENT i2s_to_parallel
25
        generic(width : integer := width);
26
        PORT(
27
                LR_CK : IN std_logic;
28
                BIT_CK : IN std_logic;
29
                DIN : IN std_logic;
30
                RESET : IN std_logic;
31
                DATA_L : OUT std_logic_vector(width-1 downto 0);
32
                DATA_R : OUT std_logic_vector(width-1 downto 0);
33
                STROBE : OUT std_logic;
34
                STROBE_LR : OUT std_logic
35
                );
36
        END COMPONENT;
37
 
38
        --Inputs
39
        SIGNAL LR_CK :  std_logic := '0';
40
        SIGNAL BIT_CK :  std_logic := '0';
41
        SIGNAL DIN :  std_logic := '0';
42
        SIGNAL RESET :  std_logic := '0';
43
 
44
        --Outputs
45
        SIGNAL DATA_L :  std_logic_vector(width-1 downto 0);
46
        SIGNAL DATA_R :  std_logic_vector(width-1 downto 0);
47
        SIGNAL STROBE_LR :  std_logic;
48
        SIGNAL STROBE :  std_logic;
49
 
50
BEGIN
51
 
52
        -- Instantiate the Unit Under Test (UUT)
53
        uut: i2s_to_parallel PORT MAP(
54
                LR_CK => LR_CK,
55
                BIT_CK => BIT_CK,
56
                DIN => DIN,
57
                RESET => RESET,
58
                DATA_L => DATA_L,
59
                DATA_R => DATA_R,
60
                STROBE_LR => STROBE_LR,
61
                STROBE => STROBE
62
        );
63
 
64
        tb : PROCESS
65
        subtype test_record is std_logic_vector(23 downto 0);
66
        type test_array is array(positive range<>) of test_record;
67
        constant test_vectors : test_array:= (
68
                "000000000000000000000000",
69
                "111100000000000000000000",
70
                "101010101010101010101010",
71
                "010101010101010101010101",
72
                "111100001111000011110000",
73
                "000011110000111100001111",
74
                "111111110000000011111111",
75
                "111111111111111111111111",
76
                "000000000000000000000000"
77
        ) ;
78
 
79
        constant frequency : integer := 48000;
80
 
81
        constant bit_clock : integer := 64 * 48000;
82
        constant bit_count: integer := 32;
83
        constant Tbcdo : time := 1 ns;
84
        constant Tcklr : time := 500 ps;
85
        variable cur_lrck : boolean := true;
86
        variable cur_bit : std_logic;
87
        variable vector :  test_record;
88
 
89
        BEGIN
90
                RESET <= '0';
91
                LR_CK <= '1';
92
                wait for 100 ns;
93
                RESET <= '1';
94
                -- Reset finished
95
                wait for 100 ns;
96
                BIT_CK <= '1';
97
                wait for 10 ns;
98
                LR_CK <= '0';
99
 
100
                for vector_index in test_vectors'range loop
101
                        vector := test_vectors(vector_index);
102
 
103
                        --for bit_index in -1 to bit_count-2 loop
104
                        --for bit_index in 24 downto -7 loop
105
                        for bit_index in vector'length downto (0-bit_count+(vector'length)+1) loop
106
 
107
                                -- Determine bit to send
108
                                if(bit_index >=0 and bit_index < vector'length) then
109
                                        cur_bit := vector(bit_index);
110
                                else
111
                                        cur_bit := '0';
112
                                end if;
113
 
114
 
115
                                --Bit Clock falling edge
116
                                BIT_CK <= '0';
117
                                --Simulate Delay time of BCKO falling edge to DOUT valid
118
                                wait for Tbcdo;
119
                                --Output current data bit
120
                                DIN <= cur_bit;
121
                                --Wait for remaining clock time
122
                                wait for (1000000000 ns / bit_clock / 2) - Tbcdo;
123
                                --Bit CLock rising edge
124
                                BIT_CK <= '1';
125
                                wait for 1000000000 ns / bit_clock / 2;
126
                        end loop;
127
 
128
                        --Delay time of BCKO falling edge to LRCKO valid
129
                        wait for Tcklr;
130
                        -- Update RL_CK
131
                        if cur_lrck = true then
132
                                LR_CK <= '1';
133
                                assert STROBE_LR = '0' report "Bad STROBE_LR signal" severity FAILURE;
134
 
135
                                assert DATA_L(width-1 downto 0) = vector((vector'length-1) downto (vector'length-width)) report "DATA_L is incorrect" severity FAILURE;
136
                                --assert DATA_L(width-1 downto 0) = vector(width-1 downto 0) report "DATA_L is incorrect" severity FAILURE;
137
                        else
138
                                LR_CK <= '0';
139
                                assert STROBE_LR = '1' report "Bad STROBE_LR signal" severity FAILURE;
140
                                --assert DATA_R(width-1 downto 0) = vector(width-1 downto 0) report "DATA_R is incorrect" severity FAILURE;
141
                                assert DATA_R(width-1 downto 0) = vector((vector'length-1) downto (vector'length-width)) report "DATA_R is incorrect" severity FAILURE;
142
                        end if;
143
 
144
                        cur_lrck := not cur_lrck;
145
                end loop;
146
 
147
                report "Testbench of I2S to Parallel completed successfully!" ;
148
 
149
                wait;
150
        END PROCESS;
151
 
152
END;

powered by: WebSVN 2.1.0

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