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

Subversion Repositories wb4pb

[/] [wb4pb/] [trunk/] [rtl/] [wbs_gpio.vhd] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ste.fis
--------------------------------------------------------------------------------
2
-- This sourcecode is released under BSD license.
3
-- Please see http://www.opensource.org/licenses/bsd-license.php for details!
4
--------------------------------------------------------------------------------
5
--
6
-- Copyright (c) 2010, Stefan Fischer <Ste.Fis@OpenCores.org>
7
-- All rights reserved.
8
--
9
-- Redistribution and use in source and binary forms, with or without 
10
-- modification, are permitted provided that the following conditions are met:
11
--
12
--  * Redistributions of source code must retain the above copyright notice, 
13
--    this list of conditions and the following disclaimer.
14
--  * Redistributions in binary form must reproduce the above copyright notice,
15
--    this list of conditions and the following disclaimer in the documentation
16 31 ste.fis
--    and/or other materials provided with the distribution.
17 2 ste.fis
--
18
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
19
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
20
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
21
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
22
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
23
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
24
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
25
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
26
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
27
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
28
-- POSSIBILITY OF SUCH DAMAGE.
29
--
30
--------------------------------------------------------------------------------
31
-- filename: wbs_gpio.vhd
32
-- description: synthesizable wishbone slave general purpose i/o module
33
-- todo4user: add more i/o ports as needed
34
-- version: 0.0.0
35
-- changelog: - 0.0.0, initial release
36
--            - ...
37
--------------------------------------------------------------------------------
38
 
39
 
40
library ieee;
41
use ieee.std_logic_1164.all;
42
 
43
 
44
entity wbs_gpio is
45
  port
46
  (
47
    rst : in std_logic;
48
    clk : in std_logic;
49
 
50
    wbs_cyc_i : in std_logic;
51
    wbs_stb_i : in std_logic;
52
    wbs_we_i : in std_logic;
53
    wbs_adr_i : in std_logic_vector(7 downto 0);
54
    wbs_dat_m2s_i : in std_logic_vector(7 downto 0);
55
    wbs_dat_s2m_o : out std_logic_vector(7 downto 0);
56
    wbs_ack_o : out std_logic;
57
 
58
    gpio_in_i : in std_logic_vector(7 downto 0);
59
    gpio_out_o : out std_logic_vector(7 downto 0);
60
    gpio_oe_o : out std_logic_vector(7 downto 0)
61
  );
62
end wbs_gpio;
63
 
64
 
65
architecture rtl of wbs_gpio is
66
 
67
  signal wbs_dat_s2m : std_logic_vector(7 downto 0) := (others => '0');
68
  signal wbs_ack : std_logic := '0';
69
 
70
  signal gpio_out : std_logic_vector(7 downto 0) := (others => '0');
71
  signal gpio_oe : std_logic_vector(7 downto 0) := (others => '0');
72
 
73
  signal wb_reg_we : std_logic := '0';
74
 
75
  signal gpio_in : std_logic_vector(7 downto 0) := (others => '0');
76
 
77
  constant IS_INPUT : std_logic := '0';
78
  constant IS_OUTPUT : std_logic := not IS_INPUT;
79
 
80
  constant ADDR_MSB : natural := 0;
81
  constant GPIO_IO_ADDR : std_logic_vector(7 downto 0) := x"00";
82
  constant GPIO_OE_ADDR : std_logic_vector(7 downto 0) := x"01";
83
 
84
begin
85
 
86
  wbs_dat_s2m_o <= wbs_dat_s2m;
87
  wbs_ack_o <= wbs_ack;
88
 
89
  gpio_out_o <= gpio_out;
90
  gpio_oe_o <= gpio_oe;
91
 
92
  -- internal register write enable signal
93
  wb_reg_we <= wbs_cyc_i and wbs_stb_i and wbs_we_i;
94
 
95
  process(clk)
96
  begin
97
    if clk'event and clk = '1' then
98
 
99
      gpio_in <= gpio_in_i;
100
 
101
      wbs_dat_s2m <= (others => '0');
102
      -- registered wishbone slave handshake
103
      wbs_ack <= wbs_cyc_i and wbs_stb_i and (not wbs_ack);
104
 
105
      case wbs_adr_i(ADDR_MSB downto 0) is
106
        -- i/o register access
107
        when GPIO_IO_ADDR(ADDR_MSB downto 0) =>
108
          if wb_reg_we = '1' then
109
            gpio_out <= wbs_dat_m2s_i;
110
          end if;
111
          wbs_dat_s2m <= gpio_in;
112
        -- output enable register access
113
        when GPIO_OE_ADDR(ADDR_MSB downto 0) =>
114
          if wb_reg_we = '1' then
115
            gpio_oe <= wbs_dat_m2s_i;
116
          end if;
117
          wbs_dat_s2m <= gpio_oe;
118
        when others => null;
119
      end case;
120
 
121
      if rst = '1' then
122
        wbs_ack <= '0';
123
        gpio_oe <= (others => IS_INPUT);
124
      end if;
125
 
126
    end if;
127
  end process;
128
 
129
end rtl;

powered by: WebSVN 2.1.0

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