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

Subversion Repositories riscompatible

[/] [riscompatible/] [trunk/] [rtl/] [gpio.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 borin
-------------------------------------------------------------------------------------------------------------------
2
library ieee;
3
use ieee.std_logic_1164.all;
4
use ieee.numeric_std.all;
5
use work.riscompatible_package.all;
6
-------------------------------------------------------------------------------------------------------------------
7
entity GPIO is
8
    generic
9
    (
10
        NumBitsAddr        : natural:=1;
11
        NumBitsInputPorts  : natural:=2;
12
        NumBitsOutputPorts : natural:=2
13
    );
14
    port
15
    (
16
        Clk_I            : in  std_logic;
17
        Enable_I         : in  std_logic;
18
        Write_I          : in  std_logic;
19
        Address_I        : in  std_logic_vector(NumBitsAddr-1 downto 0);
20
        InputData_I      : in  std_logic_vector(C_NumBitsWord-1 downto 0);
21
        OutputData_O     : out std_logic_vector(C_NumBitsWord-1 downto 0);
22
        OutputData_Vld_O : out std_logic;
23
        InputPorts_I     : in  std_logic_vector(NumBitsInputPorts-1 downto 0);
24
        OutputPorts_O    : out std_logic_vector(NumBitsOutputPorts-1 downto 0)
25
    );
26
end GPIO;
27
-------------------------------------------------------------------------------------------------------------------
28
architecture behavioral of GPIO is
29
   function num_bits(num_io : integer) return integer is
30
   begin
31
      case num_io is
32
         when 0|1|2 =>
33
             return (1);
34
         when 3|4 =>
35
             return (2);
36
         when 5|6|7|8 =>
37
             return (3);
38
         when 9|10|11|12|13|14|15|16 =>
39
             return (4);
40
         when 17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32 =>
41
             return (5);
42
         when others => return (-1);
43
      end case;
44
 
45
   end function num_bits;
46
begin
47
 
48
process (Clk_I,Address_I)
49
begin
50
    if Clk_I'event and Clk_I = '1' then
51
        if (Enable_I = '1') then
52
            if (Write_I = '1') and Address_I(Address_I'high)='1' then
53
                if to_integer(unsigned(Address_I(Address_I'high-1 downto 0))) * C_NumBitsWord < NumBitsOutputPorts then
54
                    for i in 0 to 31 loop
55
                        if to_integer(unsigned(Address_I(Address_I'high-1 downto 0))) * C_NumBitsWord + i < NumBitsOutputPorts then
56
                            OutputPorts_O(i) <= InputData_I(i);
57
                        end if;
58
                    end loop;
59
                end if;
60
            end if;
61
        end if;
62
        if Address_I(Address_I'high)='1' then
63
            OutputData_Vld_O <= '1';
64
        else
65
            OutputData_Vld_O <= '0';
66
        end if;
67
        for i in 0 to 31 loop
68
            if to_integer(unsigned(Address_I(Address_I'high-1 downto 0))) * C_NumBitsWord + i < NumBitsInputPorts then
69
                OutputData_O(i) <= InputPorts_I(i);
70
            else
71
                OutputData_O(i) <= '0';
72
            end if;
73
        end loop;
74
    end if;
75
end process;
76
 
77
end behavioral;
78
-------------------------------------------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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