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

Subversion Repositories ttl_library

[/] [ttl_library/] [trunk/] [Testbench/] [Testbench_CY7C1021.vhd] - Blame information for rev 11

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 david237
-----------------------------------------------------------------------
2
-- Basic SRAM models (VHDL)                                          --
3
-- David R Brooks                                                    --
4
-- December, 2016.  Perth, Australia                                 --
5
-- Compliance: VHDL 2008                                             --
6
-- Testbench for CY7C1021: 64k x 16 SRAM (Cypress, 10 ns)            --
7
-----------------------------------------------------------------------
8
 
9
library ieee;
10
    use ieee.std_logic_1164.all;
11
    use ieee.std_logic_misc.all;
12
    use ieee.numeric_std.all;
13
 
14
    use work.TTLPrivate.all;
15
    use work.Memories.all;
16
 
17
entity Testbench_CY7C1021 is     -- Top-level bench
18
generic(
19
    OC       : boolean        := false;
20
    StimClk  : std_logic      := '1';
21
    CheckClk : std_logic      := '1';
22
    Period   : time           := 100 ns;
23
    Finish   : time           :=  30 ms;
24
    SevLevel : severity_level := failure
25
);
26
end entity;
27
 
28
architecture Test of Testbench_CY7C1021 is
29
    subtype  TDATA   is std_logic_vector(15 downto 0);
30
    subtype  TADDR   is unsigned(15 downto 0);
31
    constant KADTOP  :  natural := (2**(TADDR'high+1))-1;
32
    subtype  TADNUM  is natural range KADTOP downto 0;
33
    type     TMEM    is array(KADTOP downto 0) of TDATA;
34
 
35
    signal J, B      : unsigned(10 downto 0);           -- Unused
36
    signal D, E      : TDATA;                           -- Expected & actual results
37
    signal CLK, RS   : std_logic;
38
    signal CS,  WR   : std_logic := '1';
39
    signal AD        : TADDR := (others => '0');
40
    signal DI        : TDATA;
41
    signal W         : std_logic;
42
    signal Phase     : natural;
43
    signal OE        : std_logic;
44
    signal BHE, BLE  : std_logic;
45
 
46
    constant AD1     : TADDR := (others => '1');
47
    constant ID1     : unsigned(TDATA'range) := "0000000000000010";
48
 
49
    begin
50
        BHE <= '0';
51
        BLE <= '0';
52
 
53
    -----------------------------------------------------------------------
54
    -- Standard testbench components
55
    -----------------------------------------------------------------------
56
    TB: TTLBench
57
    generic map(
58
        StimClk  => StimClk,
59
        CheckClk => CheckClk,
60
        Period   => Period,
61
        Finish   => Finish,
62
        SevLevel => SevLevel
63
    )
64
    port map(
65
        J    => J,
66
        B    => B,
67
        CLK  => CLK,
68
        RS   => RS,
69
        D    => D,
70
        E    => E
71
    );
72
 
73
    -----------------------------------------------------------------------
74
    -- Generate RAM-specific stimuli
75
    -----------------------------------------------------------------------
76
    CLKX: process(CLK, RS) is
77
    begin
78
        if RS = '0' then
79
            Phase <=  0;
80
            CS    <= '1';
81
            WR    <= '1';
82
            OE    <= '1';
83
        elsif rising_edge(CLK) then
84
            case Phase is
85
                when 0      => CS <= '0';             Phase <= 1;   OE <= '1';
86
                when 1      =>             WR <=  W;  Phase <= 2;   OE <= not W;
87
                when 2      =>             WR <= '1'; Phase <= 3;   OE <= '1';
88
                when others => CS <= '1';  WR <= '1'; Phase <= 0;   OE <= '1';
89
            end case;
90
        end if;
91
    end process;
92
 
93
    UPDATE: process(CLK, RS) is
94
        variable TD : unsigned(TDATA'range);
95
    begin
96
        if RS = '0' then
97
            W  <= '0';
98
            AD <= (others => '0');
99
            TD := ID1;
100
        elsif rising_edge(CLK) and Phase = 3 then
101
            if AD = AD1 then
102
                W <= not W;         -- Alternate read/write cycles
103
            end if;
104
            AD <= AD + 1;
105
            TD := TD + 1;
106
        end if;
107
        DI <= TDATA(TD);
108
    end process;
109
 
110
    -----------------------------------------------------------------------
111
    -- Generate expected results (with zero delays)
112
    -----------------------------------------------------------------------    
113
    process(all) is
114
        variable mem    : TMEM;             -- Testbench memory
115
        variable adr    : TADNUM;
116
        variable QI     : TDATA;
117
    begin
118
        D <= E;                             -- Default, if not active
119
 
120
        if CS = '0' then                    -- Device active
121
            adr := TTL_to_integer(AD);
122
            if rising_edge(WR) then         -- Rising (ie trailing) edge
123
                mem(adr) := DI;
124
            end if;
125
 
126
            if OE = '0' then                -- Reading
127
                QI := mem(adr);
128
            else
129
                QI := (others => 'Z');
130
            end if;
131
 
132
            if OC then                      -- Simulate open collector
133
                for i in D'range loop
134
                    D(i) <= TTL_OC(QI(i));
135
                end loop;
136
            else
137
                D <= QI;
138
            end if;
139
        end if;
140
    end process;
141
 
142
    process(CLK) is                         -- During writes, mimic the data
143
    begin
144
        if falling_edge(CLK) then
145
            if W = '0' then
146
                case Phase is
147
                    when 1 | 2  => D <= E;
148
                    when others => D <= (others => 'Z');
149
                end case;
150
            end if;
151
        end if;
152
    end process;
153
 
154
    E <= DI when (W = '0') and (Phase = 1 or Phase = 2) else (others => 'Z');
155
 
156
    -----------------------------------------------------------------------
157
    -- Device Under Test...                        
158
    -----------------------------------------------------------------------
159
    DUT: CY7C1021
160
generic map(
161
    fnevn => "",            -- Name of even-byte initialisation file (if any)
162
    fnodd => ""             -- Name of odd-byte  initialisation file (if any)
163
)
164
port map(
165
    X_1  => AD(4),  -- A4
166
    X_2  => AD(3),  -- A3
167
    X_3  => AD(2),  -- A2
168
    X_4  => AD(1),  -- A1
169
    X_5  => AD(0),  -- A0
170
    X_6  => CS,     -- CE\
171
    X_7  => E(0),   -- IO0
172
    X_8  => E(1),   -- IO1
173
    X_9  => E(2),   -- IO2
174
    X_10 => E(3),   -- IO3
175
    X_11 => open,   -- Vcc
176
    X_12 => open,   -- GND
177
    X_13 => E(4),   -- IO4
178
    X_14 => E(5),   -- IO5 
179
    X_15 => E(6),   -- IO6
180
    X_16 => E(7),   -- IO7
181
    X_17 => WR,     -- WE\
182
    X_18 => AD(15), -- A15
183
    X_19 => AD(14), -- A14
184
    X_20 => AD(13), -- A13
185
    X_21 => AD(12), -- A12
186
--  X_22
187
--  X_23
188
    X_24 => AD(11), -- A11
189
    X_25 => AD(10), -- A10
190
    X_26 => AD(9),  -- A9
191
    X_27 => AD(8),  -- A8
192
--  X_28
193
    X_29 => E(8),   -- IO8
194
    X_30 => E(9),   -- IO9
195
    X_31 => E(10),  -- IO10
196
    X_32 => E(11),  -- IO11
197
    X_33 => open,   -- VCC
198
    X_34 => open,   -- GND 
199
    X_35 => E(12),  -- IO12
200
    X_36 => E(13),  -- IO13
201
    X_37 => E(14),  -- IO14
202
    X_38 => E(15),  -- IO15
203
    X_39 => BLE,    -- BLE\
204
    X_40 => BHE,    -- BHE\
205
    X_41 => OE,     -- OE\
206
    X_42 => AD(7),  -- A7
207
    X_43 => AD(6),  -- A6
208
    X_44 => AD(5)   -- A5
209
);
210
end architecture Test;

powered by: WebSVN 2.1.0

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