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 224

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 217 jshamlet
  signal Addr_Match          : std_logic  := '0';
71
  signal Rd_En               : std_logic  := '0';
72 173 jshamlet
 
73 217 jshamlet
  constant MSEC_DELAY        : std_logic_vector(9 downto 0) :=
74
                                conv_std_logic_vector(1000,10);
75 173 jshamlet
 
76 217 jshamlet
  signal mSec_Timer          : std_logic_vector(9 downto 0) := (others => '0');
77
  signal mSec_Tick           : std_logic := '0';
78 173 jshamlet
 
79 217 jshamlet
  signal Button_Pressed      : DATA_TYPE := x"00";
80
  signal Button_CoS          : DATA_TYPE := x"00";
81 173 jshamlet
 
82
begin
83
 
84 223 jshamlet
  Addr_Match                 <= Open8_Bus.Rd_En when Comp_Addr = User_Addr else
85
                                '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.