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

Subversion Repositories single_port

[/] [single_port/] [trunk/] [VHDL/] [single_port.vhd] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 mgeng
----------------------------------------------------------------------
2
----                                                              ----
3
---- Single port asynchronous RAM simulation model                ----
4
----                                                              ----
5
---- This file is part of the single_port 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.                                         ----
18
----                                                              ----
19
---- Authors:                                                     ----
20
---- - Robert Paley, rpaley_yid@yahoo.com                         ----
21
---- - Michael Geng, vhdl@MichaelGeng.de                          ----
22
----                                                              ----
23
---- References:                                                  ----
24
----   1. The Designer's Guide to VHDL by Peter Ashenden          ----
25
----      ISBN: 1-55860-270-4 (pbk.)                              ----
26
----   2. Writing Testbenches - Functional Verification of HDL    ----
27
----      models by Janick Bergeron | ISBN: 0-7923-7766-4         ----
28
----                                                              ----
29
----------------------------------------------------------------------
30
----                                                              ----
31
---- Copyright (C) 2005 Authors and OPENCORES.ORG                 ----
32
----                                                              ----
33
---- This source file may be used and distributed without         ----
34
---- restriction provided that this copyright statement is not    ----
35
---- removed from the file and that any derivative work contains  ----
36
---- the original copyright notice and the associated disclaimer. ----
37
----                                                              ----
38
---- This source file is free software; you can redistribute it   ----
39
---- and/or modify it under the terms of the GNU Lesser General   ----
40
---- Public License as published by the Free Software Foundation; ----
41
---- either version 2.1 of the License, or (at your option) any   ----
42
---- later version.                                               ----
43
----                                                              ----
44
---- This source is distributed in the hope that it will be       ----
45
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
46
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
47
---- PURPOSE. See the GNU Lesser General Public License for more  ----
48
---- details.                                                     ----
49
----                                                              ----
50
---- You should have received a copy of the GNU Lesser General    ----
51
---- Public License along with this source; if not, download it   ----
52
---- from http://www.opencores.org/lgpl.shtml                     ----
53
----                                                              ----
54
----------------------------------------------------------------------
55 2 rpaley_yid
--
56 6 mgeng
-- CVS Revision History
57 2 rpaley_yid
--
58 6 mgeng
-- $Log: not supported by cvs2svn $
59 14 mgeng
-- Revision 1.4  2005/11/19 15:18:54  mgeng
60
-- rnw replaced by nce, nwe and noe, tristate drivers added
61
--
62 13 mgeng
-- Revision 1.3  2005/10/25 18:26:52  mgeng
63
-- PAGENUM constant removed because the address bus width provides this information
64
--
65 7 mgeng
-- Revision 1.2  2005/10/12 19:39:27  mgeng
66
-- Buses unconstrained, LGPL header added
67
--
68 6 mgeng
-- Revision 1.1.1.1  2003/01/14 21:48:11  rpaley_yid
69
-- initial checkin 
70 2 rpaley_yid
--
71 6 mgeng
-- Revision 1.1  2003/01/14 17:48:31  Default
72
-- Initial revision
73
--
74
-- Revision 1.1  2002/12/24 18:09:05  Default
75
-- Initial revision
76
--
77 2 rpaley_yid
LIBRARY IEEE;
78
USE IEEE.STD_LOGIC_1164.ALL;
79
USE IEEE.NUMERIC_STD.ALL;
80
USE WORK.single_port_pkg.ALL;
81
USE WORK.linked_list_mem_pkg.ALL;
82
 
83
ENTITY single_port IS
84
  GENERIC (
85 6 mgeng
    rnwtQ : TIME := 1 NS);
86 2 rpaley_yid
  PORT (
87 13 mgeng
    d           : IN  STD_LOGIC_VECTOR;   -- data bus input
88
    q           : OUT STD_LOGIC_VECTOR;   -- data bus output
89
    a           : IN  STD_LOGIC_VECTOR;   -- address bus
90
    nce         : IN  STD_LOGIC;          -- not chip enable
91
    nwe         : IN  STD_LOGIC;          -- not write enable
92
    noe         : IN  STD_LOGIC;          -- not output enable
93
    dealloc_mem : IN  BOOLEAN := FALSE);  -- control signal for deallocating memory,
94
                                          -- only used in the linked list implementation
95 2 rpaley_yid
END ENTITY single_port;
96
 
97
ARCHITECTURE ArrayMemNoFlag OF single_port IS
98
BEGIN
99
 
100 13 mgeng
  mem_proc : PROCESS(d, a, nce, nwe, noe)
101 7 mgeng
    TYPE mem_typ IS ARRAY ( 0 TO 2**a'length-1 ) OF STD_LOGIC_VECTOR(d'RANGE);
102 2 rpaley_yid
    VARIABLE mem : mem_typ;
103
  BEGIN
104 13 mgeng
    IF ( nce = '0' ) AND ( nwe = '0' ) THEN   -- Write
105 2 rpaley_yid
      mem(TO_INTEGER(unsigned(a))) := d;
106 13 mgeng
    END IF;
107
 
108
    IF ( nce = '0' ) AND ( noe = '0' ) THEN   -- Read
109 2 rpaley_yid
      q <= mem(TO_INTEGER(unsigned(a))) AFTER rnwtQ;
110 13 mgeng
    ELSE
111
      q <= (q'RANGE => 'Z') AFTER rnwtQ;
112 2 rpaley_yid
    END IF;
113
  END PROCESS mem_proc;
114
 
115
END ArrayMemNoFlag;
116
 
117
ARCHITECTURE ArrayMem OF single_port IS
118
BEGIN
119
 
120 13 mgeng
  mem_proc : PROCESS(d, a, nce, nwe, noe)
121 7 mgeng
  TYPE mem_typ  IS ARRAY ( 0 TO 2**a'length-1 ) OF BIT_VECTOR(d'RANGE);
122
  TYPE flag_typ IS ARRAY ( 0 TO 2**a'length-1 ) OF BOOLEAN;
123 6 mgeng
  VARIABLE mem  : mem_typ;
124 2 rpaley_yid
  VARIABLE flag : flag_typ;
125
  BEGIN
126 13 mgeng
    IF ( nce = '0' ) AND ( nwe = '0' ) THEN   -- Write
127
      mem( TO_INTEGER(unsigned(a))) := TO_BITVECTOR(d);
128 2 rpaley_yid
      flag(TO_INTEGER(unsigned(a))) := true; -- set valid memory location flag
129 13 mgeng
    END IF;
130
 
131
    IF ( nce = '0' ) AND ( noe = '0' ) THEN   -- Read
132
      IF ( flag(TO_INTEGER(unsigned(a))) = true ) THEN  -- read data, either valid or 'U'
133 2 rpaley_yid
        q <= TO_STDLOGICVECTOR(mem(TO_INTEGER(unsigned(a)))) AFTER rnwtQ;
134
      ELSE -- reading invalid memory location
135 13 mgeng
        q <= (q'RANGE => 'U') AFTER rnwtQ;
136 2 rpaley_yid
      END IF;
137 13 mgeng
    ELSE
138
      q <= (q'RANGE => 'Z') AFTER rnwtQ;
139
    END IF;
140 2 rpaley_yid
  END PROCESS mem_proc;
141
END ArrayMem;
142
 
143
ARCHITECTURE LinkedList OF single_port IS
144 6 mgeng
  CONSTANT WRITE_MEM : BOOLEAN := true;
145
  CONSTANT READ_MEM  : BOOLEAN := false;
146
BEGIN
147 2 rpaley_yid
 
148 13 mgeng
  mem_proc : PROCESS(d, a, nce, nwe, noe, dealloc_mem)
149 6 mgeng
    VARIABLE mem_page_v : mem_page_ptr;
150
    VARIABLE d_v : STD_LOGIC_VECTOR(d'RANGE);
151
    VARIABLE a_v : addr_typ;
152 2 rpaley_yid
  BEGIN
153
    IF NOT dealloc_mem THEN
154
      d_v :=  d;
155 14 mgeng
      if (nce = '0') then
156
         a_v := TO_INTEGER(unsigned(a));
157
      end if;
158 13 mgeng
      IF ( nce = '0' ) AND ( nwe = '0' ) THEN   -- Write
159 6 mgeng
        rw_mem( data       => d_v,
160
                addr       => a_v,
161
                next_cell  => mem_page_v,
162
                write_flag => WRITE_MEM);
163 13 mgeng
      END IF;
164
 
165
      IF ( nce = '0' ) AND ( noe = '0' ) THEN   -- Read
166 6 mgeng
        rw_mem( data       => d_v,
167
                addr       => a_v,
168
                next_cell  => mem_page_v,
169
                write_flag => READ_MEM);
170 13 mgeng
        q <= d_v AFTER rnwtQ;
171
      ELSE
172
        q <= (q'RANGE => 'Z') AFTER rnwtQ;
173 2 rpaley_yid
      END IF;
174
    ELSE -- Deallocate memory from work station memory.
175
      deallocate_mem(mem_page_v);
176
    END IF;
177
  END PROCESS mem_proc;
178
END LinkedList;

powered by: WebSVN 2.1.0

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