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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.communication/] [hibi_pe_dma/] [1.0/] [tb/] [blocks/] [sram_scalable_v3.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
---------------------------------------------------------------------------------
2
-- Original code modified by Vesa Lahtinen and Tero Kangas
3
-- Both address and data width are now configurable
4
--
5
-- Modified by Ari Kulmala. Reads in integers and stores them into
6
-- consequent addresses, interface modified
7
-- to resemble the current scheme.
8
--
9
-- sram_scalable.vhdl
10
--
11
-- Original code:
12
--
13
-- sram64kx8.vhd 
14
-- standard SRAM vhdl code, 256K*32 Bit,
15
--                          simplistic model without timing
16
--                          with startup initialization from file
17
--
18
-- (C) 1993,1994 Norman Hendrich, Dept. Computer Science
19
--                                University of Hamburg
20
--                                22041 Hamburg, Germany
21
--                                hendrich@informatik.uni-hamburg.de
22
--
23
-- initialization code taken and modified from DLX memory-behaviour.vhdl: 
24
--                    Copyright (C) 1993, Peter J. Ashenden
25
--                    Mail:       Dept. Computer Science
26
--                                University of Adelaide, SA 5005, Australia
27
--                    e-mail:     petera@cs.adelaide.edu.au
28
----------------------------------------------------------------------------------
29
 
30
use std.textio.all;
31
library IEEE;
32
use IEEE.std_logic_1164.all;
33
use IEEE.std_logic_signed.all;
34
use IEEE.std_logic_arith.all;
35
 
36
entity sram_scalable is
37
  generic (
38
    rom_data_file_name_g : string  := "none";
39
    output_file_name_g   : string  := "none";
40
    write_trigger_g      : natural := 0;  --dumps the memory contents to a file
41
    addr_width_g         : integer := 0;  --width of address bus
42
    data_width_g         : integer := 0   --width of data bus
43
    );
44
  port (
45
    cs1_n_in   : in    std_logic;         -- not chip select 1
46
    cs2_in     : in    std_logic;         -- cs2. both have to be active
47
                                          -- for memory to do something
48
    addr_in    : in    std_logic_vector(addr_width_g-1 downto 0);
49
    data_inout : inout std_logic_vector(data_width_g-1 downto 0);
50
    we_n_in    : in    std_logic;         -- not write enable
51
    oe_n_in    : in    std_logic          -- not output enable 
52
    );
53
end sram_scalable;
54
 
55
 
56
 
57
architecture sram_behaviour of sram_scalable is
58
begin
59
 
60
  mem : process
61
 
62
    constant low_address_c  : natural := 0;
63
    constant high_address_c : natural := 2**addr_width_g - 1;
64
 
65
    subtype word is std_logic_vector(data_width_g-1 downto 0);
66
 
67
    type memory_array is
68
      array (natural range low_address_c to high_address_c) of word;
69
 
70
    variable mem_v     : memory_array;
71
 
72
 
73
    variable address_v : natural;
74
    variable l       : line;
75
 
76
 
77
   ----------------------------------------------------------------------------         
78
    -- Load initial memory contents from text-file,
79
    -- One decimal number per line is read
80
    -- First value of line goes to location mem(0), value on 2nd line goes to mem(1) and so on
81
    ---------------------------------------------------------------------------
82
    procedure load(mem : out memory_array) is
83
 
84
      file binary_file : text is in rom_data_file_name_g;
85
      variable l       : line;
86
      variable a, i    : natural;
87
      variable val     : natural;
88
      variable c       : integer;
89
 
90
    begin
91
 
92
      -- first initialize the ram array with zeroes
93
      for a in low_address_c to high_address_c loop
94
        mem(a) := (others => '0');
95
      end loop;
96
 
97
      a := low_address_c;               -- turha sijoitus?
98
 
99
 
100
      -- and now read the data file
101
      for a in low_address_c to high_address_c loop
102
        if not endfile(binary_file) then
103
          readline(binary_file, l);
104
          read (l, c);
105
          -- convert integer value to std_logic_vector and store it into mem
106
          mem(a) := conv_std_logic_vector(c, data_width_g);
107
        end if;
108
      end loop;
109
    end load;
110
 
111
 
112
   ----------------------------------------------------------------------------       
113
    -- Dump memory contents to a text-file
114
    -- Line format: address data
115
    -- Nuber format: decimal numbers
116
    ---------------------------------------------------------------------------
117
    procedure dump(mem : in memory_array) is
118
 
119
      file binary_file : text is out output_file_name_g;
120
      variable l       : line;
121
      variable i       : natural;
122
      variable val2    : integer;
123
 
124
    begin
125
      report "Dump memory contents into txt file";
126
      -- and now write the data into a file
127
      for i in 0 to high_address_c loop
128
        val2 := conv_integer(mem(i));
129
        write(l, i);
130
        write(l, ' ');
131
        write(l, val2);
132
        writeline(binary_file, l);
133
      end loop;
134
    end dump;
135
 
136
 
137
 
138
 
139
  begin  -- mem : process
140
 
141
    -- sram initialization:
142
    -- first initialize the ram array with zeroes
143
    for a in low_address_c to high_address_c loop
144
      mem_v(a) := (others => '0');
145
    end loop;
146
 
147
 
148
    if (rom_data_file_name_g /= "none") then
149
      load(mem_v);
150
    end if;
151
 
152
 
153
 
154
 
155
    ----------------------------------------------------------------------------
156
    -- Process memory cycles,
157
    -- after init the model stays in this loop forever
158
    ---------------------------------------------------------------------------
159
    loop
160
      --
161
      -- wait for chip-select,
162
      -- 
163
      if (cs1_n_in = '0') and (cs2_in = '1') then
164
 
165
        -- decode address
166
        address_v := conv_integer(unsigned(addr_in));
167
 
168
        if we_n_in = '0' then
169
          --- write cycle
170
          mem_v(address_v) := data_inout;
171
          data_inout <= (others => 'Z');
172
 
173
        elsif we_n_in = '1' then
174
          -- read cycle
175
          if oe_n_in = '0' then
176
            data_inout <= mem_v(address_v);
177
          else
178
            data_inout <= (others => 'Z');
179
          end if;
180
 
181
        else
182
          data_inout <= (others => 'Z');
183
        end if;
184
      else
185
        --
186
        -- chip not selected, disable output
187
        --
188
        data_inout <= (others => 'Z');
189
      end if;
190
 
191
 
192
 
193
      -------------------------
194
      -- For debugging: accessing certain location, dumps memory contents to file
195
      if address_v = write_trigger_g then
196
        if output_file_name_g /= "none" then
197
          dump(mem_v);
198
        end if;
199
      end if;
200
      -----------------------
201
 
202
      wait on cs1_n_in, cs2_in, we_n_in, oe_n_in, addr_in, data_inout;
203
    end loop;
204
  end process;
205
 
206
 
207
end sram_behaviour;
208
 
209
 
210
configuration cfg_sram of sram_scalable is
211
  for sram_behaviour
212
  end for;
213
end cfg_sram;
214
 

powered by: WebSVN 2.1.0

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