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 213

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
  Bus_Address           : in  ADDRESS_TYPE;
62
  Wr_Enable             : in  std_logic;
63
  Wr_Data               : in  DATA_TYPE;
64
  Rd_Enable             : in  std_logic;
65
  Rd_Data               : out DATA_TYPE;
66
  --
67
  GPO                   : out DATA_TYPE
68
);
69
end entity;
70
 
71
architecture behave of o8_gpout is
72
 
73
  constant User_Addr    : std_logic_vector(15 downto 1)
74
                          := Address(15 downto 1);
75
  alias  Comp_Addr      is Bus_Address(15 downto 1);
76
  alias  Reg_Addr       is Bus_Address(0);
77
  signal Reg_Sel        : std_logic;
78
  signal Addr_Match     : std_logic;
79
  signal Wr_En          : std_logic;
80
  signal Wr_Data_q      : DATA_TYPE;
81
  signal Rd_En          : std_logic;
82
 
83
  signal User_Out       : DATA_TYPE;
84
  signal User_En        : DATA_TYPE;
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
      Reg_Sel           <= '0';
94
      Wr_En             <= '0';
95
      Wr_Data_q         <= x"00";
96
      Rd_En             <= '0';
97 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
98 167 jshamlet
      User_Out          <= Default_Out;
99
      if( not Disable_Tristate)then
100
        User_En         <= Default_En;
101
      end if;
102
    elsif( rising_edge( Clock ) )then
103
      Reg_Sel           <= Reg_Addr;
104
      Wr_En             <= Addr_Match and Wr_Enable;
105
      Wr_Data_q         <= Wr_Data;
106
      if( Wr_En = '1' )then
107
        if( Disable_Tristate )then
108
          User_Out      <= Wr_Data_q;
109
        else
110
          if( Reg_Sel = '0' )then
111
            User_Out    <= Wr_Data_q;
112
          else
113
            User_En     <= Wr_Data_q;
114
          end if;
115
        end if;
116
      end if;
117
 
118 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
119 167 jshamlet
      Rd_En             <= Addr_Match and Rd_Enable;
120
      if( Rd_En = '1' )then
121
        Rd_Data         <= User_Out;
122
        if( (Reg_Sel = '1') and (not Disable_Tristate) )then
123
          Rd_Data       <= User_En;
124
        end if;
125
      end if;
126
    end if;
127
  end process;
128
 
129
No_Tristates: if( Disable_Tristate )generate
130
  GPO                   <= User_Out;
131
end generate;
132
 
133
Tristates: if( not Disable_Tristate )generate
134
 
135
  Output_Ctl_proc: process( User_Out, User_En )
136
  begin
137
    for i in 0 to 7 loop
138
      GPO(i)            <= 'Z';
139
      if( User_En(i) = '1' )then
140
        GPO(i)          <= User_Out(i);
141
      end if;
142
    end loop;
143
  end process;
144
 
145
end generate;
146
 
147
end architecture;

powered by: WebSVN 2.1.0

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