| 1 |
180 |
jshamlet |
-- Copyright (c)2006, 2016, 2019 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 THIS
|
| 22 |
|
|
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
|
|
--
|
| 24 |
|
|
-- VHDL Units : o8_register
|
| 25 |
|
|
-- Description: Provides a single addressible 8-bit register
|
| 26 |
|
|
--
|
| 27 |
|
|
-- Register Map:
|
| 28 |
|
|
-- Offset Bitfield Description Read/Write
|
| 29 |
|
|
-- 0x00 AAAAAAAA Registered Outputs (RW)
|
| 30 |
|
|
--
|
| 31 |
|
|
-- Revision History
|
| 32 |
|
|
-- Author Date Change
|
| 33 |
|
|
------------------ -------- ---------------------------------------------------
|
| 34 |
|
|
-- Seth Henry 12/20/19 Design Start
|
| 35 |
|
|
|
| 36 |
|
|
library ieee;
|
| 37 |
|
|
use ieee.std_logic_1164.all;
|
| 38 |
|
|
use ieee.std_logic_unsigned.all;
|
| 39 |
|
|
use ieee.std_logic_arith.all;
|
| 40 |
|
|
use ieee.std_logic_misc.all;
|
| 41 |
|
|
|
| 42 |
|
|
library work;
|
| 43 |
|
|
use work.open8_pkg.all;
|
| 44 |
|
|
|
| 45 |
|
|
entity o8_register is
|
| 46 |
|
|
generic(
|
| 47 |
|
|
Default_Value : DATA_TYPE := x"00";
|
| 48 |
|
|
Reset_Level : std_logic;
|
| 49 |
|
|
Address : ADDRESS_TYPE
|
| 50 |
|
|
);
|
| 51 |
|
|
port(
|
| 52 |
|
|
Clock : in std_logic;
|
| 53 |
|
|
Reset : in std_logic;
|
| 54 |
|
|
--
|
| 55 |
|
|
Bus_Address : in ADDRESS_TYPE;
|
| 56 |
|
|
Wr_Enable : in std_logic;
|
| 57 |
|
|
Wr_Data : in DATA_TYPE;
|
| 58 |
|
|
Rd_Enable : in std_logic;
|
| 59 |
|
|
Rd_Data : out DATA_TYPE;
|
| 60 |
|
|
--
|
| 61 |
|
|
Register_Out : out DATA_TYPE
|
| 62 |
|
|
);
|
| 63 |
|
|
end entity;
|
| 64 |
|
|
|
| 65 |
|
|
architecture behave of o8_register is
|
| 66 |
|
|
|
| 67 |
|
|
function ceil_log2 (x : in natural) return natural is
|
| 68 |
|
|
variable retval : natural;
|
| 69 |
|
|
begin
|
| 70 |
|
|
retval := 1;
|
| 71 |
|
|
while ((2**retval) - 1) < x loop
|
| 72 |
|
|
retval := retval + 1;
|
| 73 |
|
|
end loop;
|
| 74 |
|
|
return retval;
|
| 75 |
|
|
end function;
|
| 76 |
|
|
|
| 77 |
|
|
constant User_Addr : std_logic_vector(15 downto 0)
|
| 78 |
|
|
:= Address(15 downto 0);
|
| 79 |
|
|
alias Comp_Addr is Bus_Address(15 downto 0);
|
| 80 |
|
|
signal Addr_Match : std_logic;
|
| 81 |
|
|
signal Wr_En : std_logic;
|
| 82 |
|
|
signal Wr_Data_q : DATA_TYPE;
|
| 83 |
|
|
signal Reg_Out : DATA_TYPE;
|
| 84 |
|
|
signal Rd_En : std_logic;
|
| 85 |
|
|
|
| 86 |
|
|
begin
|
| 87 |
|
|
|
| 88 |
|
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
| 89 |
|
|
|
| 90 |
|
|
io_reg: process( Clock, Reset )
|
| 91 |
|
|
begin
|
| 92 |
|
|
if( Reset = Reset_Level )then
|
| 93 |
|
|
Wr_En <= '0';
|
| 94 |
|
|
Wr_Data_q <= (others => '0');
|
| 95 |
|
|
Reg_Out <= Default_Value;
|
| 96 |
|
|
Rd_En <= '0';
|
| 97 |
|
|
Rd_Data <= x"00";
|
| 98 |
|
|
elsif( rising_edge( Clock ) )then
|
| 99 |
|
|
Wr_En <= Addr_Match and Wr_Enable;
|
| 100 |
|
|
Wr_Data_q <= Wr_Data;
|
| 101 |
|
|
if( Wr_En = '1' )then
|
| 102 |
|
|
Reg_Out <= Wr_Data_q;
|
| 103 |
|
|
end if;
|
| 104 |
|
|
|
| 105 |
|
|
Rd_Data <= (others => '0');
|
| 106 |
|
|
Rd_En <= Addr_Match and Rd_Enable;
|
| 107 |
|
|
if( Rd_En = '1' )then
|
| 108 |
|
|
Rd_Data <= Reg_Out;
|
| 109 |
|
|
end if;
|
| 110 |
|
|
|
| 111 |
|
|
end if;
|
| 112 |
|
|
end process;
|
| 113 |
|
|
|
| 114 |
|
|
Register_Out <= Reg_Out;
|
| 115 |
|
|
|
| 116 |
|
|
end architecture;
|