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 219

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

Line No. Rev Author Line
1 213 jshamlet
-- Copyright (c)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 213 jshamlet
--
28
-- Register Map:
29
-- Offset  Bitfield Description                        Read/Write
30
--   0x00  AAAAAAAA Current Button State                 (RW)
31
--
32
-- Revision History
33
-- Author          Date     Change
34
------------------ -------- ---------------------------------------------------
35
-- Seth Henry      01/22/20 Re-write of original with separate debouncer
36 173 jshamlet
 
37
library ieee;
38 191 jshamlet
  use ieee.std_logic_1164.all;
39
  use ieee.std_logic_unsigned.all;
40
  use ieee.std_logic_arith.all;
41
  use ieee.std_logic_misc.all;
42 173 jshamlet
 
43
library work;
44
  use work.open8_pkg.all;
45
 
46
entity o8_btn_int is
47
generic(
48 217 jshamlet
  Num_Buttons                : integer range 1 to 8 := 8;
49
  Button_Level               : std_logic := '0';
50
  Address                    : ADDRESS_TYPE := x"0000";
51
  Reset_Level                : std_logic := '1'
52 173 jshamlet
);
53
port(
54 217 jshamlet
  Clock                      : in  std_logic := '0';
55
  Reset                      : in  std_logic := '0';
56
  uSec_Tick                  : in  std_logic := '0';
57 173 jshamlet
  --
58 217 jshamlet
  Bus_Address                : in  ADDRESS_TYPE := x"0000";
59
  Rd_Enable                  : in  std_logic := '0';
60
  Rd_Data                    : out DATA_TYPE;
61
  Interrupt                  : out std_logic;
62 173 jshamlet
  --
63 217 jshamlet
  Button_In                  : in  DATA_TYPE := x"00"
64 173 jshamlet
);
65
end entity;
66
 
67
architecture behave of o8_btn_int is
68
 
69 217 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 0) := Address;
70
  alias  Comp_Addr           is Bus_Address(15 downto 0);
71
  signal Addr_Match          : std_logic  := '0';
72
  signal Rd_En               : std_logic  := '0';
73 173 jshamlet
 
74 217 jshamlet
  constant MSEC_DELAY        : std_logic_vector(9 downto 0) :=
75
                                conv_std_logic_vector(1000,10);
76 173 jshamlet
 
77 217 jshamlet
  signal mSec_Timer          : std_logic_vector(9 downto 0) := (others => '0');
78
  signal mSec_Tick           : std_logic := '0';
79 173 jshamlet
 
80 217 jshamlet
  signal Button_Pressed      : DATA_TYPE := x"00";
81
  signal Button_CoS          : DATA_TYPE := x"00";
82 173 jshamlet
 
83
begin
84
 
85 191 jshamlet
  Addr_Match                 <= Rd_Enable when Comp_Addr = User_Addr else '0';
86 173 jshamlet
 
87
  io_reg: process( Clock, Reset )
88
  begin
89
    if( Reset = Reset_Level )then
90 191 jshamlet
      Rd_En                  <= '0';
91
      Rd_Data                <= OPEN8_NULLBUS;
92
      Interrupt              <= '0';
93 173 jshamlet
    elsif( rising_edge( Clock ) )then
94 191 jshamlet
      Rd_En                  <= Addr_Match;
95
      Rd_Data                <= OPEN8_NULLBUS;
96 173 jshamlet
      if( Rd_En = '1' )then
97 191 jshamlet
        Rd_Data              <= Button_Pressed;
98 173 jshamlet
      end if;
99 191 jshamlet
      Interrupt              <= or_reduce(Button_CoS);
100 173 jshamlet
    end if;
101
  end process;
102
 
103 191 jshamlet
  mSec_proc: process( Clock, Reset )
104 173 jshamlet
  begin
105
    if( Reset = Reset_Level )then
106 191 jshamlet
      mSec_Timer             <= (others => '0');
107
      mSec_Tick              <= '0';
108 173 jshamlet
    elsif( rising_edge(Clock) )then
109 191 jshamlet
      mSec_Timer             <= mSec_Timer - uSec_Tick;
110
      mSec_Tick              <= '0';
111
      if( mSec_Timer = 0 )then
112
        mSec_Timer           <= MSEC_DELAY;
113
        mSec_Tick            <= '1';
114 173 jshamlet
      end if;
115
    end if;
116
  end process;
117
 
118 191 jshamlet
Create_Debouncers: for i in 0 to Num_Buttons - 1 generate
119 173 jshamlet
 
120 191 jshamlet
  U_BTN : entity work.button_db
121
  generic map(
122
    Button_Level             => Button_Level,
123
    Reset_Level              => Reset_Level
124
  )
125
  port map(
126
    Clock                    => Clock,
127
    Reset                    => Reset,
128
    mSec_Tick                => mSec_Tick,
129
    --
130
    Button_In                => Button_In(i),
131
    --
132
    Button_Pressed           => Button_Pressed(i),
133
    Button_CoS               => Button_CoS(i)
134
  );
135 173 jshamlet
 
136 191 jshamlet
end generate;
137 173 jshamlet
 
138
end architecture;

powered by: WebSVN 2.1.0

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