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

Subversion Repositories neo430

[/] [neo430/] [trunk/] [neo430/] [rtl/] [core/] [neo430_gpio.vhd] - Blame information for rev 198

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 198 zero_gravi
-- #################################################################################################
2
-- #  << NEO430 - General Purpose Parallel IO Unit >>                                              #
3
-- # ********************************************************************************************* #
4
-- # 16-bit parallel input & output unit. Any pin-change (HI->LO or LO->HI) triggers the IRQ.      #
5
-- # Pins used for the pin change interrupt are selected using a 16-bit mask.                      #
6
-- # The PWM controller can be used to module the GPIO controller's output.                        #
7
-- # ********************************************************************************************* #
8
-- # BSD 3-Clause License                                                                          #
9
-- #                                                                                               #
10
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
11
-- #                                                                                               #
12
-- # Redistribution and use in source and binary forms, with or without modification, are          #
13
-- # permitted provided that the following conditions are met:                                     #
14
-- #                                                                                               #
15
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
16
-- #    conditions and the following disclaimer.                                                   #
17
-- #                                                                                               #
18
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
19
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
20
-- #    provided with the distribution.                                                            #
21
-- #                                                                                               #
22
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
23
-- #    endorse or promote products derived from this software without specific prior written      #
24
-- #    permission.                                                                                #
25
-- #                                                                                               #
26
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
27
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
28
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
29
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
30
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
31
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
32
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
33
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
34
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
35
-- # ********************************************************************************************* #
36
-- # The NEO430 Processor - https://github.com/stnolting/neo430                                    #
37
-- #################################################################################################
38
 
39
library ieee;
40
use ieee.std_logic_1164.all;
41
use ieee.numeric_std.all;
42
 
43
library neo430;
44
use neo430.neo430_package.all;
45
 
46
entity neo430_gpio is
47
  port (
48
    -- host access --
49
    clk_i      : in  std_ulogic; -- global clock line
50
    rden_i     : in  std_ulogic; -- read enable
51
    wren_i     : in  std_ulogic; -- write enable
52
    addr_i     : in  std_ulogic_vector(15 downto 0); -- address
53
    data_i     : in  std_ulogic_vector(15 downto 0); -- data in
54
    data_o     : out std_ulogic_vector(15 downto 0); -- data out
55
    -- parallel io --
56
    gpio_o     : out std_ulogic_vector(15 downto 0);
57
    gpio_i     : in  std_ulogic_vector(15 downto 0);
58
    -- GPIO PWM --
59
    gpio_pwm_i : in  std_ulogic;
60
    -- interrupt --
61
    irq_o      : out std_ulogic
62
  );
63
end neo430_gpio;
64
 
65
architecture neo430_gpio_rtl of neo430_gpio is
66
 
67
  -- IO space: module base address --
68
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
69
  constant lo_abb_c : natural := index_size_f(gpio_size_c); -- low address boundary bit
70
 
71
  -- access control --
72
  signal acc_en : std_ulogic; -- module access enable
73
  signal addr   : std_ulogic_vector(15 downto 0); -- access address
74
  signal wren   : std_ulogic; -- word write enable
75
  signal rden   : std_ulogic; -- read enable
76
 
77
  -- accessible regs --
78
  signal dout, din : std_ulogic_vector(15 downto 0); -- r/w
79
  signal irq_mask  : std_ulogic_vector(15 downto 0); -- -/w
80
 
81
  -- misc --
82
  signal irq_raw, sync_in, in_buf : std_ulogic_vector(15 downto 0);
83
 
84
begin
85
 
86
  -- Access Control -----------------------------------------------------------
87
  -- -----------------------------------------------------------------------------
88
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = gpio_base_c(hi_abb_c downto lo_abb_c)) else '0';
89
  addr   <= gpio_base_c(15 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 1) & '0'; -- word aligned
90
  wren   <= acc_en and wren_i;
91
  rden   <= acc_en and rden_i;
92
 
93
 
94
  -- Write access -------------------------------------------------------------
95
  -- -----------------------------------------------------------------------------
96
  wr_access: process(clk_i)
97
  begin
98
    if rising_edge(clk_i) then
99
      if (wren = '1') then
100
        if (addr = gpio_out_addr_c) then
101
          dout <= data_i;
102
        end if;
103
        if (addr = gpio_irqmask_addr_c) then
104
          irq_mask <= data_i;
105
        end if;
106
      end if;
107
    end if;
108
  end process wr_access;
109
 
110
  -- (PWM modulated) output --
111
  gpio_o <= dout when (gpio_pwm_i = '1') else (others => '0');
112
 
113
 
114
  -- IRQ Generator ------------------------------------------------------------
115
  -- -----------------------------------------------------------------------------
116
  irq_generator: process(clk_i)
117
  begin
118
    if rising_edge(clk_i) then
119
      -- input synchronizer --
120
      in_buf  <= gpio_i;
121
      din     <= in_buf;
122
      sync_in <= din;
123
      -- IRQ --
124
      irq_o <= or_all_f(irq_raw);
125
    end if;
126
  end process irq_generator;
127
 
128
  -- any transition triggers an interrupt (if enabled for according input pin) --
129
  irq_raw <= (din xor sync_in) and irq_mask;
130
 
131
 
132
  -- Read access --------------------------------------------------------------
133
  -- -----------------------------------------------------------------------------
134
  rd_access: process(clk_i)
135
  begin
136
    if rising_edge(clk_i) then
137
      -- read access --
138
      data_o <= (others => '0');
139
      if (rden = '1') then
140
        if (addr = gpio_in_addr_c) then
141
          data_o <= din;
142
        else -- gpio_out_addr_c
143
          data_o <= dout;
144
        end if;
145
      end if;
146
    end if;
147
  end process rd_access;
148
 
149
 
150
end neo430_gpio_rtl;

powered by: WebSVN 2.1.0

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