| 1 |
10 |
david237 |
-- ======================================================================================
|
| 2 |
|
|
-- A generic VHDL entity for a typical SRAM with complete timing parameters
|
| 3 |
|
|
--
|
| 4 |
|
|
-- Static memory, version 1.3 9. August 1996
|
| 5 |
|
|
-- Changes by D. R. Brooks, see below
|
| 6 |
|
|
-- ======================================================================================
|
| 7 |
|
|
--
|
| 8 |
|
|
-- (C) Andre' Klindworth, Dept. of Computer Science
|
| 9 |
|
|
-- University of Hamburg
|
| 10 |
|
|
-- Vogt-Koelln-Str. 30
|
| 11 |
|
|
-- 22527 Hamburg
|
| 12 |
|
|
-- klindwor@informatik.uni-hamburg.de
|
| 13 |
|
|
--
|
| 14 |
|
|
-- This VHDL code may be freely copied as long as the copyright note isn't removed from
|
| 15 |
|
|
-- its header. Full affiliation of anybody modifying this file shall be added to the
|
| 16 |
|
|
-- header prior to further distribution.
|
| 17 |
|
|
-- The download procedure originates from DLX memory-behaviour.vhdl:
|
| 18 |
|
|
-- Copyright (C) 1993, Peter J. Ashenden
|
| 19 |
|
|
-- Mail: Dept. Computer Science
|
| 20 |
|
|
-- University of Adelaide, SA 5005, Australia
|
| 21 |
|
|
-- e-mail: petera@cs.adelaide.edu.au
|
| 22 |
|
|
--
|
| 23 |
|
|
-- Changes by D. R. Brooks, Perth, Australia. <daveb@iinet.net.au>
|
| 24 |
|
|
-- 1. Changed file statements to suit VHDL-2008
|
| 25 |
|
|
-- 2. Removed references to obsolete package "IEEE.std_logic_unsigned"
|
| 26 |
|
|
-- 3. Array initialisation is by specifying the value, not a boolean.
|
| 27 |
|
|
-- 4. Cleaned up tabbing.
|
| 28 |
|
|
-- 5. Array size is inferred from the connected address & data busses.
|
| 29 |
|
|
-- 6. IO is split into IN & OUT ports, to facilitate higher-level connections.
|
| 30 |
|
|
--
|
| 31 |
|
|
-- Features:
|
| 32 |
|
|
--
|
| 33 |
|
|
-- o generic memory size, width and timing parameters
|
| 34 |
|
|
--
|
| 35 |
|
|
-- o 18 typical SRAM timing parameters supported
|
| 36 |
|
|
--
|
| 37 |
|
|
-- o clear-on-power-up and/or download-on-power-up if requested by generic
|
| 38 |
|
|
--
|
| 39 |
|
|
-- o RAM dump into or download from an ASCII-file at any time possible
|
| 40 |
|
|
-- (requested by signal)
|
| 41 |
|
|
--
|
| 42 |
|
|
-- o pair of active-low and active-high Chip-Enable signals
|
| 43 |
|
|
--
|
| 44 |
|
|
-- o nWE-only memory access control
|
| 45 |
|
|
--
|
| 46 |
|
|
-- o many (but not all) timing and access control violations reported by assertions
|
| 47 |
|
|
--
|
| 48 |
|
|
--
|
| 49 |
|
|
--
|
| 50 |
|
|
-- RAM data file format:
|
| 51 |
|
|
--
|
| 52 |
|
|
-- The format of the ASCII-files for RAM download or dump is very simple:
|
| 53 |
|
|
-- Each line of the file consists of the memory address (given as a decimal number).
|
| 54 |
|
|
-- and the corresponding RAM data at this address (given as a binary number).
|
| 55 |
|
|
-- Any text in a line following the width-th digit of the binary number is ignored.
|
| 56 |
|
|
-- Please notice that address and data have to be seperated by a SINGLE blank,
|
| 57 |
|
|
-- that the binary number must have as many digits as specified by the generic width,
|
| 58 |
|
|
-- and that no additional blanks or blank lines are tolerated. Example:
|
| 59 |
|
|
--
|
| 60 |
|
|
-- 0 0111011010111101 This text is interpreted as a comment
|
| 61 |
|
|
-- 1 1011101010110010
|
| 62 |
|
|
-- 17 0010001001000100
|
| 63 |
|
|
--
|
| 64 |
|
|
--
|
| 65 |
|
|
-- Hints & traps:
|
| 66 |
|
|
--
|
| 67 |
|
|
-- If you have problems using this model, please feel free to to send me an e-mail.
|
| 68 |
|
|
-- Here are some potential problems which have been reported to me:
|
| 69 |
|
|
--
|
| 70 |
|
|
-- o There's a potential problem with passing the filenames for RAM download or
|
| 71 |
|
|
-- dump via port signals of type string. E.g. for Synopsys VSS, the string
|
| 72 |
|
|
-- assigned to a filename-port should have the same length as its default value.
|
| 73 |
|
|
-- If you are sure that you need a download or dump only once during a single
|
| 74 |
|
|
-- simulation run, you may remove the filename-ports from the interface list
|
| 75 |
|
|
-- and replace the constant string in the corresponding file declarations.
|
| 76 |
|
|
--
|
| 77 |
|
|
-- o Some simulators do not implement all of the standard TEXTIO-functions as
|
| 78 |
|
|
-- specified by the IEEE Std 1076-87 and IEEE Std 1076-93. Check it out.
|
| 79 |
|
|
-- If any of the (multiple overloaded) writeline, write, readline or
|
| 80 |
|
|
-- read functions that are used in this model is missing, you have to
|
| 81 |
|
|
-- write your own version and you should complain at your simulator tool
|
| 82 |
|
|
-- vendor for this deviation from the standard.
|
| 83 |
|
|
--
|
| 84 |
|
|
-- o If you are about to simulate a large RAM e.g. 4M * 32 Bit, representing
|
| 85 |
|
|
-- the RAM with a static array variable of 4 * 32 std_logic values uses a large
|
| 86 |
|
|
-- amount of memory and may result in an out-of-memory error. A potential remedy
|
| 87 |
|
|
-- for this is to use a dynamic data type, allocating memory for small blocks of
|
| 88 |
|
|
-- RAM data (e.g. a single word) only if they are actually referenced during a
|
| 89 |
|
|
-- simulation run. A version of the SRAM model with dynamic memory allocation
|
| 90 |
|
|
-- shall be available at the same WWW-site were you obtained this file or at:
|
| 91 |
|
|
-- http://tech-www.informatik.uni-hamburg.de/vhdl/models/sram/sram.html
|
| 92 |
|
|
--
|
| 93 |
|
|
--
|
| 94 |
|
|
-- Bugs:
|
| 95 |
|
|
--
|
| 96 |
|
|
-- No severe bugs have been found so far. Please report any bugs:
|
| 97 |
|
|
-- e-mail: klindwor@informatik.uni-hamburg.de
|
| 98 |
|
|
--
|
| 99 |
|
|
-- Bug Observed: ModelSim SE-64 vcom 10.1c crashes with Code 211 (segmentation fault), when
|
| 100 |
|
|
-- 'DELAYED is applied to a std_logic_vector. 'DELAYED works on single std_logic, but
|
| 101 |
|
|
-- fails when used on an array element (Attribute "DELAYED" requires a static signal prefix).
|
| 102 |
|
|
--
|
| 103 |
|
|
|
| 104 |
|
|
|
| 105 |
|
|
library ieee;
|
| 106 |
|
|
use ieee.std_logic_1164.all;
|
| 107 |
|
|
use ieee.numeric_std.all;
|
| 108 |
|
|
|
| 109 |
|
|
use std.textio.all;
|
| 110 |
|
|
|
| 111 |
|
|
ENTITY sram IS
|
| 112 |
|
|
GENERIC (
|
| 113 |
|
|
value_on_power_up : std_logic := 'U'; -- Memory array is filled with this at start
|
| 114 |
|
|
download_on_power_up : boolean := TRUE; -- if TRUE, RAM is downloaded at start of simulation
|
| 115 |
|
|
trace_ram_load : boolean := TRUE; -- Echoes the data downloaded to the RAM on the screen
|
| 116 |
|
|
-- (included for debugging purposes)
|
| 117 |
|
|
enable_nWE_only_control: boolean := TRUE; -- Read-/write access controlled by nWE only
|
| 118 |
|
|
-- nOE may be kept active all the time
|
| 119 |
|
|
-- READ-cycle timing parameters
|
| 120 |
|
|
tAA_max : TIME := 20 NS; -- Address Access Time
|
| 121 |
|
|
tOHA_min : TIME := 3 NS; -- Output Hold Time
|
| 122 |
|
|
tACE_max : TIME := 20 NS; -- nCE/CE2 Access Time
|
| 123 |
|
|
tDOE_max : TIME := 8 NS; -- nOE Access Time
|
| 124 |
|
|
tLZOE_min : TIME := 0 NS; -- nOE to Low-Z Output
|
| 125 |
|
|
tHZOE_max : TIME := 8 NS; -- OE to High-Z Output
|
| 126 |
|
|
tLZCE_min : TIME := 3 NS; -- nCE/CE2 to Low-Z Output
|
| 127 |
|
|
tHZCE_max : TIME := 10 NS; -- CE/nCE2 to High Z Output
|
| 128 |
|
|
|
| 129 |
|
|
-- WRITE-cycle timing parameters
|
| 130 |
|
|
tWC_min : TIME := 20 NS; -- Write Cycle Time
|
| 131 |
|
|
tSCE_min : TIME := 18 NS; -- nCE/CE2 to Write End
|
| 132 |
|
|
tAW_min : TIME := 15 NS; -- tAW Address Set-up Time to Write End
|
| 133 |
|
|
tHA_min : TIME := 0 NS; -- tHA Address Hold from Write End
|
| 134 |
|
|
tSA_min : TIME := 0 NS; -- Address Set-up Time
|
| 135 |
|
|
tPWE_min : TIME := 13 NS; -- nWE Pulse Width
|
| 136 |
|
|
tSD_min : TIME := 10 NS; -- Data Set-up to Write End
|
| 137 |
|
|
tHD_min : TIME := 0 NS; -- Data Hold from Write End
|
| 138 |
|
|
tHZWE_max : TIME := 10 NS; -- nWE Low to High-Z Output
|
| 139 |
|
|
tLZWE_min : TIME := 0 NS -- nWE High to Low-Z Output
|
| 140 |
|
|
);
|
| 141 |
|
|
PORT (
|
| 142 |
|
|
nCE : IN std_logic := '1'; -- low-active Chip-Enable of the SRAM device; defaults to '1' (inactive)
|
| 143 |
|
|
nOE : IN std_logic := '1'; -- low-active Output-Enable of the SRAM device; defaults to '1' (inactive)
|
| 144 |
|
|
nWE : IN std_logic := '1'; -- low-active Write-Enable of the SRAM device; defaults to '1' (inactive)
|
| 145 |
|
|
A : IN std_logic_vector; -- address bus of the SRAM device
|
| 146 |
|
|
D : IN std_logic_vector; -- data bus to the SRAM device
|
| 147 |
|
|
Q : OUT std_logic_vector; -- data bus from the SRAM device
|
| 148 |
|
|
CE2 : IN std_logic := '1'; -- high-active Chip-Enable of the SRAM device; defaults to '1' (active)
|
| 149 |
|
|
download : IN boolean := FALSE; -- A FALSE-to-TRUE transition on this signal downloads the data
|
| 150 |
|
|
-- in file specified by download_filename to the RAM
|
| 151 |
|
|
download_filename: IN string := "sram_load.dat"; -- name of the download source file
|
| 152 |
|
|
-- Passing the filename via a port of type
|
| 153 |
|
|
-- ********** string may cause a problem with some
|
| 154 |
|
|
-- WATCH OUT! simulators. The string signal assigned
|
| 155 |
|
|
-- ********** to the port at least should have the
|
| 156 |
|
|
-- same length as the default value.
|
| 157 |
|
|
dump : IN boolean := FALSE; -- A FALSE-to-TRUE transition on this signal dumps
|
| 158 |
|
|
-- the current content of the memory to the file
|
| 159 |
|
|
-- specified by dump_filename.
|
| 160 |
|
|
dump_start : IN natural := 0; -- Written to the dump-file are the memory words from memory address
|
| 161 |
|
|
dump_end : IN natural := 0; -- dump_start to address dump_end (default: all addresses)
|
| 162 |
|
|
dump_filename:IN string := "sram_dump.dat" -- name of the dump destination file
|
| 163 |
|
|
-- (See note at port download_filename)
|
| 164 |
|
|
);
|
| 165 |
|
|
END entity sram;
|
| 166 |
|
|
|
| 167 |
|
|
|
| 168 |
|
|
ARCHITECTURE behavior OF sram IS
|
| 169 |
|
|
subtype ibyte is integer range 0 to 255; -- 8-bit integer
|
| 170 |
|
|
type iline is array(0 to 299) of ibyte;
|
| 171 |
|
|
|
| 172 |
|
|
constant dwidth : positive := D'length;
|
| 173 |
|
|
constant awidth : positive := A'length;
|
| 174 |
|
|
constant nwords : positive := 2**awidth;
|
| 175 |
|
|
|
| 176 |
|
|
-----------------------------------------------------------------------
|
| 177 |
|
|
-- Return TRUE if all bits are '0' or '1'
|
| 178 |
|
|
-----------------------------------------------------------------------
|
| 179 |
|
|
FUNCTION Check_For_Valid_Data (a: std_logic_vector) RETURN BOOLEAN IS
|
| 180 |
|
|
VARIABLE result: BOOLEAN;
|
| 181 |
|
|
BEGIN
|
| 182 |
|
|
result := TRUE;
|
| 183 |
|
|
FOR i IN a'RANGE LOOP
|
| 184 |
|
|
result := (a(i) = '0') OR (a(i) = '1');
|
| 185 |
|
|
IF NOT result THEN
|
| 186 |
|
|
EXIT;
|
| 187 |
|
|
END IF;
|
| 188 |
|
|
END LOOP;
|
| 189 |
|
|
RETURN result;
|
| 190 |
|
|
END Check_For_Valid_Data;
|
| 191 |
|
|
|
| 192 |
|
|
-----------------------------------------------------------------------
|
| 193 |
|
|
-- Return TRUE if all bits are 'Z'
|
| 194 |
|
|
-----------------------------------------------------------------------
|
| 195 |
|
|
FUNCTION Check_For_Tristate (a: std_logic_vector) RETURN BOOLEAN IS
|
| 196 |
|
|
VARIABLE result: BOOLEAN;
|
| 197 |
|
|
BEGIN
|
| 198 |
|
|
result := TRUE;
|
| 199 |
|
|
FOR i IN a'RANGE LOOP
|
| 200 |
|
|
result := (a(i) = 'Z');
|
| 201 |
|
|
IF NOT result THEN
|
| 202 |
|
|
EXIT;
|
| 203 |
|
|
END IF;
|
| 204 |
|
|
END LOOP;
|
| 205 |
|
|
RETURN result;
|
| 206 |
|
|
END Check_For_Tristate;
|
| 207 |
|
|
|
| 208 |
|
|
-----------------------------------------------------------------------
|
| 209 |
|
|
-- Global signals
|
| 210 |
|
|
-----------------------------------------------------------------------
|
| 211 |
|
|
constant tristate_vec : std_logic_vector(D'RANGE) := (others=> 'Z');
|
| 212 |
|
|
constant undef_vec : std_logic_vector(D'RANGE) := (others=> 'X');
|
| 213 |
|
|
constant init_vec : std_logic_vector(D'RANGE) := (others=> value_on_power_up);
|
| 214 |
|
|
constant undef_adr_vec : std_logic_vector(A'RANGE) := (others=> 'X');
|
| 215 |
|
|
|
| 216 |
|
|
SIGNAL read_active : BOOLEAN := FALSE; -- Indicates whether the SRAM is sending on the D bus
|
| 217 |
|
|
SIGNAL read_valid : BOOLEAN := FALSE; -- If TRUE, the data output by the RAM is valid
|
| 218 |
|
|
SIGNAL read_data : std_logic_vector(D'RANGE); -- content of the memory location addressed by A
|
| 219 |
|
|
SIGNAL do_write : std_logic := '0'; -- A '0'->'1' transition on this signal marks
|
| 220 |
|
|
-- the moment when the data on D is stored in the
|
| 221 |
|
|
-- addressed memory location
|
| 222 |
|
|
SIGNAL adr_setup : std_logic_vector(A'RANGE); -- delayed value of A to model the Address Setup Time
|
| 223 |
|
|
SIGNAL adr_hold : std_logic_vector(A'RANGE); -- delayed value of A to model the Address Hold Time
|
| 224 |
|
|
SIGNAL valid_adr : std_logic_vector(A'RANGE); -- valid memory address derived from A after
|
| 225 |
|
|
-- considering Address Setup and Hold Times
|
| 226 |
|
|
|
| 227 |
|
|
signal DD1, DD2 : std_logic_vector(D'range); -- Delayed versions of D
|
| 228 |
|
|
|
| 229 |
|
|
BEGIN
|
| 230 |
|
|
|
| 231 |
|
|
-- vsim fails on std_logic_vector'DELAYED, so create explicit delayed versions here
|
| 232 |
|
|
-- See body of process "memory"
|
| 233 |
|
|
DD1 <= D; -- D'DELAYED
|
| 234 |
|
|
DD2 <= D after tHD_min; -- D'DELAYED(tHD_min)
|
| 235 |
|
|
|
| 236 |
|
|
-----------------------------------------------------------------------
|
| 237 |
|
|
-- The main task. The memory array is a private variable of this
|
| 238 |
|
|
-- process.
|
| 239 |
|
|
-----------------------------------------------------------------------
|
| 240 |
|
|
memory: PROCESS
|
| 241 |
|
|
CONSTANT low_address : natural := 0;
|
| 242 |
|
|
CONSTANT high_address : natural := nwords -1;
|
| 243 |
|
|
|
| 244 |
|
|
TYPE memory_array IS
|
| 245 |
|
|
ARRAY (natural RANGE low_address TO high_address) OF std_logic_vector(D'range);
|
| 246 |
|
|
|
| 247 |
|
|
type memptr is access memory_array;
|
| 248 |
|
|
variable memp : memptr := null; -- Ptr. to memory array
|
| 249 |
|
|
VARIABLE address : natural;
|
| 250 |
|
|
VARIABLE write_data : std_logic_vector(D'range);
|
| 251 |
|
|
|
| 252 |
|
|
-------------------------------------------------------------------
|
| 253 |
|
|
-- Initialise array at start: this happens before any file-load
|
| 254 |
|
|
-------------------------------------------------------------------
|
| 255 |
|
|
PROCEDURE power_up (memp: inout memptr) IS
|
| 256 |
|
|
BEGIN
|
| 257 |
|
|
if memp = null then
|
| 258 |
|
|
memp := new memory_array;
|
| 259 |
|
|
end if;
|
| 260 |
|
|
FOR add IN memp.all'range LOOP
|
| 261 |
|
|
memp.all(add) := init_vec;
|
| 262 |
|
|
END LOOP;
|
| 263 |
|
|
END power_up;
|
| 264 |
|
|
|
| 265 |
|
|
-------------------------------------------------------------------
|
| 266 |
|
|
-- Load binary file (see above for format) into array
|
| 267 |
|
|
-------------------------------------------------------------------
|
| 268 |
|
|
PROCEDURE load (memp: INOUT memptr; download_filename: IN string) IS
|
| 269 |
|
|
FILE source : text;
|
| 270 |
|
|
VARIABLE inline, outline : line;
|
| 271 |
|
|
VARIABLE add : natural;
|
| 272 |
|
|
VARIABLE c : character;
|
| 273 |
|
|
VARIABLE source_line_nr : integer := 1;
|
| 274 |
|
|
VARIABLE init_value : std_logic := 'U';
|
| 275 |
|
|
BEGIN
|
| 276 |
|
|
write(output, string'("Loading SRAM from file ") & download_filename & string'(" ... ") );
|
| 277 |
|
|
file_open(source, download_filename, READ_MODE);
|
| 278 |
|
|
WHILE NOT endfile(source) LOOP
|
| 279 |
|
|
readline(source, inline);
|
| 280 |
|
|
read(inline, add);
|
| 281 |
|
|
read(inline, c);
|
| 282 |
|
|
IF (c /= ' ') THEN
|
| 283 |
|
|
write(outline, string'("Syntax error in file '"));
|
| 284 |
|
|
write(outline, download_filename);
|
| 285 |
|
|
write(outline, string'("', line "));
|
| 286 |
|
|
write(outline, source_line_nr);
|
| 287 |
|
|
writeline(output, outline);
|
| 288 |
|
|
ASSERT FALSE
|
| 289 |
|
|
REPORT "RAM loader aborted."
|
| 290 |
|
|
SEVERITY FAILURE;
|
| 291 |
|
|
END IF;
|
| 292 |
|
|
FOR i IN D'range LOOP
|
| 293 |
|
|
read(inline, c);
|
| 294 |
|
|
case c is
|
| 295 |
|
|
when '0' => memp.all(add)(i) := '0';
|
| 296 |
|
|
when '1' => memp.all(add)(i) := '1';
|
| 297 |
|
|
when others =>
|
| 298 |
|
|
write(outline, string'("-W- Invalid character '"));
|
| 299 |
|
|
write(outline, c);
|
| 300 |
|
|
write(outline, string'("' in Bitstring in '"));
|
| 301 |
|
|
write(outline, download_filename);
|
| 302 |
|
|
write(outline, '(');
|
| 303 |
|
|
write(outline, source_line_nr);
|
| 304 |
|
|
write(outline, string'(") is set to '0'"));
|
| 305 |
|
|
writeline(output, outline);
|
| 306 |
|
|
memp.all(add)(i) := '0';
|
| 307 |
|
|
end case;
|
| 308 |
|
|
END LOOP;
|
| 309 |
|
|
IF (trace_ram_load) THEN
|
| 310 |
|
|
write(outline, string'("RAM["));
|
| 311 |
|
|
write(outline, add);
|
| 312 |
|
|
write(outline, string'("] := "));
|
| 313 |
|
|
write(outline, memp.all(add));
|
| 314 |
|
|
writeline(output, outline );
|
| 315 |
|
|
END IF;
|
| 316 |
|
|
source_line_nr := source_line_nr +1;
|
| 317 |
|
|
END LOOP; -- WHILE
|
| 318 |
|
|
file_close(source);
|
| 319 |
|
|
END PROCEDURE load;
|
| 320 |
|
|
|
| 321 |
|
|
-------------------------------------------------------------------
|
| 322 |
|
|
-- Write out the array (see above for format)
|
| 323 |
|
|
-------------------------------------------------------------------
|
| 324 |
|
|
PROCEDURE do_dump (memp: INOUT memptr;
|
| 325 |
|
|
dump_start, dump_end: IN natural;
|
| 326 |
|
|
dump_filename: IN string) IS
|
| 327 |
|
|
FILE dest : text;
|
| 328 |
|
|
VARIABLE l : line;
|
| 329 |
|
|
VARIABLE c : character;
|
| 330 |
|
|
variable d_top : natural;
|
| 331 |
|
|
BEGIN
|
| 332 |
|
|
if dump_end = 0 then
|
| 333 |
|
|
d_top := nwords-1;
|
| 334 |
|
|
else
|
| 335 |
|
|
d_top := dump_end;
|
| 336 |
|
|
end if;
|
| 337 |
|
|
IF (dump_start > d_top) OR (d_top >= nwords) THEN
|
| 338 |
|
|
ASSERT FALSE
|
| 339 |
|
|
REPORT "Invalid addresses for memory dump. Cancelled."
|
| 340 |
|
|
SEVERITY ERROR;
|
| 341 |
|
|
ELSE
|
| 342 |
|
|
file_open(dest, dump_filename, READ_MODE);
|
| 343 |
|
|
FOR add IN dump_start TO d_top LOOP
|
| 344 |
|
|
write(l, add);
|
| 345 |
|
|
write(l, ' ');
|
| 346 |
|
|
FOR i IN D'range LOOP
|
| 347 |
|
|
write(l, memp.all(add)(i));
|
| 348 |
|
|
END LOOP;
|
| 349 |
|
|
writeline(dest, l);
|
| 350 |
|
|
END LOOP;
|
| 351 |
|
|
file_close(dest);
|
| 352 |
|
|
END IF;
|
| 353 |
|
|
END PROCEDURE do_dump;
|
| 354 |
|
|
|
| 355 |
|
|
-----------------------------------------------------------------------
|
| 356 |
|
|
-- Main process body
|
| 357 |
|
|
-----------------------------------------------------------------------
|
| 358 |
|
|
BEGIN
|
| 359 |
|
|
power_up(memp);
|
| 360 |
|
|
IF download_on_power_up THEN
|
| 361 |
|
|
load(memp, download_filename);
|
| 362 |
|
|
END IF;
|
| 363 |
|
|
LOOP -- Forever (see WAIT at the end)
|
| 364 |
|
|
IF do_write'EVENT and (do_write = '1') then -- End of write: latch in the data
|
| 365 |
|
|
IF NOT Check_For_Valid_Data(D) THEN
|
| 366 |
|
|
-- D'DELAYED crashes VSIM (Code 211): apparently 'DELAYED only works on a single signal,
|
| 367 |
|
|
-- not a vector (although it compiles OK.)
|
| 368 |
|
|
-- So delayed versions of D are explicitly created, & used for these checks.
|
| 369 |
|
|
IF D'EVENT AND Check_For_Valid_Data(DD1) THEN -- should be D'DELAYED
|
| 370 |
|
|
write(output, "-W- Data changes exactly at end-of-write to SRAM.");
|
| 371 |
|
|
write_data := DD1; -- should be D'delayed
|
| 372 |
|
|
ELSE
|
| 373 |
|
|
write(output, "-E- Data not valid at end-of-write to SRAM.");
|
| 374 |
|
|
write_data := undef_vec;
|
| 375 |
|
|
END IF;
|
| 376 |
|
|
ELSIF NOT DD2'STABLE(tSD_min) THEN -- should be D'DELAYED(tHD_min)
|
| 377 |
|
|
-- End of failing block
|
| 378 |
|
|
write(output, "-E- tSD violation: Data input changes within setup-time at end-of-write to SRAM.");
|
| 379 |
|
|
write_data := undef_vec;
|
| 380 |
|
|
ELSIF NOT D'STABLE(tHD_min) THEN
|
| 381 |
|
|
write(output, "-E- tHD violation: Data input changes within hold-time at end-of-write to SRAM.");
|
| 382 |
|
|
write_data := undef_vec;
|
| 383 |
|
|
ELSIF nWE'DELAYED(tHD_min)'STABLE(tPWE_min) THEN
|
| 384 |
|
|
write(output, "-E- tPWE violation: Pulse width of nWE too short at SRAM.");
|
| 385 |
|
|
write_data := undef_vec;
|
| 386 |
|
|
ELSE
|
| 387 |
|
|
write_data := D;
|
| 388 |
|
|
END IF;
|
| 389 |
|
|
memp.all(TO_INTEGER(unsigned(valid_adr))) := write_data;
|
| 390 |
|
|
END IF;
|
| 391 |
|
|
IF Check_For_Valid_Data(valid_adr) THEN
|
| 392 |
|
|
read_data <= memp.all(TO_INTEGER(unsigned(valid_adr)));
|
| 393 |
|
|
ELSE
|
| 394 |
|
|
read_data <= undef_vec;
|
| 395 |
|
|
END IF;
|
| 396 |
|
|
IF dump AND dump'EVENT THEN
|
| 397 |
|
|
do_dump(memp, dump_start, dump_end, dump_filename);
|
| 398 |
|
|
END IF;
|
| 399 |
|
|
IF download AND download'EVENT THEN
|
| 400 |
|
|
load(memp, download_filename);
|
| 401 |
|
|
END IF;
|
| 402 |
|
|
WAIT ON do_write, valid_adr, dump, download;
|
| 403 |
|
|
END LOOP;
|
| 404 |
|
|
END PROCESS memory;
|
| 405 |
|
|
|
| 406 |
|
|
-----------------------------------------------------------------------
|
| 407 |
|
|
-- Signal delays
|
| 408 |
|
|
-----------------------------------------------------------------------
|
| 409 |
|
|
adr_setup <= TRANSPORT A AFTER tAA_max;
|
| 410 |
|
|
adr_hold <= TRANSPORT A AFTER tOHA_min;
|
| 411 |
|
|
|
| 412 |
|
|
valid_adr <= adr_setup WHEN Check_For_Valid_Data(adr_setup)
|
| 413 |
|
|
AND (adr_setup = adr_hold)
|
| 414 |
|
|
AND adr_hold'STABLE(tAA_max - tOHA_min) ELSE
|
| 415 |
|
|
undef_adr_vec;
|
| 416 |
|
|
|
| 417 |
|
|
read_active <= ((nOE = '0') AND (nOE'DELAYED(tLZOE_min) = '0') AND nOE'STABLE(tLZOE_min)
|
| 418 |
|
|
AND ((nWE = '1') OR (nWE'DELAYED(tHZWE_max) = '0'))
|
| 419 |
|
|
AND (nCE = '0') AND (CE2 = '1') AND nCE'STABLE(tLZCE_min) AND CE2'STABLE(tLZCE_min))
|
| 420 |
|
|
OR (read_active AND (nOE'DELAYED(tHZOE_max) = '0')
|
| 421 |
|
|
AND (nWE'DELAYED(tHZWE_max) = '1')
|
| 422 |
|
|
AND (nCE'DELAYED(tHZCE_max) = '0') AND (CE2'DELAYED(tHZCE_max) = '1'));
|
| 423 |
|
|
|
| 424 |
|
|
read_valid <= ((nOE = '0') AND nOE'STABLE(tDOE_max)
|
| 425 |
|
|
AND (nWE = '1') AND (nWE'DELAYED(tHZWE_max) = '1')
|
| 426 |
|
|
AND (nCE = '0') AND (CE2 = '1') AND nCE'STABLE(tACE_max) AND CE2'STABLE(tACE_max))
|
| 427 |
|
|
OR (read_valid AND read_active);
|
| 428 |
|
|
|
| 429 |
|
|
Q <= read_data WHEN read_valid and read_active ELSE
|
| 430 |
|
|
undef_vec WHEN not read_valid and read_active ELSE
|
| 431 |
|
|
tristate_vec;
|
| 432 |
|
|
|
| 433 |
|
|
-----------------------------------------------------------------------
|
| 434 |
|
|
-- Decode write command
|
| 435 |
|
|
-----------------------------------------------------------------------
|
| 436 |
|
|
PROCESS (nWE, nCE, CE2)
|
| 437 |
|
|
BEGIN
|
| 438 |
|
|
IF ((nCE = '1') OR (nWE = '1') OR (CE2 = '0'))
|
| 439 |
|
|
AND (nCE'DELAYED = '0') AND (CE2'DELAYED = '1') AND (nWE'DELAYED = '0') -- End of Write
|
| 440 |
|
|
THEN
|
| 441 |
|
|
do_write <= '1' AFTER tHD_min;
|
| 442 |
|
|
ELSE
|
| 443 |
|
|
IF (Now > 10 NS) AND (nCE = '0') AND (CE2 = '1') AND (nWE = '0') -- Start of Write
|
| 444 |
|
|
THEN
|
| 445 |
|
|
ASSERT Check_For_Valid_Data(A)
|
| 446 |
|
|
REPORT "Address not valid at start-of-write to RAM."
|
| 447 |
|
|
SEVERITY FAILURE;
|
| 448 |
|
|
|
| 449 |
|
|
ASSERT A'STABLE(tSA_min)
|
| 450 |
|
|
REPORT "tSA violation: Address changed within setup-time at start-of-write to SRAM."
|
| 451 |
|
|
SEVERITY ERROR;
|
| 452 |
|
|
|
| 453 |
|
|
ASSERT enable_nWE_only_control OR ((nOE = '1') AND nOE'STABLE(tSA_min))
|
| 454 |
|
|
REPORT "tSA violation: nOE not inactive at start-of-write to RAM."
|
| 455 |
|
|
SEVERITY ERROR;
|
| 456 |
|
|
END IF;
|
| 457 |
|
|
do_write <= '0';
|
| 458 |
|
|
END IF;
|
| 459 |
|
|
END PROCESS;
|
| 460 |
|
|
|
| 461 |
|
|
-----------------------------------------------------------------------
|
| 462 |
|
|
-- The following processes check for validity of the control signals at the
|
| 463 |
|
|
-- SRAM interface. Removing them to speed up simulation will not affect the
|
| 464 |
|
|
-- functionality of the SRAM model.
|
| 465 |
|
|
-----------------------------------------------------------------------
|
| 466 |
|
|
-- Checks that an address change is allowed
|
| 467 |
|
|
-----------------------------------------------------------------------
|
| 468 |
|
|
PROCESS (A)
|
| 469 |
|
|
BEGIN
|
| 470 |
|
|
IF (Now > 0 NS) THEN -- suppress obsolete error message at time 0
|
| 471 |
|
|
ASSERT (nCE = '1') OR (CE2 = '0') OR (nWE = '1')
|
| 472 |
|
|
REPORT "Address not stable while write-to-SRAM active"
|
| 473 |
|
|
SEVERITY FAILURE;
|
| 474 |
|
|
|
| 475 |
|
|
ASSERT (nCE = '1') OR (CE2 = '0') OR (nWE = '1')
|
| 476 |
|
|
OR (nCE'DELAYED(tHA_min) = '1') OR (CE2'DELAYED(tHA_min) = '0')
|
| 477 |
|
|
OR (nWE'DELAYED(tHA_min) = '1')
|
| 478 |
|
|
REPORT "tHA violation: Address changed within hold-time at end-of-write to SRAM."
|
| 479 |
|
|
SEVERITY FAILURE;
|
| 480 |
|
|
END IF;
|
| 481 |
|
|
END PROCESS;
|
| 482 |
|
|
|
| 483 |
|
|
-----------------------------------------------------------------------
|
| 484 |
|
|
-- Checks that control signals at RAM are valid all the time
|
| 485 |
|
|
-----------------------------------------------------------------------
|
| 486 |
|
|
PROCESS (nOE, nWE, nCE, CE2)
|
| 487 |
|
|
BEGIN
|
| 488 |
|
|
IF (Now > 0 NS) AND (nCE /= '1') AND (CE2 /= '0') THEN
|
| 489 |
|
|
IF (nCE = '0') AND (CE2 = '1') THEN
|
| 490 |
|
|
ASSERT (nWE = '0') OR (nWE = '1')
|
| 491 |
|
|
REPORT "Invalid nWE-signal at SRAM while nCE is active"
|
| 492 |
|
|
SEVERITY WARNING;
|
| 493 |
|
|
ELSE
|
| 494 |
|
|
IF (nCE /= '0') THEN
|
| 495 |
|
|
ASSERT (nOE = '1')
|
| 496 |
|
|
REPORT "Invalid nCE-signal at SRAM while nOE not inactive"
|
| 497 |
|
|
SEVERITY WARNING;
|
| 498 |
|
|
|
| 499 |
|
|
ASSERT (nWE = '1')
|
| 500 |
|
|
REPORT "Invalid nCE-signal at SRAM while nWE not inactive"
|
| 501 |
|
|
SEVERITY ERROR;
|
| 502 |
|
|
END IF;
|
| 503 |
|
|
IF (CE2 /= '1') THEN
|
| 504 |
|
|
ASSERT (nOE = '1')
|
| 505 |
|
|
REPORT "Invalid CE2-signal at SRAM while nOE not inactive"
|
| 506 |
|
|
SEVERITY WARNING;
|
| 507 |
|
|
|
| 508 |
|
|
ASSERT (nWE = '1')
|
| 509 |
|
|
REPORT "Invalid CE2-signal at SRAM while nWE not inactive"
|
| 510 |
|
|
SEVERITY ERROR;
|
| 511 |
|
|
END IF;
|
| 512 |
|
|
END IF;
|
| 513 |
|
|
END IF;
|
| 514 |
|
|
END PROCESS;
|
| 515 |
|
|
|
| 516 |
|
|
END behavior;
|