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 294

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 224 jshamlet
-- Seth Henry      04/16/20 Modified to use Open8 bus record
37 173 jshamlet
 
38
library ieee;
39 191 jshamlet
  use ieee.std_logic_1164.all;
40
  use ieee.std_logic_unsigned.all;
41
  use ieee.std_logic_arith.all;
42
  use ieee.std_logic_misc.all;
43 173 jshamlet
 
44
library work;
45
  use work.open8_pkg.all;
46
 
47
entity o8_btn_int is
48
generic(
49 217 jshamlet
  Num_Buttons                : integer range 1 to 8 := 8;
50
  Button_Level               : std_logic := '0';
51 224 jshamlet
  Address                    : ADDRESS_TYPE := x"0000"
52 173 jshamlet
);
53
port(
54 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
55 217 jshamlet
  Rd_Data                    : out DATA_TYPE;
56
  Interrupt                  : out std_logic;
57 173 jshamlet
  --
58 217 jshamlet
  Button_In                  : in  DATA_TYPE := x"00"
59 173 jshamlet
);
60
end entity;
61
 
62
architecture behave of o8_btn_int is
63
 
64 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
65
  alias Reset                is Open8_Bus.Reset;
66
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
67
 
68 217 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 0) := Address;
69 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 0);
70 244 jshamlet
  signal Addr_Match          : std_logic := '0';
71 173 jshamlet
 
72 244 jshamlet
  signal Rd_En_d             : std_logic := '0';
73
  signal Rd_En_q             : std_logic := '0';
74
 
75 217 jshamlet
  constant MSEC_DELAY        : std_logic_vector(9 downto 0) :=
76
                                conv_std_logic_vector(1000,10);
77 173 jshamlet
 
78 217 jshamlet
  signal mSec_Timer          : std_logic_vector(9 downto 0) := (others => '0');
79
  signal mSec_Tick           : std_logic := '0';
80 173 jshamlet
 
81 217 jshamlet
  signal Button_Pressed      : DATA_TYPE := x"00";
82
  signal Button_CoS          : DATA_TYPE := x"00";
83 173 jshamlet
 
84
begin
85
 
86 244 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
87
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
88 173 jshamlet
 
89
  io_reg: process( Clock, Reset )
90
  begin
91
    if( Reset = Reset_Level )then
92 244 jshamlet
      Rd_En_q                <= '0';
93 191 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
94
      Interrupt              <= '0';
95 173 jshamlet
    elsif( rising_edge( Clock ) )then
96 244 jshamlet
      Rd_En_q                <= Rd_En_d;
97 191 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
98 244 jshamlet
      if( Rd_En_q = '1' )then
99 191 jshamlet
        Rd_Data              <= Button_Pressed;
100 173 jshamlet
      end if;
101 191 jshamlet
      Interrupt              <= or_reduce(Button_CoS);
102 173 jshamlet
    end if;
103
  end process;
104
 
105 191 jshamlet
  mSec_proc: process( Clock, Reset )
106 173 jshamlet
  begin
107
    if( Reset = Reset_Level )then
108 191 jshamlet
      mSec_Timer             <= (others => '0');
109
      mSec_Tick              <= '0';
110 173 jshamlet
    elsif( rising_edge(Clock) )then
111 191 jshamlet
      mSec_Timer             <= mSec_Timer - uSec_Tick;
112
      mSec_Tick              <= '0';
113
      if( mSec_Timer = 0 )then
114
        mSec_Timer           <= MSEC_DELAY;
115
        mSec_Tick            <= '1';
116 173 jshamlet
      end if;
117
    end if;
118
  end process;
119
 
120 191 jshamlet
Create_Debouncers: for i in 0 to Num_Buttons - 1 generate
121 173 jshamlet
 
122 191 jshamlet
  U_BTN : entity work.button_db
123
  generic map(
124
    Button_Level             => Button_Level,
125
    Reset_Level              => Reset_Level
126
  )
127
  port map(
128
    Clock                    => Clock,
129
    Reset                    => Reset,
130
    mSec_Tick                => mSec_Tick,
131
    --
132
    Button_In                => Button_In(i),
133
    --
134
    Button_Pressed           => Button_Pressed(i),
135
    Button_CoS               => Button_CoS(i)
136
  );
137 173 jshamlet
 
138 191 jshamlet
end generate;
139 173 jshamlet
 
140
end architecture;

powered by: WebSVN 2.1.0

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