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

Subversion Repositories simu_mem

[/] [simu_mem/] [trunk/] [rtl/] [vhdl/] [AS_RAM.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mgeng
----------------------------------------------------------------------
2
----                                                              ----
3
---- Single port asynchronous static RAM simulation model         ----
4
----                                                              ----
5
---- This file is part of the simu_mem project                    ----
6
----                                                              ----
7
---- Description                                                  ----
8
---- This is a single port asynchronous memory. This files        ----
9
---- describes three architectures. Two architectures are         ----
10
---- traditional array based memories. One describes the memory   ----
11
---- as an array of  STD_LOGIC_VECTOR, and the other describes    ----
12
---- the ARRAY as BIT_VECTOR.                                     ----
13
---- The third architecture describes the memory arranged as a    ----
14
---- linked list in order to conserve computer memory usage. The  ----
15
---- memory is organized as a linked list of BIT_VECTOR arrays    ----
16
---- whose size is defined by the constant PAGEDEPTH in           ----
17
---- single_port_pkg.vhd. Example for an applicable device:       ----
18
----                                                              ----
19
---- Manufacturer   Device                                        ----
20
---- IDT            IDT71V424                                     ----
21
----                                                              ----
22
---- Advantages of this model:                                    ----
23
---- 1. User can choose between an array implementation (for      ----
24
----    applications which access almost all memory locations in  ----
25
----    on single simulation) or a linked list implementation     ----
26
----    which consumes only few simulator memory otherwise.       ----
27
---- 2. Simulates quickly because it does not contain timing      ----
28
----    information. Fast simulator startup time of the linked    ----
29
----    list model.                                               ----
30
---- 3. Usable for any data and address bus width.                ----
31
---- 4. Works at any clock frequency.                             ----
32
---- 5. Programmed in VHDL.                                       ----
33
----                                                              ----
34
---- When this model will not be useful:                          ----
35
---- 1. When it has to be synthesized.                            ----
36
---- 2. When a timing model is required. Ask your RAM vendor for  ----
37
----    a timing model.                                           ----
38
---- 3. When your design is in Verilog.                           ----
39
----                                                              ----
40
---- Authors:                                                     ----
41
---- - Robert Paley, rpaley_yid@yahoo.com                         ----
42
---- - Michael Geng, vhdl@MichaelGeng.de                          ----
43
----                                                              ----
44
----------------------------------------------------------------------
45
----                                                              ----
46
---- Copyright (C) 2005 Authors                                   ----
47
----                                                              ----
48
---- This source file may be used and distributed without         ----
49
---- restriction provided that this copyright statement is not    ----
50
---- removed from the file and that any derivative work contains  ----
51
---- the original copyright notice and the associated disclaimer. ----
52
----                                                              ----
53
---- This source file is free software; you can redistribute it   ----
54
---- and/or modify it under the terms of the GNU Lesser General   ----
55
---- Public License as published by the Free Software Foundation; ----
56
---- either version 2.1 of the License, or (at your option) any   ----
57
---- later version.                                               ----
58
----                                                              ----
59
---- This source is distributed in the hope that it will be       ----
60
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
61
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
62
---- PURPOSE. See the GNU Lesser General Public License for more  ----
63
---- details.                                                     ----
64
----                                                              ----
65
---- You should have received a copy of the GNU Lesser General    ----
66
---- Public License along with this source; if not, download it   ----
67
---- from http://www.opencores.org/lgpl.shtml                     ----
68
----                                                              ----
69
----------------------------------------------------------------------
70
--
71
-- CVS Revision History
72
--
73
-- $Log: not supported by cvs2svn $
74
--
75
LIBRARY IEEE;
76
  USE IEEE.STD_LOGIC_1164.ALL;
77
  USE IEEE.NUMERIC_STD.ALL;
78
 
79
  USE work.linked_list_mem_pkg.ALL;
80
 
81
ENTITY ASRAM IS
82
  PORT (
83
    D           : IN    STD_LOGIC_VECTOR;   -- data in
84
    Q           : OUT   STD_LOGIC_VECTOR;   -- data out
85
    A           : IN    STD_LOGIC_VECTOR;   -- address bus
86
    CE_n        : IN    STD_LOGIC;          -- not chip enable
87
    WE_n        : IN    STD_LOGIC;          -- not write enable
88
    OE_n        : IN    STD_LOGIC;          -- not output enable
89
    dealloc_mem : IN    BOOLEAN := FALSE);  -- control signal for deallocating memory,
90
END ENTITY ASRAM;
91
 
92
ARCHITECTURE array_mem_no_flag OF ASRAM IS
93
BEGIN
94
  ASSERT D'LENGTH = Q'LENGTH
95
    REPORT "D and Q must have same the length"
96
    SEVERITY FAILURE;
97
 
98
  mem_proc : PROCESS (D, A, CE_n, WE_n, OE_n)
99
    TYPE mem_typ IS ARRAY (0 TO 2 ** A'length - 1) OF STD_LOGIC_VECTOR (D'RANGE);
100
    VARIABLE mem : mem_typ;
101
  BEGIN
102
    IF (CE_n = '0') AND (WE_n = '0') THEN   -- Write
103
      mem (TO_INTEGER (unsigned (A))) := D;
104
    END IF;
105
 
106
    IF (CE_n = '0') AND (OE_n = '0') THEN   -- Read
107
      Q <= mem (TO_INTEGER (unsigned (A)));
108
    ELSE
109
      Q <= (Q'RANGE => 'Z');
110
    END IF;
111
  END PROCESS mem_proc;
112
 
113
END array_mem_no_flag;
114
 
115
ARCHITECTURE array_mem OF ASRAM IS
116
BEGIN
117
  ASSERT D'LENGTH = Q'LENGTH
118
    REPORT "D and Q must have same the length"
119
    SEVERITY FAILURE;
120
 
121
  mem_proc : PROCESS (D, A, CE_n, WE_n, OE_n)
122
  TYPE mem_typ  IS ARRAY (0 TO 2 ** A'length - 1) OF BIT_VECTOR (D'RANGE);
123
  TYPE flag_typ IS ARRAY (0 TO 2 ** A'length - 1) OF BOOLEAN;
124
  VARIABLE mem  : mem_typ;
125
  VARIABLE flag : flag_typ;
126
  BEGIN
127
    IF (CE_n = '0') AND (WE_n = '0') THEN   -- Write
128
      mem (TO_INTEGER (unsigned (A))) := TO_BITVECTOR (D);
129
      flag (TO_INTEGER (unsigned (A))) := TRUE; -- set valid memory location flag
130
    END IF;
131
 
132
    IF (CE_n = '0') AND (OE_n = '0') THEN   -- Read
133
      IF (flag (TO_INTEGER (unsigned (A))) = TRUE) THEN  -- read data, either valid or 'U'
134
        Q <= TO_STDLOGICVECTOR (mem (TO_INTEGER (unsigned (A))));
135
      ELSE -- reading invalid memory location
136
        Q <= (Q'RANGE => 'U');
137
      END IF;
138
    ELSE
139
      Q <= (Q'RANGE => 'Z');
140
    END IF;
141
  END PROCESS mem_proc;
142
END array_mem;
143
 
144
ARCHITECTURE linked_list OF ASRAM IS
145
BEGIN
146
  ASSERT D'LENGTH = Q'LENGTH
147
    REPORT "D and Q must have same the length"
148
    SEVERITY FAILURE;
149
 
150
  mem_proc : PROCESS (D, A, CE_n, WE_n, OE_n, dealloc_mem)
151
    VARIABLE mem_page_v : mem_page_ptr;
152
    VARIABLE D_v : STD_LOGIC_VECTOR (D'RANGE);
153
    VARIABLE A_v : NATURAL;
154
  BEGIN
155
    IF dealloc_mem THEN
156
       -- deallocate simulator memory
157
      deallocate_mem (mem_page_v);
158
    ELSE
159
      D_v :=  D;
160
      if (CE_n = '0') then
161
         A_v := TO_INTEGER (unsigned (A));
162
      end if;
163
      IF (CE_n = '0') AND (WE_n = '0') THEN   -- Write
164
        rw_mem (data      => D_v,
165
                addr      => A_v,
166
                next_cell => mem_page_v,
167
                operation => write);
168
      END IF;
169
 
170
      IF (CE_n = '0') AND (OE_n = '0') THEN   -- Read
171
        rw_mem (data      => D_v,
172
                addr      => A_v,
173
                next_cell => mem_page_v,
174
                operation => read);
175
        Q <= D_v;
176
      ELSE
177
        Q <= (D'RANGE => 'Z');
178
      END IF;
179
    END IF;
180
  END PROCESS mem_proc;
181
END linked_list;

powered by: WebSVN 2.1.0

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