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 244

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
  Rd_Data                    : out DATA_TYPE
64
);
65
end entity;
66
 
67
architecture behave of o8_ram_1k is
68
 
69
  alias  Clock               is Open8_Bus.Clock;
70
  alias  Reset               is Open8_Bus.Reset;
71
  alias  ISR_En              is Open8_Bus.GP_Flags(EXT_ISR);
72
  alias  Wr_En               is Open8_Bus.Wr_En;
73
  alias  Rd_En               is Open8_Bus.Rd_En;
74
 
75
  constant WPR_User_Addr     : std_logic_vector(15 downto 1)
76
                               := Address_WPR(15 downto 1);
77
 
78
  constant RAM_User_Addr     : std_logic_vector(15 downto 10)
79
                               := Address_RAM(15 downto 10);
80
 
81
  alias  WPR_Comp_Addr       is Open8_Bus.Address(15 downto 1);
82
  signal WPR_Addr_Match      : std_logic := '0';
83
 
84
  alias  WPR_Reg_Sel_d       is Open8_Bus.Address(0);
85 244 jshamlet
  signal WPR_Reg_Sel_q       : std_logic := '0';
86 242 jshamlet
 
87
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
88 244 jshamlet
  signal WPR_Wr_Data_q       : DATA_TYPE := x"00";
89 242 jshamlet
 
90
  signal Write_Mask          : std_logic_vector(15 downto 0) :=
91
                                x"0000";
92
  alias  Write_Mask_0        is Write_Mask(7 downto 0);
93
  alias  Write_Mask_1        is Write_Mask(15 downto 8);
94
 
95 244 jshamlet
  signal WPR_Wr_En_d         : std_logic := '0';
96
  signal WPR_Wr_En_q         : std_logic := '0';
97
  signal WPR_Rd_En_d         : std_logic := '0';
98
  signal WPR_Rd_En_q         : std_logic := '0';
99 242 jshamlet
 
100
  alias  RAM_Base_Addr       is Open8_Bus.Address(15 downto 10);
101
  alias  RAM_Addr            is Open8_Bus.Address(9 downto 0);
102
 
103
  alias  RAM_Rgn_Addr        is Open8_Bus.Address(9 downto 6);
104
 
105
  signal RAM_Region_Match    : std_logic := '0';
106
  signal RAM_Addr_Match      : std_logic := '0';
107
 
108 244 jshamlet
  signal RAM_Wr_En_d         : std_logic := '0';
109
  signal RAM_Rd_En_d         : std_logic := '0';
110
  signal RAM_Rd_En_q         : std_logic := '0';
111 242 jshamlet
  signal RAM_Rd_Data         : DATA_TYPE := OPEN8_NULLBUS;
112
 
113
begin
114
 
115
Write_Protect_On : if( Write_Protect )generate
116
 
117
  WPR_Addr_Match             <= '1' when WPR_Comp_Addr = WPR_User_Addr else '0';
118 244 jshamlet
  WPR_Wr_En_d                <= WPR_Addr_Match and Wr_En and ISR_En;
119
  WPR_Rd_En_d                <= WPR_Addr_Match and Rd_En;
120 242 jshamlet
 
121
  RAM_Addr_Match             <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
122
 
123
  RAM_Region_Match           <= Write_Mask(conv_integer(RAM_Rgn_Addr)) or
124
                                ISR_En;
125
 
126 244 jshamlet
  RAM_Rd_En_d                <= RAM_Addr_Match and Rd_En;
127
  RAM_Wr_En_d                <= RAM_Addr_Match and RAM_Region_Match and Wr_En;
128 242 jshamlet
 
129
  RAM_proc: process( Reset, Clock )
130
  begin
131
    if( Reset = Reset_Level )then
132 244 jshamlet
      WPR_Reg_Sel_q          <= '0';
133
      WPR_Wr_Data_q          <= x"00";
134 242 jshamlet
 
135 244 jshamlet
      WPR_Wr_En_q            <= '0';
136
      WPR_Rd_En_q            <= '0';
137 242 jshamlet
 
138 244 jshamlet
      Write_Mask             <= Default_Mask;
139 242 jshamlet
 
140 244 jshamlet
      RAM_Rd_En_q            <= '0';
141 242 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
142
    elsif( rising_edge(Clock) )then
143 244 jshamlet
      WPR_Reg_Sel_q          <= WPR_Reg_Sel_d;
144 242 jshamlet
 
145 244 jshamlet
      WPR_Wr_En_q            <= WPR_Wr_En_d;
146
      WPR_Wr_Data_q          <= Wr_Data_d;
147
      if( WPR_Wr_En_q = '1' )then
148
        case( WPR_Reg_Sel_q )is
149 242 jshamlet
          when '0' =>
150 244 jshamlet
            Write_Mask_0     <= WPR_Wr_Data_q;
151 242 jshamlet
          when '1' =>
152 244 jshamlet
            Write_Mask_1     <= WPR_Wr_Data_q;
153 242 jshamlet
          when others =>
154
            null;
155
        end case;
156
      end if;
157
 
158 244 jshamlet
      WPR_Rd_En_q            <= WPR_Rd_En_d;
159
      RAM_Rd_En_q            <= RAM_Rd_En_d;
160 243 jshamlet
 
161 242 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
162 244 jshamlet
      if( RAM_Rd_En_q = '1' )then
163 243 jshamlet
        Rd_Data              <= RAM_Rd_Data;
164 244 jshamlet
      elsif( WPR_Rd_En_q = '1'  )then
165
        case( WPR_Reg_Sel_q )is
166 242 jshamlet
          when '0' =>
167
            Rd_Data          <= Write_Mask_0;
168
          when '1' =>
169
            Rd_Data          <= Write_Mask_1;
170
          when others =>
171
            null;
172
        end case;
173
      end if;
174
    end if;
175
  end process;
176
 
177
end generate;
178
 
179
Write_Protect_Off : if( not Write_Protect )generate
180
 
181
  RAM_Addr_Match             <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
182
 
183 244 jshamlet
  RAM_Rd_En_d                <= RAM_Addr_Match and Open8_Bus.Rd_En;
184
  RAM_Wr_En_d                <= RAM_Addr_Match and Open8_Bus.Wr_En;
185 242 jshamlet
 
186
  RAM_proc: process( Reset, Clock )
187
  begin
188
    if( Reset = Reset_Level )then
189 244 jshamlet
      RAM_Rd_En_q            <= '0';
190 242 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
191
    elsif( rising_edge(Clock) )then
192 244 jshamlet
      RAM_Rd_En_q            <= RAM_Rd_En_d;
193 242 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
194 244 jshamlet
      if( RAM_Rd_En_q = '1' )then
195 242 jshamlet
        Rd_Data              <= RAM_Rd_Data;
196
      end if;
197
    end if;
198
  end process;
199
 
200
end generate;
201
 
202
  -- Note that this RAM should be created without an output FF (unregistered Q)
203
  U_RAM : entity work.ram_1k_core
204
  port map(
205
    address                  => RAM_Addr,
206
    clock                    => Clock,
207
    data                     => Wr_Data_d,
208 244 jshamlet
    wren                     => RAM_Wr_En_d,
209 242 jshamlet
    q                        => RAM_Rd_Data
210
  );
211
 
212
end architecture;

powered by: WebSVN 2.1.0

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