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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_gpout.vhd] - Blame information for rev 223

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 213 jshamlet
-- Copyright (c)2011, 20219, 2020 Jeremy Seth Henry
2 167 jshamlet
-- 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 194 jshamlet
-- (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 167 jshamlet
--
24
-- VHDL Units :  o8_gpout
25
-- Description:  Provides a single 8-bit GP output register with selectable
26
--            :   tri-state control.
27 213 jshamlet
--
28
-- Register Map:
29
-- Offset  Bitfield Description                        Read/Write
30
--   0x00  AAAAAAAA Output Register                       (RW)
31
--   0x01  AAAAAAAA Enable/Tri-State Register             (RW)
32
--
33
-- Note that setting a bit to '1' will enable the pin for output, while
34
--  setting it to a '0' will tri-state the pin.
35
--
36
-- Revision History
37
-- Author          Date     Change
38
------------------ -------- ---------------------------------------------------
39
-- Seth Henry      07/28/11 Design Start
40
-- Seth Henry      12/19/19 Renamed to "o8_gpout" to fit "theme"
41
-- Seth Henry      04/10/20 Code Cleanup and comments
42 167 jshamlet
 
43
library ieee;
44
use ieee.std_logic_1164.all;
45
 
46
library work;
47
  use work.open8_pkg.all;
48
 
49
entity o8_gpout is
50
generic(
51
  Default_Out           : DATA_TYPE := x"00";
52
  Default_En            : DATA_TYPE := x"00";
53
  Disable_Tristate      : boolean   := false;
54
  Reset_Level           : std_logic;
55
  Address               : ADDRESS_TYPE
56
);
57
port(
58
  Clock                 : in  std_logic;
59
  Reset                 : in  std_logic;
60
  --
61 223 jshamlet
  Open8_Bus             : in  OPEN8_BUS_TYPE;
62 167 jshamlet
  Rd_Data               : out DATA_TYPE;
63
  --
64
  GPO                   : out DATA_TYPE
65
);
66
end entity;
67
 
68
architecture behave of o8_gpout is
69
 
70
  constant User_Addr    : std_logic_vector(15 downto 1)
71
                          := Address(15 downto 1);
72 223 jshamlet
  alias  Comp_Addr      is Open8_Bus.Address(15 downto 1);
73
  alias  Reg_Addr       is Open8_Bus.Address(0);
74
  signal Reg_Sel        : std_logic := '0';
75
  signal Addr_Match     : std_logic := '0';
76
  signal Wr_En          : std_logic := '0';
77
  signal Wr_Data_q      : DATA_TYPE := x"00";
78
  signal Rd_En          : std_logic := '0';
79 167 jshamlet
 
80 223 jshamlet
  signal User_Out       : DATA_TYPE := x"00";
81
  signal User_En        : DATA_TYPE := x"00";
82 167 jshamlet
 
83
begin
84
 
85
  Addr_Match            <= '1' when Comp_Addr = User_Addr else '0';
86
 
87
  io_reg: process( Clock, Reset )
88
  begin
89
    if( Reset = Reset_Level )then
90
      Reg_Sel           <= '0';
91
      Wr_En             <= '0';
92
      Wr_Data_q         <= x"00";
93
      Rd_En             <= '0';
94 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
95 167 jshamlet
      User_Out          <= Default_Out;
96
      if( not Disable_Tristate)then
97
        User_En         <= Default_En;
98
      end if;
99
    elsif( rising_edge( Clock ) )then
100
      Reg_Sel           <= Reg_Addr;
101 223 jshamlet
      Wr_En             <= Addr_Match and Open8_Bus.Wr_En;
102
      Wr_Data_q         <= Open8_Bus.Wr_Data;
103 167 jshamlet
      if( Wr_En = '1' )then
104
        if( Disable_Tristate )then
105
          User_Out      <= Wr_Data_q;
106
        else
107
          if( Reg_Sel = '0' )then
108
            User_Out    <= Wr_Data_q;
109
          else
110
            User_En     <= Wr_Data_q;
111
          end if;
112
        end if;
113
      end if;
114
 
115 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
116 223 jshamlet
      Rd_En             <= Addr_Match and Open8_Bus.Rd_En;
117 167 jshamlet
      if( Rd_En = '1' )then
118
        Rd_Data         <= User_Out;
119
        if( (Reg_Sel = '1') and (not Disable_Tristate) )then
120
          Rd_Data       <= User_En;
121
        end if;
122
      end if;
123
    end if;
124
  end process;
125
 
126
No_Tristates: if( Disable_Tristate )generate
127
  GPO                   <= User_Out;
128
end generate;
129
 
130
Tristates: if( not Disable_Tristate )generate
131
 
132
  Output_Ctl_proc: process( User_Out, User_En )
133
  begin
134
    for i in 0 to 7 loop
135
      GPO(i)            <= 'Z';
136
      if( User_En(i) = '1' )then
137
        GPO(i)          <= User_Out(i);
138
      end if;
139
    end loop;
140
  end process;
141
 
142
end generate;
143
 
144
end architecture;

powered by: WebSVN 2.1.0

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