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 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_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
  signal WPR_Reg_Sel         : std_logic := '0';
86
 
87
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
88
  signal Wr_Data             : DATA_TYPE := x"00";
89
 
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
  signal WPR_Wr_En           : std_logic := '0';
96
  signal WPR_Rd_En           : std_logic := '0';
97
 
98
  alias  RAM_Base_Addr       is Open8_Bus.Address(15 downto 10);
99
  alias  RAM_Addr            is Open8_Bus.Address(9 downto 0);
100
 
101
  alias  RAM_Rgn_Addr        is Open8_Bus.Address(9 downto 6);
102
 
103
  signal RAM_Region_Match    : std_logic := '0';
104
  signal RAM_Addr_Match      : std_logic := '0';
105
 
106
  signal RAM_Wr_En           : std_logic := '0';
107
  signal RAM_Rd_En           : std_logic := '0';
108
  signal RAM_Rd_Data         : DATA_TYPE := OPEN8_NULLBUS;
109
 
110
begin
111
 
112
Write_Protect_On : if( Write_Protect )generate
113
 
114
  WPR_Addr_Match             <= '1' when WPR_Comp_Addr = WPR_User_Addr else '0';
115
 
116
  RAM_Addr_Match             <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
117
 
118
  RAM_Region_Match           <= Write_Mask(conv_integer(RAM_Rgn_Addr)) or
119
                                ISR_En;
120
 
121
  RAM_Wr_En                  <= RAM_Addr_Match and RAM_Region_Match and Wr_En;
122
 
123
  RAM_proc: process( Reset, Clock )
124
  begin
125
    if( Reset = Reset_Level )then
126
      Write_Mask             <= Default_Mask;
127
 
128
      WPR_Reg_Sel            <= '0';
129
 
130
      WPR_Wr_En              <= '0';
131
      WPR_Rd_En              <= '0';
132
 
133
      RAM_Rd_En              <= '0';
134
      Rd_Data                <= OPEN8_NULLBUS;
135
    elsif( rising_edge(Clock) )then
136
      WPR_Reg_Sel            <= WPR_Reg_Sel_d;
137
 
138
      WPR_Wr_En              <= WPR_Addr_Match and Wr_En and ISR_En;
139
      Wr_Data                <= Wr_Data_d;
140
      if( WPR_Wr_En = '1' )then
141
        case( WPR_Reg_Sel )is
142
          when '0' =>
143
            Write_Mask_0     <= Wr_Data;
144
          when '1' =>
145
            Write_Mask_1     <= Wr_Data;
146
          when others =>
147
            null;
148
        end case;
149
      end if;
150
 
151
      WPR_Rd_En              <= WPR_Addr_Match and Rd_En;
152
      RAM_Rd_En              <= RAM_Addr_Match and Rd_En;
153
      Rd_Data                <= OPEN8_NULLBUS;
154
      if( WPR_Rd_En = '1'  )then
155
        case( WPR_Reg_Sel )is
156
          when '0' =>
157
            Rd_Data          <= Write_Mask_0;
158
          when '1' =>
159
            Rd_Data          <= Write_Mask_1;
160
          when others =>
161
            null;
162
        end case;
163
      end if;
164
      if( RAM_Rd_En = '1' )then
165
        Rd_Data              <= RAM_Rd_Data;
166
      end if;
167
    end if;
168
  end process;
169
 
170
end generate;
171
 
172
Write_Protect_Off : if( not Write_Protect )generate
173
 
174
  RAM_Addr_Match             <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
175
 
176
  RAM_Wr_En                  <= RAM_Addr_Match and Open8_Bus.Wr_En;
177
 
178
  RAM_proc: process( Reset, Clock )
179
  begin
180
    if( Reset = Reset_Level )then
181
      RAM_Rd_En              <= '0';
182
      Rd_Data                <= OPEN8_NULLBUS;
183
    elsif( rising_edge(Clock) )then
184
      RAM_Rd_En              <= RAM_Addr_Match and Open8_Bus.Rd_En;
185
      Rd_Data                <= OPEN8_NULLBUS;
186
      if( RAM_Rd_En = '1' )then
187
        Rd_Data              <= RAM_Rd_Data;
188
      end if;
189
    end if;
190
  end process;
191
 
192
end generate;
193
 
194
  -- Note that this RAM should be created without an output FF (unregistered Q)
195
  U_RAM : entity work.ram_1k_core
196
  port map(
197
    address                  => RAM_Addr,
198
    clock                    => Clock,
199
    data                     => Wr_Data_d,
200
    wren                     => RAM_Wr_En,
201
    q                        => RAM_Rd_Data
202
  );
203
 
204
end architecture;

powered by: WebSVN 2.1.0

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