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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_switch_if.vhd] - Blame information for rev 313

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

Line No. Rev Author Line
1 257 jshamlet
-- Copyright (c)2020 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
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_switch_if
25
-- Description:  Based on the Debounce_Enable bit, either detects and reports
26
--                when a user pushbutton is pressed with an interrupt or
27
--                simply makes the switch status available.
28
--
29
-- Register Map:
30
-- Offset  Bitfield Description                        Read/Write
31
--   0x00  AAAAAAAA Current Switch State                 (RW)
32
--
33
-- Revision History
34
-- Author          Date     Change
35
------------------ -------- ---------------------------------------------------
36
-- Seth Henry      01/22/20 Re-write of original with separate debouncer
37
-- Seth Henry      04/16/20 Modified to use Open8 bus record
38
 
39
library ieee;
40
  use ieee.std_logic_1164.all;
41
  use ieee.std_logic_unsigned.all;
42
  use ieee.std_logic_arith.all;
43
  use ieee.std_logic_misc.all;
44
 
45
library work;
46
  use work.open8_pkg.all;
47
 
48
entity o8_switch_if is
49
generic(
50
  Debounce_Enables           : DATA_TYPE := x"00";
51
  Switch_Levels              : DATA_TYPE := x"00";
52
  Address                    : ADDRESS_TYPE := x"0000"
53
);
54
port(
55
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
56
  Rd_Data                    : out DATA_TYPE;
57
  Interrupt                  : out std_logic;
58
  --
59
  Switch_In                  : in  DATA_TYPE := x"00"
60
);
61
end entity;
62
 
63
architecture behave of o8_switch_if is
64
 
65
  alias Clock                is Open8_Bus.Clock;
66
  alias Reset                is Open8_Bus.Reset;
67
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
68
 
69
  constant User_Addr         : std_logic_vector(15 downto 0) := Address;
70
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 0);
71
  signal Addr_Match          : std_logic := '0';
72
 
73
  signal Rd_En_d             : std_logic := '0';
74
  signal Rd_En_q             : std_logic := '0';
75
 
76
  constant MSEC_DELAY        : std_logic_vector(9 downto 0) :=
77
                                conv_std_logic_vector(1000,10);
78
 
79
  signal mSec_Timer          : std_logic_vector(9 downto 0) := (others => '0');
80
  signal mSec_Tick           : std_logic := '0';
81
 
82
  signal Button_Pressed      : DATA_TYPE := x"00";
83
  signal Button_CoS          : DATA_TYPE := x"00";
84
 
85
begin
86
 
87
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
88
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
89
 
90
  io_reg: process( Clock, Reset )
91
  begin
92
    if( Reset = Reset_Level )then
93
      Rd_En_q                <= '0';
94
      Rd_Data                <= OPEN8_NULLBUS;
95
      Interrupt              <= '0';
96
    elsif( rising_edge( Clock ) )then
97
      Rd_En_q                <= Rd_En_d;
98
      Rd_Data                <= OPEN8_NULLBUS;
99
      if( Rd_En_q = '1' )then
100
        Rd_Data              <= Button_Pressed;
101
      end if;
102
      Interrupt              <= or_reduce(Button_CoS);
103
    end if;
104
  end process;
105
 
106
  mSec_proc: process( Clock, Reset )
107
  begin
108
    if( Reset = Reset_Level )then
109
      mSec_Timer             <= (others => '0');
110
      mSec_Tick              <= '0';
111
    elsif( rising_edge(Clock) )then
112
      mSec_Timer             <= mSec_Timer - uSec_Tick;
113
      mSec_Tick              <= '0';
114
      if( mSec_Timer = 0 )then
115
        mSec_Timer           <= MSEC_DELAY;
116
        mSec_Tick            <= '1';
117
      end if;
118
    end if;
119
  end process;
120
 
121
Create_Debouncers: for i in 0 to 7 generate
122
 
123
Debouncer_Enabled: if( Debounce_Enables(i) = '1' )generate
124
 
125
  U_BTN : entity work.button_db
126
  generic map(
127
    Button_Level             => Switch_Levels(i),
128
    Reset_Level              => Reset_Level
129
  )
130
  port map(
131
    Clock                    => Clock,
132
    Reset                    => Reset,
133
    mSec_Tick                => mSec_Tick,
134
    --
135
    Button_In                => Switch_In(i),
136
    --
137
    Button_Pressed           => Button_Pressed(i),
138
    Button_CoS               => Button_CoS(i)
139
  );
140
 
141
end generate;
142
 
143
Debouncer_Disabled: if( Debounce_Enables(i) = '0' )generate
144
 
145
  Button_Pressed(i)          <= Switch_In(i);
146
  Button_CoS(i)              <= '0';
147
end generate;
148
 
149
end generate;
150
 
151
end architecture;

powered by: WebSVN 2.1.0

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