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

Subversion Repositories risc5x

[/] [risc5x/] [trunk/] [regs.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mikej
--
2
-- Risc5x
3
-- www.OpenCores.Org - November 2001
4
--
5
--
6
-- This library is free software; you can distribute it and/or modify it
7
-- under the terms of the GNU Lesser General Public License as published
8
-- by the Free Software Foundation; either version 2.1 of the License, or
9
-- (at your option) any later version.
10
--
11
-- This library is distributed in the hope that it will be useful, but
12
-- WITHOUT ANY WARRANTY; without even the implied warranty of
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
-- See the GNU Lesser General Public License for more details.
15
--
16
-- A RISC CPU core.
17
--
18
-- (c) Mike Johnson 2001. All Rights Reserved.
19
-- mikej@opencores.org for support or any other issues.
20
--
21
-- Revision list
22
--
23
-- version 1.0 initial opencores release
24
--
25
 
26
use work.pkg_risc5x.all;
27
library ieee;
28
  use ieee.std_logic_1164.all;
29
  use ieee.std_logic_arith.all;
30
  use ieee.std_logic_unsigned.all;
31
 
32
entity REGS is
33
  port (
34
    WE              : in  std_logic;
35
    RE              : in  std_logic;
36
    BANK            : in  std_logic_vector(1 downto 0);
37
    LOCATION        : in  std_logic_vector(4 downto 0);
38
    DIN             : in  std_logic_vector(7 downto 0);
39
    DOUT            : out std_logic_vector(7 downto 0);
40
    RESET           : in  std_logic;
41
    CLK             : in  std_logic
42
    );
43
end;
44
--
45
-- USE THIS ARCHITECTURE FOR XILINX
46
--
47
use work.pkg_risc5x.all;
48
use work.pkg_xilinx_prims.all;
49
use work.pkg_prims.all;
50
library ieee;
51
  use ieee.std_logic_1164.all;
52
  use ieee.std_logic_arith.all;
53
  use ieee.std_logic_unsigned.all;
54
 
55
architecture VIRTEX of REGS is
56
 
57
  constant WIDTH : natural := 8;
58
  constant OP_REG : boolean := false;
59
 
60
  type slv_array is array (natural range <>) of std_logic_vector(WIDTH-1 downto 0);
61
  signal ram_out : slv_array(4 downto 0);
62
  signal wen_int : std_logic_vector(4 downto 0);
63
  signal sel     : std_logic_vector(2 downto 0);
64
 
65
begin -- architecture
66
 
67
  -- ram mapping
68
  -- bank location
69
  -- xx   00xxx special registers
70
  -- xx   01xxx common 8 to all banks
71
  -- 00   1xxxx 16 bank 0
72
  -- 01   1xxxx 16 bank 1
73
  -- 10   1xxxx 16 bank 2
74
  -- 11   1xxxx 16 bank 3
75
  p_wen_comb : process (BANK,LOCATION,WE)
76
    variable addr : std_logic_vector(3 downto 0);
77
  begin
78
    addr := (BANK & LOCATION(4 downto 3));
79
    wen_int <= (others => '0');
80
    case addr(3 downto 1) is
81
      when "001" => wen_int(0) <= WE; -- bank0
82
      when "011" => wen_int(1) <= WE; -- bank1
83
      when "101" => wen_int(2) <= WE; -- bank2
84
      when "111" => wen_int(3) <= WE; -- bank3
85
 
86
      when others => null;
87
    end case;
88
    if (LOCATION(4 downto 3) = "01") then
89
      wen_int(4) <= WE; -- common
90
    end if;
91
  end process;
92
 
93
  ram_bit : for i in 0 to WIDTH-1 generate
94
  begin
95
    rams : for j in 0 to 4 generate
96
    attribute RLOC of ram: label is "R" & integer'image((WIDTH -1)-i) & "C" & integer'image((j+1)/2) & ".S" & integer'image(1 - ((j+1) mod 2));
97
    begin
98
      ram : RAM16X1D
99
      port map (
100
        a0    => LOCATION(0),
101
        a1    => LOCATION(1),
102
        a2    => LOCATION(2),
103
        a3    => LOCATION(3),
104
        dpra0 => LOCATION(0),
105
        dpra1 => LOCATION(1),
106
        dpra2 => LOCATION(2),
107
        dpra3 => LOCATION(3),
108
        wclk  => CLK,
109
        we    => wen_int(j),
110
        d     => DIN(i),
111
        dpo   => ram_out(j)(i));
112
    end generate;
113
  end generate;
114
 
115
  SEL <= BANK & LOCATION(4);
116
 
117
  mux : if true generate
118
    attribute RLOC of mux8_1: label is "R0C3";
119
  begin
120
    mux8_1 : MUX8
121
      generic map (
122
        WIDTH         => WIDTH,
123
        OP_REG        => OP_REG
124
        )
125
      port map (
126
        DIN7          => ram_out(3),
127
        DIN6          => ram_out(4),
128
        DIN5          => ram_out(2),
129
        DIN4          => ram_out(4),
130
        DIN3          => ram_out(1),
131
        DIN2          => ram_out(4),
132
        DIN1          => ram_out(0),
133
        DIN0          => ram_out(4),
134
 
135
        SEL           => sel,
136
        ENA           => '1', -- not used
137
        CLK           => CLK, -- not used
138
 
139
        DOUT          => DOUT
140
        );
141
   end generate;
142
end VIRTEX;
143
 
144
--pragma translate_off
145
 
146
use work.pkg_risc5x.all;
147
library ieee;
148
  use ieee.std_logic_1164.all;
149
  use ieee.std_logic_arith.all;
150
  use ieee.std_logic_unsigned.all;
151
 
152
architecture RTL of REGS is
153
  signal final_addr : std_logic_vector(6 downto 0);
154
  constant WIDTH : natural := 8;
155
  constant OP_REG : boolean := false;
156
 
157
  -- following required for simulation model only
158
  constant nwords : integer := 2 ** 7;
159
  type ram_type is array (0 to nwords-1) of std_logic_vector(WIDTH-1 downto 0);
160
  signal ram_read_data : std_logic_vector(WIDTH-1 downto 0);
161
  --shared variable ram :ram_type := (others => (others => 'X')); -- helps debug no end!
162
  shared variable ram :ram_type := (others => (others => '0'));
163
 
164
begin -- architecture
165
  p_remap : process(BANK,LOCATION)
166
    variable addr : std_logic_vector(3 downto 0);
167
  begin
168
    addr := (BANK & LOCATION(4 downto 3));
169
    final_addr <= "0000000";
170
    case addr is
171
      when "0001" => final_addr <= "0000" & LOCATION(2 downto 0);
172
      when "0101" => final_addr <= "0000" & LOCATION(2 downto 0);
173
      when "1001" => final_addr <= "0000" & LOCATION(2 downto 0);
174
      when "1101" => final_addr <= "0000" & LOCATION(2 downto 0);
175
      -- bank #0
176
      when "0010" => final_addr <= "0001" & LOCATION(2 downto 0);
177
      when "0011" => final_addr <= "0010" & LOCATION(2 downto 0);
178
      -- bank #1
179
      when "0110" => final_addr <= "0011" & LOCATION(2 downto 0);
180
      when "0111" => final_addr <= "0100" & LOCATION(2 downto 0);
181
      -- bank #2
182
      when "1010" => final_addr <= "0101" & LOCATION(2 downto 0);
183
      when "1011" => final_addr <= "0110" & LOCATION(2 downto 0);
184
      -- bank #3
185
      when "1110" => final_addr <= "0111" & LOCATION(2 downto 0);
186
      when "1111" => final_addr <= "1000" & LOCATION(2 downto 0);
187
      when others => null;
188
    end case;
189
  end process;
190
 
191
  -- you should replace the following simulation memory model
192
  -- with a dpram (no clock delay on read) for synthesis if
193
  -- you do not wish to use the Xilinx Virtex architecture.
194
  -- i.e.
195
  --
196
  --U1: dpram
197
  --  generic map (addr_bits => 7,
198
  --               data_bits => 8)
199
  --  port map (
200
  --    reset   => RESET,
201
  --    wr_clk  => CLK,
202
  --    wr_en   => WE,
203
  --    wr_addr => final_addr,
204
  --    wr_data => DIN,
205
  --    rd_clk  => '0',
206
  --    rd_addr => final_addr,
207
  --    rd_data => DOUT
208
  --    );
209
 
210
  -- SIMULATION MODEL OF RAM
211
  p_ram_write : process
212
    variable ram_addr : integer := 0;
213
  begin
214
    wait until CLK'event and (CLK = '1');
215
    if (WE = '1') then
216
      ram_addr := slv_to_integer(final_addr);
217
      ram(ram_addr) := DIN;
218
    end if;
219
  end process;
220
 
221
  p_ram_read_comb : process(CLK,final_addr)
222
    variable ram_addr : integer := 0;
223
  begin
224
    ram_addr := slv_to_integer(final_addr);
225
    ram_read_data <= ram(ram_addr);
226
  end process;
227
 
228
  opreg : if OP_REG generate
229
    p_opreg : process
230
    begin
231
      wait until CLK'event and (CLK = '1');
232
      if (RE = '1') then
233
        DOUT <= ram_read_data;
234
      end if;
235
    end process;
236
  end generate;
237
 
238
  opwire : if not OP_REG generate
239
    DOUT <= ram_read_data;
240
  end generate;
241
 
242
end RTL;
243
 
244
--pragma translate_on
245
 

powered by: WebSVN 2.1.0

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