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 191

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

Line No. Rev Author Line
1 191 jshamlet
-- Copyright (c)2013, 2020 Jeremy Seth Henry
2 173 jshamlet
-- 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 191 jshamlet
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 173 jshamlet
--
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 191 jshamlet
  use ieee.std_logic_1164.all;
30
  use ieee.std_logic_unsigned.all;
31
  use ieee.std_logic_arith.all;
32
  use ieee.std_logic_misc.all;
33 173 jshamlet
 
34
library work;
35
  use work.open8_pkg.all;
36
 
37
entity o8_btn_int is
38
generic(
39 191 jshamlet
  Num_Buttons           : integer range 1 to 8 := 8;
40
  Button_Level          : std_logic := '0';
41
  Address               : ADDRESS_TYPE := x"0000";
42
  Reset_Level           : std_logic := '1'
43 173 jshamlet
);
44
port(
45 191 jshamlet
  Clock                 : in  std_logic := '0';
46
  Reset                 : in  std_logic := '0';
47
  uSec_Tick             : in  std_logic := '0';
48 173 jshamlet
  --
49 191 jshamlet
  Bus_Address           : in  ADDRESS_TYPE := x"0000";
50
  Rd_Enable             : in  std_logic := '0';
51 173 jshamlet
  Rd_Data               : out DATA_TYPE;
52
  Interrupt             : out std_logic;
53
  --
54 191 jshamlet
  Button_In             : in  DATA_TYPE := x"00"
55 173 jshamlet
);
56
end entity;
57
 
58
architecture behave of o8_btn_int is
59
 
60
  constant User_Addr    : std_logic_vector(15 downto 0) := Address;
61
  alias  Comp_Addr      is Bus_Address(15 downto 0);
62
  signal Addr_Match     : std_logic;
63
  signal Rd_En          : std_logic;
64
 
65 191 jshamlet
  constant MSEC_DELAY   : std_logic_vector(9 downto 0) :=
66
                           conv_std_logic_vector(1000,10);
67 173 jshamlet
 
68 191 jshamlet
  signal mSec_Timer     : std_logic_vector(9 downto 0);
69
  signal mSec_Tick      : std_logic;
70 173 jshamlet
 
71 191 jshamlet
  signal Button_Pressed : DATA_TYPE := x"00";
72
  signal Button_CoS     : DATA_TYPE := x"00";
73 173 jshamlet
 
74
begin
75
 
76 191 jshamlet
  Addr_Match                 <= Rd_Enable when Comp_Addr = User_Addr else '0';
77 173 jshamlet
 
78
  io_reg: process( Clock, Reset )
79
  begin
80
    if( Reset = Reset_Level )then
81 191 jshamlet
      Rd_En                  <= '0';
82
      Rd_Data                <= OPEN8_NULLBUS;
83
      Interrupt              <= '0';
84 173 jshamlet
    elsif( rising_edge( Clock ) )then
85 191 jshamlet
      Rd_En                  <= Addr_Match;
86
      Rd_Data                <= OPEN8_NULLBUS;
87 173 jshamlet
      if( Rd_En = '1' )then
88 191 jshamlet
        Rd_Data              <= Button_Pressed;
89 173 jshamlet
      end if;
90 191 jshamlet
      Interrupt              <= or_reduce(Button_CoS);
91 173 jshamlet
    end if;
92
  end process;
93
 
94 191 jshamlet
  mSec_proc: process( Clock, Reset )
95 173 jshamlet
  begin
96
    if( Reset = Reset_Level )then
97 191 jshamlet
      mSec_Timer             <= (others => '0');
98
      mSec_Tick              <= '0';
99 173 jshamlet
    elsif( rising_edge(Clock) )then
100 191 jshamlet
      mSec_Timer             <= mSec_Timer - uSec_Tick;
101
      mSec_Tick              <= '0';
102
      if( mSec_Timer = 0 )then
103
        mSec_Timer           <= MSEC_DELAY;
104
        mSec_Tick            <= '1';
105 173 jshamlet
      end if;
106
    end if;
107
  end process;
108
 
109 191 jshamlet
Create_Debouncers: for i in 0 to Num_Buttons - 1 generate
110 173 jshamlet
 
111 191 jshamlet
  U_BTN : entity work.button_db
112
  generic map(
113
    Button_Level             => Button_Level,
114
    Reset_Level              => Reset_Level
115
  )
116
  port map(
117
    Clock                    => Clock,
118
    Reset                    => Reset,
119
    mSec_Tick                => mSec_Tick,
120
    --
121
    Button_In                => Button_In(i),
122
    --
123
    Button_Pressed           => Button_Pressed(i),
124
    Button_CoS               => Button_CoS(i)
125
  );
126 173 jshamlet
 
127 191 jshamlet
end generate;
128 173 jshamlet
 
129
end architecture;

powered by: WebSVN 2.1.0

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