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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_ram_4k.vhd] - Blame information for rev 242

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 242 jshamlet
-- Copyright (c)2013, 2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_ram_4k
25
-- Description:  Provides a wrapper layer for a 4kx8 RAM model with interface
26
--            :   logic for the Open8 CPU. Also provides an optional write
27
--            :   enable register that prevents regions from being written
28
--            :   by non-ISR code (uses the I flag) as a way to prevent tasks
29
--            :   from inadvertently writing outside of their designated
30
--            :   memory space.
31
--            :  When enabled, the write mask logically divides the memory into
32
--            :   32, 128 byte regions, corresponding to the 32 bits in the WPR
33
--            :   register.
34
--
35
-- WP Register Map:
36
-- Offset  Bitfield Description                        Read/Write
37
--   0x00  AAAAAAAA Region Enables  7:0                  (RW)
38
--   0x01  AAAAAAAA Region Enables 15:8                  (RW)
39
--   0x02  AAAAAAAA Region Enables 23:16                 (RW)
40
--   0x03  AAAAAAAA Region Enables 31:24                 (RW)
41
--
42
-- Revision History
43
-- Author          Date     Change
44
------------------ -------- ---------------------------------------------------
45
-- Seth Henry      04/16/20 Revision block added
46
-- Seth Henry      05/12/20 Added write protect logic
47
 
48
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.std_logic_unsigned.all;
51
use ieee.std_logic_arith.all;
52
 
53
library work;
54
  use work.open8_pkg.all;
55
 
56
entity o8_ram_4k is
57
generic(
58
  Write_Protect              : boolean := FALSE;
59
  Default_Mask               : std_logic_vector(31 downto 0) := x"00000000";
60
  Address_WPR                : ADDRESS_TYPE := x"1000";
61
  Address_RAM                : ADDRESS_TYPE
62
);
63
port(
64
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
65
  Rd_Data                    : out DATA_TYPE
66
);
67
end entity;
68
 
69
architecture behave of o8_ram_4k is
70
 
71
  alias  Clock               is Open8_Bus.Clock;
72
  alias  Reset               is Open8_Bus.Reset;
73
  alias  ISR_En              is Open8_Bus.GP_Flags(EXT_ISR);
74
  alias  Wr_En               is Open8_Bus.Wr_En;
75
  alias  Rd_En               is Open8_Bus.Rd_En;
76
 
77
  constant WPR_User_Addr     : std_logic_vector(15 downto 2)
78
                               := Address_WPR(15 downto 2);
79
 
80
  constant RAM_User_Addr     : std_logic_vector(15 downto 12)
81
                               := Address_RAM(15 downto 12);
82
 
83
  alias  WPR_Comp_Addr       is Open8_Bus.Address(15 downto 2);
84
  signal WPR_Addr_Match      : std_logic := '0';
85
 
86
  alias  WPR_Reg_Sel_d       is Open8_Bus.Address(1 downto 0);
87
  signal WPR_Reg_Sel         : std_logic_vector(1 downto 0) :=
88
                                (others => '0');
89
 
90
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
91
  signal Wr_Data             : DATA_TYPE := x"00";
92
 
93
  signal Write_Mask          : std_logic_vector(31 downto 0) :=
94
                                x"00000000";
95
  alias  Write_Mask_0        is Write_Mask( 7 downto  0);
96
  alias  Write_Mask_1        is Write_Mask(15 downto  8);
97
  alias  Write_Mask_2        is Write_Mask(23 downto 16);
98
  alias  Write_Mask_3        is Write_Mask(31 downto 24);
99
 
100
  signal WPR_Wr_En_d         : std_logic := '0';
101
  signal WPR_Wr_En           : std_logic := '0';
102
  signal WPR_Rd_En_d         : std_logic := '0';
103
  signal WPR_Rd_En           : std_logic := '0';
104
 
105
  alias  RAM_Base_Addr       is Open8_Bus.Address(15 downto 12);
106
  alias  RAM_Addr            is Open8_Bus.Address(11 downto 0);
107
 
108
  alias  RAM_Rgn_Addr        is Open8_Bus.Address(11 downto 7);
109
 
110
  signal RAM_Region_Match    : std_logic := '0';
111
  signal RAM_Addr_Match      : std_logic := '0';
112
 
113
  signal RAM_Wr_En           : std_logic := '0';
114
  signal RAM_Rd_En           : std_logic := '0';
115
  signal RAM_Rd_Data         : DATA_TYPE := OPEN8_NULLBUS;
116
 
117
begin
118
 
119
Write_Protect_On : if( Write_Protect )generate
120
 
121
  WPR_Addr_Match             <= '1' when WPR_Comp_Addr = WPR_User_Addr else '0';
122
 
123
  RAM_Addr_Match             <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
124
 
125
  RAM_Region_Match           <= Write_Mask(conv_integer(RAM_Rgn_Addr)) or
126
                                ISR_En;
127
 
128
  RAM_Wr_En                  <= RAM_Addr_Match and RAM_Region_Match and Wr_En;
129
 
130
  RAM_proc: process( Reset, Clock )
131
  begin
132
    if( Reset = Reset_Level )then
133
      Write_Mask             <= Default_Mask;
134
 
135
      WPR_Reg_Sel            <= (others => '0');
136
 
137
      WPR_Wr_En              <= '0';
138
      WPR_Rd_En              <= '0';
139
 
140
      RAM_Rd_En              <= '0';
141
      Rd_Data                <= OPEN8_NULLBUS;
142
    elsif( rising_edge(Clock) )then
143
      WPR_Reg_Sel            <= WPR_Reg_Sel_d;
144
 
145
      WPR_Wr_En              <= WPR_Addr_Match and Wr_En and ISR_En;
146
      Wr_Data                <= Wr_Data_d;
147
      if( WPR_Wr_En = '1' )then
148
        case( WPR_Reg_Sel )is
149
          when "00" =>
150
            Write_Mask_0     <= Wr_Data;
151
          when "01" =>
152
            Write_Mask_1     <= Wr_Data;
153
          when "10" =>
154
            Write_Mask_2     <= Wr_Data;
155
          when "11" =>
156
            Write_Mask_3     <= Wr_Data;
157
          when others =>
158
            null;
159
        end case;
160
      end if;
161
 
162
      WPR_Rd_En              <= WPR_Addr_Match and Rd_En;
163
      RAM_Rd_En              <= RAM_Addr_Match and Rd_En;
164
      Rd_Data                <= OPEN8_NULLBUS;
165
      if( WPR_Rd_En = '1'  )then
166
        case( WPR_Reg_Sel )is
167
          when "00" =>
168
            Rd_Data          <= Write_Mask_0;
169
          when "01" =>
170
            Rd_Data          <= Write_Mask_1;
171
          when "10" =>
172
            Rd_Data          <= Write_Mask_2;
173
          when "11" =>
174
            Rd_Data          <= Write_Mask_3;
175
          when others =>
176
            null;
177
        end case;
178
      end if;
179
      if( RAM_Rd_En = '1' )then
180
        Rd_Data              <= RAM_Rd_Data;
181
      end if;
182
    end if;
183
  end process;
184
 
185
end generate;
186
 
187
Write_Protect_Off : if( not Write_Protect )generate
188
 
189
  RAM_Addr_Match             <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
190
 
191
  RAM_Wr_En                  <= RAM_Addr_Match and Open8_Bus.Wr_En;
192
 
193
  RAM_proc: process( Reset, Clock )
194
  begin
195
    if( Reset = Reset_Level )then
196
      RAM_Rd_En              <= '0';
197
      Rd_Data                <= OPEN8_NULLBUS;
198
    elsif( rising_edge(Clock) )then
199
      RAM_Rd_En              <= RAM_Addr_Match and Open8_Bus.Rd_En;
200
      Rd_Data                <= OPEN8_NULLBUS;
201
      if( RAM_Rd_En = '1' )then
202
        Rd_Data              <= RAM_Rd_Data;
203
      end if;
204
    end if;
205
  end process;
206
 
207
end generate;
208
 
209
  -- Note that this RAM should be created without an output FF (unregistered Q)
210
  U_RAM : entity work.ram_4k_core
211
  port map(
212
    address                  => RAM_Addr,
213
    clock                    => Clock,
214
    data                     => Wr_Data_d,
215
    wren                     => RAM_Wr_En,
216
    q                        => RAM_Rd_Data
217
  );
218
 
219
end architecture;

powered by: WebSVN 2.1.0

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