Line 20... |
Line 20... |
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
--
|
--
|
-- VHDL Units : o8_ram_1k
|
-- VHDL Units : o8_ram_1k
|
-- Description: Provides a wrapper layer for a 1kx8 RAM model
|
-- Description: Provides a wrapper layer for a 1kx8 RAM model with interface
|
|
-- : logic for the Open8 CPU. Also provides an optional write
|
|
-- : enable register that prevents regions from being written
|
|
-- : by non-ISR code (uses the I flag) as a way to prevent tasks
|
|
-- : from inadvertently writing outside of their designated
|
|
-- : memory space.
|
|
-- : When enabled, the write mask logically divides the memory into
|
|
-- : 16, 64 byte regions, corresponding to the 16 bits in the WPR
|
|
-- : register.
|
|
--
|
|
-- WP Register Map:
|
|
-- Offset Bitfield Description Read/Write
|
|
-- 0x00 AAAAAAAA Region Enables 7:0 (RW)
|
|
-- 0x01 AAAAAAAA Region Enables 15:8 (RW)
|
--
|
--
|
-- Revision History
|
-- Revision History
|
-- Author Date Change
|
-- Author Date Change
|
------------------ -------- ---------------------------------------------------
|
------------------ -------- ---------------------------------------------------
|
-- Seth Henry 04/16/20 Revision block added
|
-- Seth Henry 04/16/20 Revision block added
|
|
-- Seth Henry 05/12/20 Added write protect logic
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_arith.all;
|
use ieee.std_logic_arith.all;
|
Line 37... |
Line 51... |
library work;
|
library work;
|
use work.open8_pkg.all;
|
use work.open8_pkg.all;
|
|
|
entity o8_ram_1k is
|
entity o8_ram_1k is
|
generic(
|
generic(
|
Address : ADDRESS_TYPE
|
Write_Protect : boolean := FALSE;
|
|
Default_Mask : ADDRESS_TYPE := x"0000";
|
|
Address_WPR : ADDRESS_TYPE := x"0400";
|
|
Address_RAM : ADDRESS_TYPE
|
);
|
);
|
port(
|
port(
|
Open8_Bus : in OPEN8_BUS_TYPE;
|
Open8_Bus : in OPEN8_BUS_TYPE;
|
Rd_Data : out DATA_TYPE
|
Rd_Data : out DATA_TYPE
|
);
|
);
|
Line 49... |
Line 66... |
|
|
architecture behave of o8_ram_1k is
|
architecture behave of o8_ram_1k is
|
|
|
alias Clock is Open8_Bus.Clock;
|
alias Clock is Open8_Bus.Clock;
|
alias Reset is Open8_Bus.Reset;
|
alias Reset is Open8_Bus.Reset;
|
|
alias ISR_En is Open8_Bus.GP_Flags(EXT_ISR);
|
|
alias Wr_En is Open8_Bus.Wr_En;
|
|
alias Rd_En is Open8_Bus.Rd_En;
|
|
|
|
constant WPR_User_Addr : std_logic_vector(15 downto 1)
|
|
:= Address_WPR(15 downto 1);
|
|
|
|
constant RAM_User_Addr : std_logic_vector(15 downto 10)
|
|
:= Address_RAM(15 downto 10);
|
|
|
|
alias WPR_Comp_Addr is Open8_Bus.Address(15 downto 1);
|
|
signal WPR_Addr_Match : std_logic := '0';
|
|
|
|
alias WPR_Reg_Sel_d is Open8_Bus.Address(0);
|
|
signal WPR_Reg_Sel : std_logic := '0';
|
|
|
|
alias Wr_Data_d is Open8_Bus.Wr_Data;
|
|
signal Wr_Data : DATA_TYPE := x"00";
|
|
|
constant User_Addr : std_logic_vector(15 downto 10)
|
signal Write_Mask : std_logic_vector(15 downto 0) :=
|
:= Address(15 downto 10);
|
x"0000";
|
alias Comp_Addr is Open8_Bus.Address(15 downto 10);
|
alias Write_Mask_0 is Write_Mask(7 downto 0);
|
|
alias Write_Mask_1 is Write_Mask(15 downto 8);
|
|
|
|
signal WPR_Wr_En : std_logic := '0';
|
|
signal WPR_Rd_En : std_logic := '0';
|
|
|
|
alias RAM_Base_Addr is Open8_Bus.Address(15 downto 10);
|
alias RAM_Addr is Open8_Bus.Address(9 downto 0);
|
alias RAM_Addr is Open8_Bus.Address(9 downto 0);
|
|
|
signal Addr_Match : std_logic := '0';
|
alias RAM_Rgn_Addr is Open8_Bus.Address(9 downto 6);
|
signal Wr_En : std_logic := '0';
|
|
signal Rd_En : std_logic := '0';
|
signal RAM_Region_Match : std_logic := '0';
|
signal Rd_Data_i : DATA_TYPE := OPEN8_NULLBUS;
|
signal RAM_Addr_Match : std_logic := '0';
|
|
|
|
signal RAM_Wr_En : std_logic := '0';
|
|
signal RAM_Rd_En : std_logic := '0';
|
|
signal RAM_Rd_Data : DATA_TYPE := OPEN8_NULLBUS;
|
|
|
begin
|
begin
|
|
|
-- This decode needs to happen immediately, to give the RAM a chance to
|
Write_Protect_On : if( Write_Protect )generate
|
-- do the lookup before we have to set Rd_Data
|
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
|
Wr_En <= Addr_Match and Open8_Bus.Wr_En;
|
|
|
|
-- Note that this RAM should be created without an output FF (unregistered Q)
|
WPR_Addr_Match <= '1' when WPR_Comp_Addr = WPR_User_Addr else '0';
|
U_RAM : entity work.ram_1k_core
|
|
port map(
|
RAM_Addr_Match <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
|
address => RAM_Addr,
|
|
clock => Clock,
|
RAM_Region_Match <= Write_Mask(conv_integer(RAM_Rgn_Addr)) or
|
data => Open8_Bus.Wr_Data,
|
ISR_En;
|
wren => Wr_En,
|
|
q => Rd_Data_i
|
RAM_Wr_En <= RAM_Addr_Match and RAM_Region_Match and Wr_En;
|
);
|
|
|
RAM_proc: process( Reset, Clock )
|
|
begin
|
|
if( Reset = Reset_Level )then
|
|
Write_Mask <= Default_Mask;
|
|
|
|
WPR_Reg_Sel <= '0';
|
|
|
|
WPR_Wr_En <= '0';
|
|
WPR_Rd_En <= '0';
|
|
|
|
RAM_Rd_En <= '0';
|
|
Rd_Data <= OPEN8_NULLBUS;
|
|
elsif( rising_edge(Clock) )then
|
|
WPR_Reg_Sel <= WPR_Reg_Sel_d;
|
|
|
|
WPR_Wr_En <= WPR_Addr_Match and Wr_En and ISR_En;
|
|
Wr_Data <= Wr_Data_d;
|
|
if( WPR_Wr_En = '1' )then
|
|
case( WPR_Reg_Sel )is
|
|
when '0' =>
|
|
Write_Mask_0 <= Wr_Data;
|
|
when '1' =>
|
|
Write_Mask_1 <= Wr_Data;
|
|
when others =>
|
|
null;
|
|
end case;
|
|
end if;
|
|
|
|
WPR_Rd_En <= WPR_Addr_Match and Rd_En;
|
|
RAM_Rd_En <= RAM_Addr_Match and Rd_En;
|
|
Rd_Data <= OPEN8_NULLBUS;
|
|
if( WPR_Rd_En = '1' )then
|
|
case( WPR_Reg_Sel )is
|
|
when '0' =>
|
|
Rd_Data <= Write_Mask_0;
|
|
when '1' =>
|
|
Rd_Data <= Write_Mask_1;
|
|
when others =>
|
|
null;
|
|
end case;
|
|
end if;
|
|
if( RAM_Rd_En = '1' )then
|
|
Rd_Data <= RAM_Rd_Data;
|
|
end if;
|
|
end if;
|
|
end process;
|
|
|
|
end generate;
|
|
|
|
Write_Protect_Off : if( not Write_Protect )generate
|
|
|
|
RAM_Addr_Match <= '1' when RAM_Base_Addr = RAM_User_Addr else '0';
|
|
|
|
RAM_Wr_En <= RAM_Addr_Match and Open8_Bus.Wr_En;
|
|
|
RAM_proc: process( Reset, Clock )
|
RAM_proc: process( Reset, Clock )
|
begin
|
begin
|
if( Reset = Reset_Level )then
|
if( Reset = Reset_Level )then
|
Rd_En <= '0';
|
RAM_Rd_En <= '0';
|
Rd_Data <= OPEN8_NULLBUS;
|
Rd_Data <= OPEN8_NULLBUS;
|
elsif( rising_edge(Clock) )then
|
elsif( rising_edge(Clock) )then
|
Rd_En <= Addr_Match and Open8_Bus.Rd_En;
|
RAM_Rd_En <= RAM_Addr_Match and Open8_Bus.Rd_En;
|
Rd_Data <= OPEN8_NULLBUS;
|
Rd_Data <= OPEN8_NULLBUS;
|
if( Rd_En = '1' )then
|
if( RAM_Rd_En = '1' )then
|
Rd_Data <= Rd_Data_i;
|
Rd_Data <= RAM_Rd_Data;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
|
end generate;
|
|
|
|
-- Note that this RAM should be created without an output FF (unregistered Q)
|
|
U_RAM : entity work.ram_1k_core
|
|
port map(
|
|
address => RAM_Addr,
|
|
clock => Clock,
|
|
data => Wr_Data_d,
|
|
wren => RAM_Wr_En,
|
|
q => RAM_Rd_Data
|
|
);
|
|
|
end architecture;
|
end architecture;
|
|
|
No newline at end of file
|
No newline at end of file
|