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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_ram_1k.vhd] - Blame information for rev 257

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_1k
25
-- Description:  Provides a wrapper layer for a 1kx8 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
--            :   16, 64 byte regions, corresponding to the 16 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
--
40
-- Revision History
41
-- Author          Date     Change
42
------------------ -------- ---------------------------------------------------
43
-- Seth Henry      04/16/20 Revision block added
44
-- Seth Henry      05/12/20 Added write protect logic
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
use ieee.std_logic_unsigned.all;
49
use ieee.std_logic_arith.all;
50
 
51
library work;
52
  use work.open8_pkg.all;
53
 
54
entity o8_ram_1k is
55
generic(
56
  Write_Protect              : boolean := FALSE;
57
  Default_Mask               : ADDRESS_TYPE := x"0000";
58
  Address_WPR                : ADDRESS_TYPE := x"0400";
59
  Address_RAM                : ADDRESS_TYPE
60
);
61
port(
62
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
63 251 jshamlet
  Rd_Data                    : out DATA_TYPE;
64
  Write_Fault                : out std_logic
65 242 jshamlet
);
66
end entity;
67
 
68
architecture behave of o8_ram_1k is
69
 
70
  alias  Clock               is Open8_Bus.Clock;
71
  alias  Reset               is Open8_Bus.Reset;
72
  alias  ISR_En              is Open8_Bus.GP_Flags(EXT_ISR);
73
  alias  Wr_En               is Open8_Bus.Wr_En;
74
  alias  Rd_En               is Open8_Bus.Rd_En;
75
 
76
  constant WPR_User_Addr     : std_logic_vector(15 downto 1)
77
                               := Address_WPR(15 downto 1);
78
 
79
  constant RAM_User_Addr     : std_logic_vector(15 downto 10)
80
                               := Address_RAM(15 downto 10);
81
 
82
  alias  WPR_Comp_Addr       is Open8_Bus.Address(15 downto 1);
83
  signal WPR_Addr_Match      : std_logic := '0';
84
 
85
  alias  WPR_Reg_Sel_d       is Open8_Bus.Address(0);
86 244 jshamlet
  signal WPR_Reg_Sel_q       : std_logic := '0';
87 242 jshamlet
 
88
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
89 244 jshamlet
  signal WPR_Wr_Data_q       : DATA_TYPE := x"00";
90 242 jshamlet
 
91
  signal Write_Mask          : std_logic_vector(15 downto 0) :=
92
                                x"0000";
93
  alias  Write_Mask_0        is Write_Mask(7 downto 0);
94
  alias  Write_Mask_1        is Write_Mask(15 downto 8);
95
 
96 244 jshamlet
  signal WPR_Wr_En_d         : std_logic := '0';
97
  signal WPR_Wr_En_q         : std_logic := '0';
98
  signal WPR_Rd_En_d         : std_logic := '0';
99
  signal WPR_Rd_En_q         : std_logic := '0';
100 242 jshamlet
 
101
  alias  RAM_Base_Addr       is Open8_Bus.Address(15 downto 10);
102
  alias  RAM_Addr            is Open8_Bus.Address(9 downto 0);
103
 
104
  alias  RAM_Rgn_Addr        is Open8_Bus.Address(9 downto 6);
105
 
106
  signal RAM_Region_Match    : std_logic := '0';
107
  signal RAM_Addr_Match      : std_logic := '0';
108
 
109 244 jshamlet
  signal RAM_Wr_En_d         : std_logic := '0';
110
  signal RAM_Rd_En_d         : std_logic := '0';
111
  signal RAM_Rd_En_q         : std_logic := '0';
112 242 jshamlet
  signal RAM_Rd_Data         : DATA_TYPE := OPEN8_NULLBUS;
113
 
114 251 jshamlet
  signal Write_Fault_d       : std_logic := '0';
115
 
116 242 jshamlet
begin
117
 
118
Write_Protect_On : if( Write_Protect )generate
119
 
120
  WPR_Addr_Match             <= '1' when WPR_Comp_Addr = WPR_User_Addr else '0';
121 244 jshamlet
  WPR_Wr_En_d                <= WPR_Addr_Match and Wr_En and ISR_En;
122
  WPR_Rd_En_d                <= WPR_Addr_Match and Rd_En;
123 242 jshamlet
 
124
  RAM_Addr_Match             <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
125
 
126
  RAM_Region_Match           <= Write_Mask(conv_integer(RAM_Rgn_Addr)) or
127
                                ISR_En;
128
 
129 244 jshamlet
  RAM_Rd_En_d                <= RAM_Addr_Match and Rd_En;
130
  RAM_Wr_En_d                <= RAM_Addr_Match and RAM_Region_Match and Wr_En;
131 242 jshamlet
 
132 251 jshamlet
  Write_Fault_d              <= RAM_Addr_Match and (not RAM_Region_Match) and Wr_En;
133
 
134 242 jshamlet
  RAM_proc: process( Reset, Clock )
135
  begin
136
    if( Reset = Reset_Level )then
137 244 jshamlet
      WPR_Reg_Sel_q          <= '0';
138
      WPR_Wr_Data_q          <= x"00";
139 242 jshamlet
 
140 244 jshamlet
      WPR_Wr_En_q            <= '0';
141
      WPR_Rd_En_q            <= '0';
142 242 jshamlet
 
143 244 jshamlet
      Write_Mask             <= Default_Mask;
144 242 jshamlet
 
145 244 jshamlet
      RAM_Rd_En_q            <= '0';
146 242 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
147 251 jshamlet
 
148
      Write_Fault            <= '0';
149
 
150 242 jshamlet
    elsif( rising_edge(Clock) )then
151 244 jshamlet
      WPR_Reg_Sel_q          <= WPR_Reg_Sel_d;
152 242 jshamlet
 
153 244 jshamlet
      WPR_Wr_En_q            <= WPR_Wr_En_d;
154
      WPR_Wr_Data_q          <= Wr_Data_d;
155
      if( WPR_Wr_En_q = '1' )then
156
        case( WPR_Reg_Sel_q )is
157 242 jshamlet
          when '0' =>
158 244 jshamlet
            Write_Mask_0     <= WPR_Wr_Data_q;
159 242 jshamlet
          when '1' =>
160 244 jshamlet
            Write_Mask_1     <= WPR_Wr_Data_q;
161 242 jshamlet
          when others =>
162
            null;
163
        end case;
164
      end if;
165
 
166 244 jshamlet
      WPR_Rd_En_q            <= WPR_Rd_En_d;
167
      RAM_Rd_En_q            <= RAM_Rd_En_d;
168 243 jshamlet
 
169 242 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
170 244 jshamlet
      if( RAM_Rd_En_q = '1' )then
171 243 jshamlet
        Rd_Data              <= RAM_Rd_Data;
172 244 jshamlet
      elsif( WPR_Rd_En_q = '1'  )then
173
        case( WPR_Reg_Sel_q )is
174 242 jshamlet
          when '0' =>
175
            Rd_Data          <= Write_Mask_0;
176
          when '1' =>
177
            Rd_Data          <= Write_Mask_1;
178
          when others =>
179
            null;
180
        end case;
181
      end if;
182 251 jshamlet
 
183
      Write_Fault            <= Write_Fault_d;
184
 
185 242 jshamlet
    end if;
186
  end process;
187
 
188
end generate;
189
 
190
Write_Protect_Off : if( not Write_Protect )generate
191
 
192
  RAM_Addr_Match             <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
193
 
194 244 jshamlet
  RAM_Rd_En_d                <= RAM_Addr_Match and Open8_Bus.Rd_En;
195
  RAM_Wr_En_d                <= RAM_Addr_Match and Open8_Bus.Wr_En;
196 242 jshamlet
 
197
  RAM_proc: process( Reset, Clock )
198
  begin
199
    if( Reset = Reset_Level )then
200 244 jshamlet
      RAM_Rd_En_q            <= '0';
201 242 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
202
    elsif( rising_edge(Clock) )then
203 244 jshamlet
      RAM_Rd_En_q            <= RAM_Rd_En_d;
204 242 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
205 244 jshamlet
      if( RAM_Rd_En_q = '1' )then
206 242 jshamlet
        Rd_Data              <= RAM_Rd_Data;
207
      end if;
208
    end if;
209
  end process;
210
 
211
end generate;
212
 
213
  -- Note that this RAM should be created without an output FF (unregistered Q)
214
  U_RAM : entity work.ram_1k_core
215
  port map(
216
    address                  => RAM_Addr,
217
    clock                    => Clock,
218
    data                     => Wr_Data_d,
219 244 jshamlet
    wren                     => RAM_Wr_En_d,
220 242 jshamlet
    q                        => RAM_Rd_Data
221
  );
222
 
223
end architecture;

powered by: WebSVN 2.1.0

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