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 225

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 224 jshamlet
-- Seth Henry      04/16/20 Modified to make use of Open8 bus record
43 167 jshamlet
 
44
library ieee;
45
use ieee.std_logic_1164.all;
46
 
47
library work;
48
  use work.open8_pkg.all;
49
 
50
entity o8_gpout is
51
generic(
52 224 jshamlet
  Default_Out                : DATA_TYPE := x"00";
53
  Default_En                 : DATA_TYPE := x"00";
54
  Disable_Tristate           : boolean   := false;
55
  Address                    : ADDRESS_TYPE
56 167 jshamlet
);
57
port(
58 224 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
59
  Rd_Data                    : out DATA_TYPE;
60 167 jshamlet
  --
61 224 jshamlet
  GPO                        : out DATA_TYPE
62 167 jshamlet
);
63
end entity;
64
 
65
architecture behave of o8_gpout is
66
 
67 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
68
  alias Reset                is Open8_Bus.Reset;
69 167 jshamlet
 
70 224 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 1)
71
                               := Address(15 downto 1);
72
  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 224 jshamlet
  signal User_Out            : DATA_TYPE := x"00";
81
  signal User_En             : DATA_TYPE := x"00";
82
 
83 167 jshamlet
begin
84
 
85 224 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
86 167 jshamlet
 
87
  io_reg: process( Clock, Reset )
88
  begin
89
    if( Reset = Reset_Level )then
90 224 jshamlet
      Reg_Sel                <= '0';
91
      Wr_En                  <= '0';
92
      Wr_Data_q              <= x"00";
93
      Rd_En                  <= '0';
94
      Rd_Data                <= OPEN8_NULLBUS;
95
      User_Out               <= Default_Out;
96 167 jshamlet
      if( not Disable_Tristate)then
97 224 jshamlet
        User_En              <= Default_En;
98 167 jshamlet
      end if;
99
    elsif( rising_edge( Clock ) )then
100 224 jshamlet
      Reg_Sel                <= Reg_Addr;
101
      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 224 jshamlet
          User_Out           <= Wr_Data_q;
106 167 jshamlet
        else
107
          if( Reg_Sel = '0' )then
108 224 jshamlet
            User_Out         <= Wr_Data_q;
109 167 jshamlet
          else
110 224 jshamlet
            User_En          <= Wr_Data_q;
111 167 jshamlet
          end if;
112
        end if;
113
      end if;
114
 
115 224 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
116
      Rd_En                  <= Addr_Match and Open8_Bus.Rd_En;
117 167 jshamlet
      if( Rd_En = '1' )then
118 224 jshamlet
        Rd_Data              <= User_Out;
119 167 jshamlet
        if( (Reg_Sel = '1') and (not Disable_Tristate) )then
120 224 jshamlet
          Rd_Data            <= User_En;
121 167 jshamlet
        end if;
122
      end if;
123
    end if;
124
  end process;
125
 
126
No_Tristates: if( Disable_Tristate )generate
127 224 jshamlet
  GPO                        <= User_Out;
128 167 jshamlet
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 224 jshamlet
      GPO(i)                 <= 'Z';
136 167 jshamlet
      if( User_En(i) = '1' )then
137 224 jshamlet
        GPO(i)               <= User_Out(i);
138 167 jshamlet
      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.