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

Subversion Repositories simu_mem

[/] [simu_mem/] [trunk/] [rtl/] [vhdl/] [ZBT_RAM.vhd] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 mgeng
----------------------------------------------------------------------
2
----                                                              ----
3
---- Synchronous static RAM ("Zero Bus Turnaround" RAM, ZBT RAM)  ----
4
---- simulation model                                             ----
5
----                                                              ----
6
---- This file is part of the simu_mem project.                   ----
7
----                                                              ----
8
---- Description                                                  ----
9
---- This is a functional simulation model for single port        ----
10
---- synchronous static RAMs. Examples for applicable devices:    ----
11
----                                                              ----
12
---- Manufacturer   Device                                        ----
13
---- Samsung        K7N643645M                                    ----
14
---- ISSI           IS61NLP51236                                  ----
15
----                                                              ----
16
---- Advantages of this model:                                    ----
17
---- 1. Consumes few simulator memory if only few memory          ----
18
----    locations are accessed because it internally uses a       ----
19
----    linked list.                                              ----
20
---- 2. Simulates quickly because it does not contain timing      ----
21
----    information. Fast simulator startup time because of the   ----
22
----    linked list.                                              ----
23
---- 3. Usable for any data and address bus width.                ----
24
---- 4. Works at any clock frequency.                             ----
25
---- 5. Programmed in VHDL.                                       ----
26
----                                                              ----
27
---- When this model will not be useful:                          ----
28
---- 1. When it has to be synthesized.                            ----
29
---- 2. When a timing model is required. Ask your RAM vendor for  ----
30
----    a timing model.                                           ----
31
---- 3. When all memory locations have to be accessed in one      ----
32
----    single simulation run. The linked list model will not     ----
33
----    be well suited then.                                      ----
34
---- 4. When your design is in Verilog.                           ----
35
----                                                              ----
36
---- For above reasons a typical application is a functional      ----
37
---- simulation of a design which uses external synchronous       ----
38
---- static RAMs.                                                 ----
39
----                                                              ----
40
---- Authors:                                                     ----
41
---- - Michael Geng, vhdl@MichaelGeng.de                          ----
42
----                                                              ----
43
----------------------------------------------------------------------
44
----                                                              ----
45
---- Copyright (C) 2008 Authors                                   ----
46
----                                                              ----
47
---- This source file may be used and distributed without         ----
48
---- restriction provided that this copyright statement is not    ----
49
---- removed from the file and that any derivative work contains  ----
50
---- the original copyright notice and the associated disclaimer. ----
51
----                                                              ----
52
---- This source file is free software; you can redistribute it   ----
53
---- and/or modify it under the terms of the GNU Lesser General   ----
54
---- Public License as published by the Free Software Foundation; ----
55
---- either version 2.1 of the License, or (at your option) any   ----
56
---- later version.                                               ----
57
----                                                              ----
58
---- This source is distributed in the hope that it will be       ----
59
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
60
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
61
---- PURPOSE. See the GNU Lesser General Public License for more  ----
62
---- details.                                                     ----
63
----                                                              ----
64
---- You should have received a copy of the GNU Lesser General    ----
65
---- Public License along with this source; if not, download it   ----
66
---- from http://www.gnu.org/licenses/lgpl.html                   ----
67
----                                                              ----
68
----------------------------------------------------------------------
69
-- CVS Revision History
70
--
71
-- $Log: not supported by cvs2svn $
72
--
73
LIBRARY IEEE;
74
  USE IEEE.STD_LOGIC_1164.ALL;
75
  USE IEEE.NUMERIC_STD.ALL;
76
 
77
  USE work.ZBT_RAM_pkg.ALL;
78
  USE work.linked_list_mem_pkg.ALL;
79
 
80
ENTITY ZBT_RAM IS
81
  GENERIC (
82
    debug : INTEGER := 0);  -- >= 1: print      write operations
83
                            -- >= 2: print also read  operations
84
  PORT (
85
    Clk   : IN  STD_LOGIC;
86
    D     : IN  STD_LOGIC_VECTOR;
87
    Q     : OUT STD_LOGIC_VECTOR;
88
    A     : IN  STD_LOGIC_VECTOR;
89
    CKE_n : IN  STD_LOGIC;
90
    CS1_n : IN  STD_LOGIC;
91
    CS2   : IN  STD_LOGIC;
92
    CS2_n : IN  STD_LOGIC;
93
    WE_n  : IN  STD_LOGIC;
94
    BW_n  : IN  STD_LOGIC_VECTOR;
95
    OE_n  : IN  STD_LOGIC;
96
    ADV   : IN  STD_LOGIC;
97
    ZZ    : IN  STD_LOGIC;
98
    LBO_n : IN  STD_LOGIC;
99
    dealloc_mem : IN BOOLEAN := FALSE);  -- control SIGNAL for deallocating memory
100
END ENTITY ZBT_RAM;
101
 
102
ARCHITECTURE LinkedList OF ZBT_RAM IS
103
  CONSTANT D_width : INTEGER := D'LENGTH;
104
  CONSTANT A_width : INTEGER := A'LENGTH;
105
 
106
  TYPE mem_page_ptr_array IS ARRAY (0 TO D_width / 9 - 1) of mem_page_ptr;
107
 
108
  SIGNAL state, last_state : state_type := Deselect;
109
  SIGNAL operation         : state_type := Deselect;
110
  SIGNAL DOut              : STD_LOGIC_VECTOR (D_width - 1 DOWNTO 0) := (OTHERS => 'Z');
111
  SIGNAL A_delayed_1       : NATURAL;
112
  SIGNAL A_delayed_2       : NATURAL;
113
  SIGNAL BW_n_delayed_1    : STD_LOGIC_VECTOR (D_width / 9 - 1 DOWNTO 0);
114
  SIGNAL BW_n_delayed_2    : STD_LOGIC_VECTOR (D_width / 9 - 1 DOWNTO 0);
115
  SIGNAL ADV_delayed       : STD_LOGIC;
116
  SIGNAL sleep_count       : INTEGER RANGE 4 DOWNTO 0 := 0;
117
BEGIN
118
  ASSERT BW_n'LENGTH = D'LENGTH / 9
119
    REPORT "Error: BW_n'length must be equal to D'length / 9"
120
    SEVERITY FAILURE;
121
 
122
  mem_proc : PROCESS (Clk, dealloc_mem) IS
123
    VARIABLE state_v    : state_type;
124
    VARIABLE mem_page_v : mem_page_ptr_array;
125
    VARIABLE D_v        : STD_LOGIC_VECTOR (8 DOWNTO 0);
126
  BEGIN
127
    IF dealloc_mem THEN
128
      FOR i IN 0 TO D_width / 9 - 1 LOOP
129
        deallocate_mem (mem_page_v (i));
130
      END LOOP;
131
    ELSIF rising_edge (Clk) THEN
132
      IF (CKE_n = '0') THEN
133
        state_v   := calc_state (CS1_n, CS2, CS2_n, WE_n, BW_n, OE_n, ADV, ZZ, operation);
134
        operation <= calc_operation (state_v, operation);
135
 
136
        IF ((state_v = read) OR (state_v = dummy_read) OR (state_v = write)) THEN
137
          A_delayed_1 <= to_INTEGER (UNSIGNED (A));
138
        END IF;
139
 
140
        IF ((state_v = write) OR (state_v = write_continue)) THEN
141
          BW_n_delayed_1 <= BW_n;
142
        END IF;
143
 
144
        IF (state_v = invalid_state) THEN
145
          REPORT "Invalid state" SEVERITY ERROR;
146
        END IF;
147
 
148
        state          <= state_v;
149
        last_state     <= state;
150
        ADV_delayed    <= ADV;
151
        BW_n_delayed_2 <= BW_n_delayed_1;
152
      END IF;
153
 
154
      IF (ZZ = '1') THEN
155
        sleep_count <= 4;
156
      ELSIF (sleep_count > 0) THEN
157
        sleep_count <= sleep_count - 1;
158
      END IF;
159
 
160
      IF (sleep_count = 0) THEN
161
        IF (((state = write)      OR
162
             (state = read)       OR
163
             (state = dummy_read) OR
164
             (state = write_abort)) AND (CKE_n = '0')) THEN
165
          A_delayed_2 <= A_delayed_1;
166
        ELSIF (ADV_delayed = '1') AND (CKE_n = '0') THEN
167 8 mgeng
          IF (A_delayed_2 MOD 4 < 3) THEN
168 3 mgeng
            A_delayed_2 <= A_delayed_2 + 1;
169
          ELSE
170
            A_delayed_2 <= A_delayed_1;
171
          END IF;
172
        END IF;
173
 
174
        IF ((CKE_n = '0') AND (BW_n_delayed_2 /= (D_width / 9 - 1 DOWNTO 0 => '1')) AND
175
            ((last_state = write) OR (last_state = write_continue))) THEN
176
          FOR i IN 0 TO D_width / 9 - 1 LOOP
177
            IF (BW_n_delayed_2 (i) = '0') THEN
178
              D_v := D (9 * (i + 1) - 1 DOWNTO 9 * i);
179
              rw_mem (data      => D_v,
180
                      addr      => A_delayed_2,
181
                      next_cell => mem_page_v (i),
182
                      operation => write);
183
              IF (Debug >= 1) THEN
184
                 REPORT ("DBG, " & TIME'IMAGE (now) & ": Write " &
185
                   INTEGER'IMAGE (to_INTEGER (UNSIGNED (D_v))) & " to address=" &
186
                   INTEGER'IMAGE (A_delayed_2) & ", bank=" & INTEGER'IMAGE (i));
187
              END IF;
188
            END IF;
189
          END LOOP;
190
        END IF;
191
      ELSIF (sleep_count = 3) THEN
192
        A_delayed_2 <= 0;
193
      END IF;
194
    END IF;
195
 
196
    IF falling_edge (Clk) THEN
197
      IF (sleep_count = 0) THEN
198
        IF (CKE_n = '0') THEN
199
          IF ((last_state = read)      OR (last_state = read_continue) OR
200
              (last_state = dummy_read) OR (last_state = dummy_read_continue)) THEN
201
            FOR i IN 0 TO D_width / 9 - 1 LOOP
202
              rw_mem (data      => D_v,
203
                      addr      => A_delayed_2,
204
                      next_cell => mem_page_v (i),
205
                      operation => read);
206
              DOut (9 * (i + 1) - 1 DOWNTO 9 * i) <= D_v;
207
              IF (Debug >= 2) THEN
208
                REPORT ("DBG, " & TIME'IMAGE (now) & ": Read " &
209
                  INTEGER'IMAGE (to_INTEGER (UNSIGNED (D_v))) & " from address=" &
210
                  INTEGER'IMAGE (A_delayed_2) & ", bank=" & INTEGER'IMAGE (i));
211
              END IF;
212
            END LOOP;
213
          ELSE
214
             DOut <= (OTHERS => 'Z');
215
          END IF;
216
        END IF;
217
      ELSE
218
        DOut <= (OTHERS => 'Z');
219
      END IF;
220
    END IF;
221
  END PROCESS mem_proc;
222
 
223
  Q <= (Q'RANGE => 'Z') WHEN (OE_n = '1') ELSE DOut;
224
END LinkedList;

powered by: WebSVN 2.1.0

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