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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_gpio.vhd] - Blame information for rev 242

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

Line No. Rev Author Line
1 194 jshamlet
-- Copyright (c)2013, 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_gpio
25
-- Description:  Provides a single 8-bit GPIO register
26 213 jshamlet
--
27
-- Register Map:
28
-- Offset  Bitfield Description                        Read/Write
29
--   0x00  AAAAAAAA Output Register                       (RW)
30
--   0x01  AAAAAAAA Direction Register                    (RW)
31
--   0x03  AAAAAAAA Input Register                        (RO)
32
--
33
-- Revision History
34
-- Author          Date     Change
35
------------------ -------- ---------------------------------------------------
36
-- Seth Henry      12/20/13 Design Start
37
-- Seth Henry      04/10/20 Code cleanup and register documentation
38
--                          Also removed "input only" generic, as there is a
39
--                           separate module for that
40 224 jshamlet
-- Seth Henry      04/16/20 Modified to make use of Open8 bus record
41 167 jshamlet
 
42
library ieee;
43
use ieee.std_logic_1164.all;
44
 
45
library work;
46
  use work.open8_pkg.all;
47
 
48
entity o8_gpio is
49
generic(
50 213 jshamlet
  Default_Out                : DATA_TYPE := x"00";
51
  Default_En                 : DATA_TYPE := x"00";
52
  Address                    : ADDRESS_TYPE
53 167 jshamlet
);
54
port(
55 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
56 213 jshamlet
  Rd_Data                    : out DATA_TYPE;
57 167 jshamlet
  --
58 213 jshamlet
  GPIO                       : inout DATA_TYPE
59 167 jshamlet
);
60
end entity;
61
 
62
architecture behave of o8_gpio is
63
 
64 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
65
  alias Reset                is Open8_Bus.Reset;
66
 
67 213 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 2)
68
                               := Address(15 downto 2);
69 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
70
  alias  Reg_Addr            is Open8_Bus.Address(1 downto 0);
71
  signal Reg_Sel             : std_logic_vector(1 downto 0) := "00";
72
  signal Addr_Match          : std_logic := '0';
73
  signal Wr_En               : std_logic := '0';
74
  signal Wr_Data_q           : DATA_TYPE := x"00";
75
  signal Rd_En               : std_logic := '0';
76 167 jshamlet
 
77 223 jshamlet
  signal User_Out            : DATA_TYPE := x"00";
78
  signal User_En             : DATA_TYPE := x"00";
79
  signal User_In             : DATA_TYPE := x"00";
80 167 jshamlet
 
81
begin
82
 
83 213 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
84 167 jshamlet
 
85
  io_reg: process( Clock, Reset )
86
  begin
87
    if( Reset = Reset_Level )then
88 213 jshamlet
      Reg_Sel                <= "00";
89
      Rd_En                  <= '0';
90
      Rd_Data                <= OPEN8_NULLBUS;
91
      Wr_En                  <= '0';
92
      Wr_Data_q              <= x"00";
93
      User_Out               <= Default_Out;
94
      User_En                <= Default_En;
95 167 jshamlet
    elsif( rising_edge( Clock ) )then
96 213 jshamlet
      Reg_Sel                <= Reg_Addr;
97 167 jshamlet
 
98 223 jshamlet
      Wr_En                  <= Addr_Match and Open8_Bus.Wr_En;
99
      Wr_Data_q              <= Open8_Bus.Wr_Data;
100 213 jshamlet
      if( Wr_En = '1' )then
101
        case( Reg_Sel )is
102
          when "00" =>
103
            User_Out         <= Wr_Data_q;
104
          when "01" =>
105
            User_En          <= Wr_Data_q;
106
          when others => null;
107
        end case;
108 167 jshamlet
      end if;
109
 
110 213 jshamlet
      User_In                <= GPIO;
111 167 jshamlet
 
112 213 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
113 223 jshamlet
      Rd_En                  <= Addr_Match and Open8_Bus.Rd_En;
114 167 jshamlet
      if( Rd_En = '1' )then
115 213 jshamlet
        Rd_Data              <= User_In;
116
        case( Reg_Sel )is
117
          when "00" =>
118
            Rd_Data          <= User_Out;
119
          when "01" =>
120
            Rd_Data          <= User_En;
121
          when "10" =>
122
            Rd_Data          <= User_In;
123
          when others => null;
124
        end case;
125 167 jshamlet
      end if;
126
    end if;
127
  end process;
128
 
129
  Output_Ctl_proc: process( User_Out, User_En )
130
  begin
131
    for i in 0 to 7 loop
132 213 jshamlet
      GPIO(i)                <= 'Z';
133 167 jshamlet
      if( User_En(i) = '1' )then
134 213 jshamlet
        GPIO(i)              <= User_Out(i);
135 167 jshamlet
      end if;
136
    end loop;
137
  end process;
138
 
139
end architecture;

powered by: WebSVN 2.1.0

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