OpenCores
URL https://opencores.org/ocsvn/8b10b_encdec/8b10b_encdec/trunk

Subversion Repositories 8b10b_encdec

[/] [8b10b_encdec/] [trunk/] [enc_8b10b_TB.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kboyette
-------------------------------------------------------------------------------
2
--
3
-- Title        : Test Bench for enc_8b10b
4
-- Design       : 8b/10b Encoder Test Bench
5
-- Project      : 8000 - 8b10b_encdec
6
-- Author       : Ken Boyette
7
-- Company      : Critia Computer, Inc.
8
--
9
-------------------------------------------------------------------------------
10
--
11
-- File                 : enc_8b10b_TB.vhd
12
-- Version              : 1.0
13
-- Generated    : 09.25.2006
14
-- From                 : y:\Projects\8000\FPGA\VHDLSource\8b10b\8b10_enc.vhd
15
-- By                   : Active-HDL Built-in Test Bench Generator ver. 1.2s
16
--
17
-------------------------------------------------------------------------------
18
--
19
-- Description : Test Bench for enc_8b10b_tb
20
--
21
--      This testbench provides a sequence of data pattern stimuli for the
22
--      enc_8b10b component.  It latches the encoded output and provides this
23
--      for waveform display during simulation.  The test pattern generator
24
--      alternately drives all data patterns and then the 12 defined K patterns.
25
-------------------------------------------------------------------------------
26
-- This program is licensed under the GPL
27
-------------------------------------------------------------------------------
28
 
29
library ieee;
30
use ieee.std_logic_1164.all;
31
use ieee.std_logic_unsigned.all;
32
 
33
entity enc_8b10b_tb is
34
end enc_8b10b_tb;
35
 
36
architecture TB_ARCHITECTURE of enc_8b10b_tb is
37
 
38
        component enc_8b10b
39
        port(
40
                RESET : in std_logic;
41
                SBYTECLK : in std_logic;
42
                KI : in std_logic;
43
                AI : in std_logic;
44
                BI : in std_logic;
45
                CI : in std_logic;
46
                DI : in std_logic;
47
                EI : in std_logic;
48
                FI : in std_logic;
49
                GI : in std_logic;
50
                HI : in std_logic;
51
                AO : out std_logic;
52
                BO : out std_logic;
53
                CO : out std_logic;
54
                DO : out std_logic;
55
                EO : out std_logic;
56
                FO : out std_logic;
57
                IO : out std_logic;
58
                GO : out std_logic;
59
                HO : out std_logic;
60
                JO : out std_logic
61
                );
62
        end component;
63
 
64
        -- Special character code values
65
        constant K28d0 : std_logic_vector := "00011100"; -- Balanced
66
        constant K28d1 : std_logic_vector := "00111100"; -- Unbalanced comma
67
        constant K28d2 : std_logic_vector := "01011100"; -- Unbalanced
68
        constant K28d3 : std_logic_vector := "01111100"; -- Unbalanced
69
        constant K28d4 : std_logic_vector := "10011100"; -- Balanced
70
        constant K28d5 : std_logic_vector := "10111100"; -- Unbalanced comma
71
        constant K28d6 : std_logic_vector := "11011100"; -- Unbalanced
72
        constant K28d7 : std_logic_vector := "11111100"; -- Balanced comma
73
        constant K23d7 : std_logic_vector := "11110111"; -- Balanced
74
        constant K27d7 : std_logic_vector := "11111011"; -- Balanced
75
        constant K29d7 : std_logic_vector := "11111101"; -- Balanced
76
        constant K30d7 : std_logic_vector := "11111110"; -- Balanced
77
 
78
        -- Stimulus signals - mapped to the input  of enc_8b10b
79
        signal TRESET : std_logic;
80
        signal TBYTECLK : std_logic;
81
        signal TKO : std_logic;
82
        signal TAO : std_logic;
83
        signal TBO : std_logic;
84
        signal TCO : std_logic;
85
        signal TDO : std_logic;
86
        signal TEO : std_logic;
87
        signal TFO : std_logic;
88
        signal TGO : std_logic;
89
        signal THO : std_logic;
90
 
91
        -- Observed signals - mapped from output of enc_8b10b
92
        signal TA : std_logic;
93
        signal TB : std_logic;
94
        signal TC : std_logic;
95
        signal TD : std_logic;
96
        signal TE : std_logic;
97
        signal TF : std_logic;
98
        signal TI : std_logic;
99
        signal TG : std_logic;
100
        signal TH : std_logic;
101
        signal TJ : std_logic;
102
 
103
        -- Signals for TestBench control functions
104
        signal tchar : std_logic_vector (7 downto 0) ;           -- All character vector
105
        signal kcounter : std_logic_vector (3 downto 0) ;        -- K character counter
106
        signal dcounter : std_logic_vector (7 downto 0) ;        -- D value counter
107
        signal tcharout, tlcharout : std_logic_vector (9 downto 0) ;     -- Character output vector
108
        signal tclken : std_logic ; -- Enables clock after short delay starting up
109
        signal tcnten : std_logic ; -- Enables count after 1 cycle
110
        signal tks : std_logic ; -- Use to select control function of encoder
111
        signal dk : std_logic ; -- '0' if D, '1' if K
112
 
113
begin
114
        ---------------------------------------------------------------------------
115
        -- Instantiate module
116
        ---------------------------------------------------------------------------
117
        encoder : enc_8b10b
118
                port map (
119
                        RESET => TRESET,
120
                        SBYTECLK => TBYTECLK,
121
                        KI => TKO,
122
                        AI => TAO,
123
                        BI => TBO,
124
                        CI => TCO,
125
                        DI => TDO,
126
                        EI => TEO,
127
                        FI => TFO,
128
                        GI => TGO,
129
                        HI => THO,
130
                        AO => TA,
131
                        BO => TB,
132
                        CO => TC,
133
                        DO => TD,
134
                        EO => TE,
135
                        IO => TI,
136
                        FO => TF,
137
                        GO => TG,
138
                        HO => TH,
139
                        JO => TJ
140
                ) ;
141
 
142
TRESET <= '1', '0' after 200 ns ; -- Start with a valid reset for 100ns
143
tclken <= '0', '1' after 10 ns ; -- Start clock with valid state, then 10MHz
144
 
145
process (TBYTECLK, tclken)
146
begin
147
        If (tclken = '0') then
148
                TBYTECLK <= '0';
149
        else TBYTECLK <= (not TBYTECLK) after 50 ns ;   -- Generate 10MHz byte clock
150
        end if;
151
end process ;
152
 
153
process (TRESET, TBYTECLK)
154
begin
155
        if (TRESET = '1') then  -- Delay count 1 cycle 
156
                tcnten <= '0' ;
157
        elsif (TBYTECLK'event and TBYTECLK = '0') then
158
                tcnten <= '1' ;
159
        end if ;
160
end process ;
161
 
162
process (TRESET, TBYTECLK, tks, tcnten, kcounter, dcounter, tchar)
163
begin
164
        if (TRESET = '1') then
165
                tchar <= "00000000" ;
166
                tks <= '1' ; -- Set for K initially
167
                dk <= '0' ;
168
                kcounter <= "0000" ; -- Preset K counter
169
                dcounter <= "00000000" ;        -- Preset D counter
170
        elsif (TBYTECLK'event and TBYTECLK = '1') then
171
                dk <= tks ;
172
                if tks = '1' then       -- Output K characters
173
                        kcounter <= kcounter + tcnten ; -- Increment counter
174
                        dcounter <= "00000000" ;
175
                        case kcounter is
176
                                when "0000" => tchar <= K28d0 ;
177
                                when "0001" => tchar <= K28d1 ;
178
                                when "0010" => tchar <= K28d2 ;
179
                                when "0011" => tchar <= K28d3 ;
180
                                when "0100" => tchar <= K28d4 ;
181
                                when "0101" => tchar <= K28d5 ;
182
                                when "0110" => tchar <= K28d6 ;
183
                                when "0111" => tchar <= K28d7 ;
184
                                when "1000" => tchar <= K23d7 ;
185
                                when "1001" => tchar <= K27d7 ;
186
                                when "1010" => tchar <= K29d7 ;
187
                                when "1011" => tchar <= K30d7 ;
188
                                        tks <= '0' ;     -- Switch to D output
189
                                when "1100" => tchar <= "00000000" ;
190
                                when others => tchar(7 downto 0) <= K28d5 ;
191
                        end case;
192
                else dcounter <= dcounter + tcnten ;    -- Output D values
193
                        tchar <= dcounter ;
194
                        if dcounter = "11111111" then
195
                                tks <= '1' ;    -- Repeat K portion
196
                                kcounter <= "0000" ; -- Reset K counter
197
                        end if;
198
                end if ;
199
        end if;
200
end process ;
201
 
202
-- Latch encoder output each rising edge for simulation display
203
process (TBYTECLK)
204
begin
205
        if (TBYTECLK'event and TBYTECLK = '1') then
206
                tlcharout(0) <= TA;
207
                tlcharout(1) <= TB;
208
                tlcharout(2) <= TC;
209
                tlcharout(3) <= TD;
210
                tlcharout(4) <= TE;
211
                tlcharout(5) <= TI;
212
                tlcharout(6) <= TF;
213
                tlcharout(7) <= TG;
214
                tlcharout(8) <= TH;
215
                tlcharout(9) <= TJ;
216
        end if;
217
end process ;
218
 
219
-- Connect our test values to the encoder inputs
220
TAO <= tchar(0);
221
TBO <= tchar(1);
222
TCO <= tchar(2);
223
TDO <= tchar(3);
224
TEO <= tchar(4);
225
TFO <= tchar(5);
226
TGO <= tchar(6);
227
THO <= tchar(7);
228
TKO <= dk;
229
 
230
-- Monitor encoder output
231
tcharout(0) <= TA;
232
tcharout(1) <= TB;
233
tcharout(2) <= TC;
234
tcharout(3) <= TD;
235
tcharout(4) <= TE;
236
tcharout(5) <= TI;
237
tcharout(6) <= TF;
238
tcharout(7) <= TG;
239
tcharout(8) <= TH;
240
tcharout(9) <= TJ;
241
 
242
end TB_ARCHITECTURE;
243
 
244
 

powered by: WebSVN 2.1.0

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