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

Subversion Repositories wb4pb

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

Go to most recent revision | 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
--    and/or other materials provided with the distribution. 
17
--  * Neither the name of the author nor the names of his contributors may be 
18
--    used to endorse or promote products derived from this software without 
19
--    specific prior written permission.
20
--
21
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
22
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
23
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
24
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
25
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
26
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
27
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
28
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
29
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
30
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
31
-- POSSIBILITY OF SUCH DAMAGE.
32
--
33
--------------------------------------------------------------------------------
34
-- filename: wbs_gpio.vhd
35
-- description: synthesizable wishbone slave general purpose i/o module
36
-- todo4user: add more i/o ports as needed
37
-- version: 0.0.0
38
-- changelog: - 0.0.0, initial release
39
--            - ...
40
--------------------------------------------------------------------------------
41
 
42
 
43
library ieee;
44
use ieee.std_logic_1164.all;
45
 
46
 
47
entity wbs_gpio is
48
  port
49
  (
50
    rst : in std_logic;
51
    clk : in std_logic;
52
 
53
    wbs_cyc_i : in std_logic;
54
    wbs_stb_i : in std_logic;
55
    wbs_we_i : in std_logic;
56
    wbs_adr_i : in std_logic_vector(7 downto 0);
57
    wbs_dat_m2s_i : in std_logic_vector(7 downto 0);
58
    wbs_dat_s2m_o : out std_logic_vector(7 downto 0);
59
    wbs_ack_o : out std_logic;
60
 
61
    gpio_in_i : in std_logic_vector(7 downto 0);
62
    gpio_out_o : out std_logic_vector(7 downto 0);
63
    gpio_oe_o : out std_logic_vector(7 downto 0)
64
  );
65
end wbs_gpio;
66
 
67
 
68
architecture rtl of wbs_gpio is
69
 
70
  signal wbs_dat_s2m : std_logic_vector(7 downto 0) := (others => '0');
71
  signal wbs_ack : std_logic := '0';
72
 
73
  signal gpio_out : std_logic_vector(7 downto 0) := (others => '0');
74
  signal gpio_oe : std_logic_vector(7 downto 0) := (others => '0');
75
 
76
  signal wb_reg_we : std_logic := '0';
77
 
78
  signal gpio_in : std_logic_vector(7 downto 0) := (others => '0');
79
 
80
  constant IS_INPUT : std_logic := '0';
81
  constant IS_OUTPUT : std_logic := not IS_INPUT;
82
 
83
  constant ADDR_MSB : natural := 0;
84
  constant GPIO_IO_ADDR : std_logic_vector(7 downto 0) := x"00";
85
  constant GPIO_OE_ADDR : std_logic_vector(7 downto 0) := x"01";
86
 
87
begin
88
 
89
  wbs_dat_s2m_o <= wbs_dat_s2m;
90
  wbs_ack_o <= wbs_ack;
91
 
92
  gpio_out_o <= gpio_out;
93
  gpio_oe_o <= gpio_oe;
94
 
95
  -- internal register write enable signal
96
  wb_reg_we <= wbs_cyc_i and wbs_stb_i and wbs_we_i;
97
 
98
  process(clk)
99
  begin
100
    if clk'event and clk = '1' then
101
 
102
      gpio_in <= gpio_in_i;
103
 
104
      wbs_dat_s2m <= (others => '0');
105
      -- registered wishbone slave handshake
106
      wbs_ack <= wbs_cyc_i and wbs_stb_i and (not wbs_ack);
107
 
108
      case wbs_adr_i(ADDR_MSB downto 0) is
109
        -- i/o register access
110
        when GPIO_IO_ADDR(ADDR_MSB downto 0) =>
111
          if wb_reg_we = '1' then
112
            gpio_out <= wbs_dat_m2s_i;
113
          end if;
114
          wbs_dat_s2m <= gpio_in;
115
        -- output enable register access
116
        when GPIO_OE_ADDR(ADDR_MSB downto 0) =>
117
          if wb_reg_we = '1' then
118
            gpio_oe <= wbs_dat_m2s_i;
119
          end if;
120
          wbs_dat_s2m <= gpio_oe;
121
        when others => null;
122
      end case;
123
 
124
      if rst = '1' then
125
        wbs_ack <= '0';
126
        gpio_oe <= (others => IS_INPUT);
127
      end if;
128
 
129
    end if;
130
  end process;
131
 
132
end rtl;

powered by: WebSVN 2.1.0

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