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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_btn_int.vhd] - Blame information for rev 189

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

Line No. Rev Author Line
1 173 jshamlet
-- Copyright (c)2013 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_btn_int
25
-- Description:  Detects and reports when a user pushbutton is pressed with an
26 189 jshamlet
--                interrupt.
27 173 jshamlet
 
28
library ieee;
29
use ieee.std_logic_1164.all;
30
use ieee.std_logic_unsigned.all;
31
use ieee.std_logic_misc.all;
32
 
33
library work;
34
  use work.open8_pkg.all;
35
 
36
entity o8_btn_int is
37
generic(
38
  Button_Level          : std_logic;
39
  Address               : ADDRESS_TYPE;
40
  Reset_Level           : std_logic
41
);
42
port(
43
  Clock                 : in  std_logic;
44
  Reset                 : in  std_logic;
45
  uSec_Tick             : in  std_logic;
46
  --
47
  Bus_Address           : in  ADDRESS_TYPE;
48
  Rd_Enable             : in  std_logic;
49
  Rd_Data               : out DATA_TYPE;
50
  Interrupt             : out std_logic;
51
  --
52
  Button1_In            : in  std_logic;
53
  Button2_In            : in  std_logic
54
);
55
end entity;
56
 
57
architecture behave of o8_btn_int is
58
 
59
  constant User_Addr    : std_logic_vector(15 downto 0) := Address;
60
  alias  Comp_Addr      is Bus_Address(15 downto 0);
61
  signal Addr_Match     : std_logic;
62
  signal Rd_En          : std_logic;
63
 
64
  signal Button1_SR     : std_logic_vector(2 downto 0);
65
  alias  Button1_In_q   is Button1_SR(2);
66
 
67
  signal Button1_Dn_Tmr : std_logic_vector(7 downto 0);
68
  signal Button1_Dn     : std_logic;
69
 
70
  signal Button1_Up_Tmr : std_logic_vector(7 downto 0);
71
  signal Button1_Up     : std_logic;
72
 
73
  signal Button1_State  : std_logic;
74
  signal Button1_State_q: std_logic;
75
 
76
  signal Button1_Int    : std_logic;
77
 
78
  signal Button2_SR     : std_logic_vector(2 downto 0);
79
  alias  Button2_In_q   is Button2_SR(2);
80
 
81
  signal Button2_Dn_Tmr : std_logic_vector(7 downto 0);
82
  signal Button2_Dn     : std_logic;
83
 
84
  signal Button2_Up_Tmr : std_logic_vector(7 downto 0);
85
  signal Button2_Up     : std_logic;
86
 
87
  signal Button2_State  : std_logic;
88
  signal Button2_State_q: std_logic;
89
 
90
  signal Button2_Int    : std_logic;
91
 
92
begin
93
 
94
  Addr_Match            <= Rd_Enable when Comp_Addr = User_Addr else '0';
95
 
96
  io_reg: process( Clock, Reset )
97
  begin
98
    if( Reset = Reset_Level )then
99
      Rd_En             <= '0';
100
      Rd_Data           <= x"00";
101
    elsif( rising_edge( Clock ) )then
102
      Rd_En             <= Addr_Match;
103
      Rd_Data           <= (others => '0');
104
      if( Rd_En = '1' )then
105
        Rd_Data(6)      <= Button1_State;
106
        Rd_Data(7)      <= Button2_State;
107
      end if;
108
 
109
    end if;
110
  end process;
111
 
112
  Interrupt             <= Button1_Int or Button2_Int;
113
 
114
  Button1_trap: process( Clock, Reset )
115
  begin
116
    if( Reset = Reset_Level )then
117
      Button1_SR         <= (others => '0');
118
 
119
      Button1_Dn_Tmr     <= (others => '0');
120
      Button1_Dn         <= '0';
121
 
122
      Button1_Up_Tmr     <= (others => '0');
123
      Button1_Up         <= '0';
124
 
125
      Button1_State      <= '0';
126
      Button1_State_q    <= '0';
127
 
128
      Button1_Int        <= '0';
129
    elsif( rising_edge(Clock) )then
130
      Button1_SR        <= Button1_SR(1 downto 0) & Button1_In;
131
 
132
      Button1_Dn_Tmr    <= (others => '0');
133
      Button1_Dn        <= '0';
134
      if( Button1_In_q = Button_Level )then
135
        Button1_Dn_Tmr  <= Button1_Dn_Tmr + uSec_Tick;
136
        if( and_reduce(Button1_Dn_Tmr) = '1' )then
137
          Button1_Dn_Tmr<= Button1_Dn_Tmr;
138
          Button1_Dn    <= '1';
139
        end if;
140
      end if;
141
 
142
      Button1_Up_Tmr    <= (others => '0');
143
      Button1_Up        <= '0';
144
      if( Button1_In_q = not Button_Level )then
145
        Button1_Up_Tmr  <= Button1_Up_Tmr + uSec_Tick;
146
        if( and_reduce(Button1_Up_Tmr) = '1' )then
147
          Button1_Up_Tmr<= Button1_Up_Tmr;
148
          Button1_Up    <= '1';
149
        end if;
150
      end if;
151
 
152
      if( Button1_Dn = '1' )then
153
        Button1_State   <= '1';
154
      elsif( Button1_Up = '1' )then
155
        Button1_State   <= '0';
156
      end if;
157
 
158
      Button1_State_q   <= Button1_State;
159
      Button1_Int       <= Button1_State xor Button1_State_q;
160
 
161
    end if;
162
  end process;
163
 
164
  Button2_trap: process( Clock, Reset )
165
  begin
166
    if( Reset = Reset_Level )then
167
      Button2_SR         <= (others => '0');
168
 
169
      Button2_Dn_Tmr     <= (others => '0');
170
      Button2_Dn         <= '0';
171
 
172
      Button2_Up_Tmr     <= (others => '0');
173
      Button2_Up         <= '0';
174
 
175
      Button2_State      <= '0';
176
      Button2_State_q    <= '0';
177
 
178
      Button2_Int        <= '0';
179
    elsif( rising_edge(Clock) )then
180
      Button2_SR        <= Button2_SR(1 downto 0) & Button2_In;
181
 
182
      Button2_Dn_Tmr    <= (others => '0');
183
      Button2_Dn        <= '0';
184
      if( Button2_In_q = Button_Level )then
185
        Button2_Dn_Tmr  <= Button2_Dn_Tmr + uSec_Tick;
186
        if( and_reduce(Button2_Dn_Tmr) = '1' )then
187
          Button2_Dn_Tmr<= Button2_Dn_Tmr;
188
          Button2_Dn    <= '1';
189
        end if;
190
      end if;
191
 
192
      Button2_Up_Tmr    <= (others => '0');
193
      Button2_Up        <= '0';
194
      if( Button2_In_q = not Button_Level )then
195
        Button2_Up_Tmr  <= Button2_Up_Tmr + uSec_Tick;
196
        if( and_reduce(Button2_Up_Tmr) = '1' )then
197
          Button2_Up_Tmr<= Button2_Up_Tmr;
198
          Button2_Up    <= '1';
199
        end if;
200
      end if;
201
 
202
      if( Button2_Dn = '1' )then
203
        Button2_State   <= '1';
204
      elsif( Button2_Up = '1' )then
205
        Button2_State   <= '0';
206
      end if;
207
 
208
      Button2_State_q   <= Button2_State;
209
      Button2_Int       <= Button2_State xor Button2_State_q;
210
 
211
    end if;
212
  end process;
213
 
214
end architecture;

powered by: WebSVN 2.1.0

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