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 244

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 244 jshamlet
-- Seth Henry      05/18/20 Added write qualification input
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_gpio is
50
generic(
51 213 jshamlet
  Default_Out                : DATA_TYPE := x"00";
52
  Default_En                 : DATA_TYPE := x"00";
53
  Address                    : ADDRESS_TYPE
54 167 jshamlet
);
55
port(
56 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
57 244 jshamlet
  Write_Qual                 : in  std_logic := '1';
58 213 jshamlet
  Rd_Data                    : out DATA_TYPE;
59 167 jshamlet
  --
60 213 jshamlet
  GPIO                       : inout DATA_TYPE
61 167 jshamlet
);
62
end entity;
63
 
64
architecture behave of o8_gpio is
65
 
66 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
67
  alias Reset                is Open8_Bus.Reset;
68
 
69 213 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 2)
70
                               := Address(15 downto 2);
71 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
72 244 jshamlet
  signal Addr_Match          : std_logic;
73
 
74
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
75
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
76
  signal Wr_En_d             : std_logic := '0';
77
  signal Wr_En_q             : std_logic := '0';
78
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
79 223 jshamlet
  signal Wr_Data_q           : DATA_TYPE := x"00";
80 244 jshamlet
  signal Rd_En_d             : std_logic := '0';
81
  signal Rd_En_q             : std_logic := '0';
82 167 jshamlet
 
83 223 jshamlet
  signal User_Out            : DATA_TYPE := x"00";
84
  signal User_En             : DATA_TYPE := x"00";
85
  signal User_In             : DATA_TYPE := x"00";
86 167 jshamlet
 
87
begin
88
 
89 213 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
90 244 jshamlet
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En and Write_Qual;
91
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
92 167 jshamlet
 
93
  io_reg: process( Clock, Reset )
94
  begin
95
    if( Reset = Reset_Level )then
96 244 jshamlet
      Reg_Sel_q              <= "00";
97
      Wr_En_q                <= '0';
98
      Wr_Data_q              <= x"00";
99
      Rd_En_q                <= '0';
100 213 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
101 244 jshamlet
 
102 213 jshamlet
      User_Out               <= Default_Out;
103
      User_En                <= Default_En;
104 167 jshamlet
    elsif( rising_edge( Clock ) )then
105 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
106 167 jshamlet
 
107 244 jshamlet
      Wr_En_q                <= Wr_En_d;
108
      Wr_Data_q              <= Wr_Data_d;
109
      if( Wr_En_q = '1' )then
110
        case( Reg_Sel_q )is
111 213 jshamlet
          when "00" =>
112
            User_Out         <= Wr_Data_q;
113
          when "01" =>
114
            User_En          <= Wr_Data_q;
115
          when others => null;
116
        end case;
117 167 jshamlet
      end if;
118
 
119 213 jshamlet
      User_In                <= GPIO;
120 167 jshamlet
 
121 244 jshamlet
      Rd_En_q                <= Rd_En_d;
122 213 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
123 244 jshamlet
      if( Rd_En_q = '1' )then
124
        case( Reg_Sel_q )is
125 213 jshamlet
          when "00" =>
126
            Rd_Data          <= User_Out;
127
          when "01" =>
128
            Rd_Data          <= User_En;
129
          when "10" =>
130
            Rd_Data          <= User_In;
131
          when others => null;
132
        end case;
133 167 jshamlet
      end if;
134
    end if;
135
  end process;
136
 
137
  Output_Ctl_proc: process( User_Out, User_En )
138
  begin
139
    for i in 0 to 7 loop
140 213 jshamlet
      GPIO(i)                <= 'Z';
141 167 jshamlet
      if( User_En(i) = '1' )then
142 213 jshamlet
        GPIO(i)              <= User_Out(i);
143 167 jshamlet
      end if;
144
    end loop;
145
  end process;
146
 
147
end architecture;

powered by: WebSVN 2.1.0

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