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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gaisler/] [sim/] [sram.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
------------------------------------------------------------------------------
2
--  This file is a part of the GRLIB VHDL IP LIBRARY
3
--  Copyright (C) 2003, Gaisler Research
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This program is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this program; if not, write to the Free Software
17
--  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
18
-----------------------------------------------------------------------------
19
-- Entity:      sram
20
-- File:        sram.vhd
21
-- Author:      Jiri Gaisler Gaisler Research
22
-- Description: Simulation model of generic async SRAM
23
------------------------------------------------------------------------------
24
 
25
-- pragma translate_off
26
 
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use std.textio.all;
30
 
31
library gaisler;
32
use gaisler.sim.all;
33
library grlib;
34
use grlib.stdlib.all;
35
 
36
entity sram is
37
  generic (
38
    index : integer := 0;                -- Byte lane (0 - 3)
39
    abits: Positive := 10;              -- Default 10 address bits (1 Kbyte)
40
    tacc : integer := 10;               -- access time (ns)
41
    fname : string := "ram.dat";        -- File to read from
42
    clear : integer := 0);       -- Clear memory
43
  port (
44
    a : in std_logic_vector(abits-1 downto 0);
45
    d : inout std_logic_vector(7 downto 0);
46
    ce1 : in std_logic;
47
    we : in std_ulogic;
48
    oe : in std_ulogic);
49
end;
50
 
51
 
52
architecture sim of sram is
53
 
54
  subtype BYTE is std_logic_vector(7 downto 0);
55
  type MEM is array(0 to ((2**Abits)-1)) of BYTE;
56
  signal DINT,DI,DO : BYTE;
57
 
58
  constant ahigh : integer := abits - 1;
59
  signal wrpre : std_ulogic;
60
 
61
  function Vpar(vec : std_logic_vector) return std_ulogic is
62
  variable par : std_ulogic := '1';
63
  begin
64
    for i in vec'range loop     --'
65
      par := par xor vec(i);
66
    end loop;
67
    return par;
68
  end;
69
 
70
begin
71
 
72
  RAM : process(CE1,WE,DI,A,OE,D)
73
  variable MEMA : MEM;
74
  variable L1 : line;
75
  variable FIRST : boolean := true;
76
  variable ADR : std_logic_vector(19 downto 0);
77
  variable BUF : std_logic_vector(31 downto 0);
78
  variable CH : character;
79
  variable ai : integer := 0;
80
  file TCF : text open read_mode is fname;
81
  variable rectype : std_logic_vector(3 downto 0);
82
  variable recaddr : std_logic_vector(31 downto 0);
83
  variable reclen  : std_logic_vector(7 downto 0);
84
  variable recdata : std_logic_vector(0 to 16*8-1);
85
 
86
  begin
87
    if FIRST then
88
 
89
      if clear = 1 then MEMA := (others => X"00"); end if;
90
      L1:= new string'("");     --'
91
      while not endfile(TCF) loop
92
        readline(TCF,L1);
93
        if (L1'length /= 0) then --'
94
          while (not (L1'length=0)) and (L1(L1'left) = ' ') loop
95
            std.textio.read(L1,CH);
96
          end loop;
97
 
98
          if L1'length > 0 then  --'
99
            read(L1, ch);
100
            if (ch = 'S') or (ch = 's') then
101
              hexread(L1, rectype);
102
              hexread(L1, reclen);
103
              recaddr := (others => '0');
104
              case rectype is
105
                when "0001" =>
106
                  hexread(L1, recaddr(15 downto 0));
107
                when "0010" =>
108
                  hexread(L1, recaddr(23 downto 0));
109
                when "0011" =>
110
                  hexread(L1, recaddr);
111
                  recaddr(31 downto abits) := (others => '0');
112
                when others => next;
113
              end case;
114
              hexread(L1, recdata);
115
              if index = 6 then
116
                ai := conv_integer(recaddr);
117
                for i in 0 to 15 loop
118
                  MEMA(ai+i) := recdata((i*8) to (i*8+7));
119
                end loop;
120
              elsif (index = 4) or (index = 5) then
121
                ai := conv_integer(recaddr)/2;
122
                for i in 0 to 7 loop
123
                  MEMA(ai+i) := recdata((i*16+(index-4)*8) to (i*16+(index-4)*8+7));
124
                end loop;
125
              else
126
                ai := conv_integer(recaddr)/4;
127
                for i in 0 to 3 loop
128
                  MEMA(ai+i) := recdata((i*32+index*8) to (i*32+index*8+7));
129
                end loop;
130
              end if;
131
            end if;
132
          end if;
133
        end if;
134
      end loop;
135
 
136
      FIRST := false;
137
 
138
    else
139
      if (TO_X01(not CE1) = '1') then
140
        if not is_x(a) then ai := conv_integer(A(abits-1 downto 0)); else ai := 0; end if;
141
        dint <= mema(ai);
142
      end if;
143
      if (TO_X01(CE1 or WE) = '1') then
144
        if wrpre = '1' then
145
          mema(ai) := to_x01(std_logic_vector(DI));
146
        end if;
147
      end if;
148
    end if;
149
    wrpre <= TO_X01((not CE1) and (not WE));
150
    DI <= D;
151
  end process;
152
 
153
  BUFS : process(CE1,WE,DINT,OE)
154
  variable DRIVEB : std_logic;
155
  begin
156
    DRIVEB := TO_X01((not CE1) and (not OE) and WE);
157
    case DRIVEB is
158
      when '1' => D <= DINT after tacc * 1 ns;
159
      when '0' => D <= "ZZZZZZZZ" after 8 ns;
160
      when others => D <= "XXXXXXXX";
161
    end case;
162
  end process;
163
 
164
end sim;
165
-- pragma translate_on

powered by: WebSVN 2.1.0

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