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

Subversion Repositories potato

[/] [potato/] [trunk/] [soc/] [pp_soc_gpio.vhd] - Blame information for rev 10

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

Line No. Rev Author Line
1 7 skordal
-- The Potato Processor - A simple processor for FPGAs
2
-- (c) Kristian Klomsten Skordal 2014 - 2015 <kristian.skordal@wafflemail.net>
3
-- Report bugs and issues on <https://github.com/skordal/potato/issues>
4
 
5
library ieee;
6
use ieee.std_logic_1164.all;
7
use ieee.numeric_std.all;
8
 
9
--! @brief Generic Wishbone GPIO Module.
10
--! The following registers are defined:
11
--! * 0: Input values, one bit per GPIO (read-only)
12
--! * 1: Output values, one bit per GPIO (read/write)
13
--! * 2: Direction register, 0 means input, 1 means output.
14
entity pp_soc_gpio is
15
        generic(
16
                NUM_GPIOS : natural := 32
17
        );
18
        port(
19
                clk : in std_logic;
20
                reset : in std_logic;
21
 
22
                -- GPIO interface:
23
                gpio : inout std_logic_vector(NUM_GPIOS - 1 downto 0);
24
 
25
                -- Wishbone interface:
26
                wb_adr_in  : in  std_logic_vector( 1 downto 0);
27
                wb_dat_in  : in  std_logic_vector(31 downto 0);
28
                wb_dat_out : out std_logic_vector(31 downto 0);
29
                wb_cyc_in  : in  std_logic;
30
                wb_stb_in  : in  std_logic;
31
                wb_we_in   : in  std_logic;
32
                wb_ack_out : out std_logic
33
        );
34
end entity pp_soc_gpio;
35
 
36
architecture behaviour of pp_soc_gpio is
37
 
38
        signal direction_register : std_logic_vector(NUM_GPIOS - 1 downto 0);
39
        signal output_register : std_logic_vector(NUM_GPIOS - 1 downto 0);
40
        signal input_register : std_logic_vector(NUM_GPIOS - 1 downto 0);
41
 
42
        signal ack : std_logic := '0';
43
 
44
begin
45
 
46
        assert NUM_GPIOS > 0 and NUM_GPIOS <= 32
47
                report "Only a number between 1 and 32 (inclusive) GPIOs are supported!"
48
                severity FAILURE;
49
 
50
        io_setup: for i in 0 to NUM_GPIOS - 1 generate
51
                gpio(i) <= 'Z' when direction_register(i) = '0' else output_register(i);
52
                input_register(i) <= gpio(i) when direction_register(i) = '0' else '0';
53
        end generate;
54
 
55
        wb_ack_out <= ack and wb_cyc_in and wb_stb_in;
56
 
57
        wishbone: process(clk)
58
        begin
59
                if rising_edge(clk) then
60
                        if reset = '1' then
61
                                direction_register <= (others => '0');
62
                                output_register <= (others => '0');
63
                                wb_dat_out <= (others => '0');
64
                                ack <= '0';
65
                        else
66
                                if wb_cyc_in = '1' and wb_stb_in = '1' and ack = '0' then
67
                                        if wb_we_in = '1' then
68
                                                case wb_adr_in is
69
                                                        when b"01" =>
70
                                                                output_register <= wb_dat_in(NUM_GPIOS - 1 downto 0);
71
                                                        when b"10" =>
72
                                                                direction_register <= wb_dat_in(NUM_GPIOS - 1 downto 0);
73
                                                        when others =>
74
                                                end case;
75
                                                ack <= '1';
76
                                        else
77
                                                case wb_adr_in is
78
                                                        when b"00" =>
79
                                                                wb_dat_out <= std_logic_vector(resize(unsigned(input_register), wb_dat_out'length));
80
                                                        when b"01" =>
81
                                                                wb_dat_out <= std_logic_vector(resize(unsigned(output_register), wb_dat_out'length));
82
                                                        when b"10" =>
83
                                                                wb_dat_out <= std_logic_vector(resize(unsigned(direction_register), wb_dat_out'length));
84
                                                        when others =>
85
                                                end case;
86
                                                ack <= '1';
87
                                        end if;
88
                                elsif wb_stb_in = '0' then
89
                                        ack <= '0';
90
                                end if;
91
                        end if;
92
                end if;
93
        end process wishbone;
94
 
95
end architecture behaviour;

powered by: WebSVN 2.1.0

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