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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [processor/] [VHDL/] [ext_modules/] [ext_key_matrix/] [ext_key_matrix_beh.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jlechner
-----------------------------------------------------------------------
2
-- This file is part of SCARTS.
3
-- 
4
-- SCARTS is free software: you can redistribute it and/or modify
5
-- it under the terms of the GNU General Public License as published by
6
-- the Free Software Foundation, either version 3 of the License, or
7
-- (at your option) any later version.
8
-- 
9
-- SCARTS is distributed in the hope that it will be useful,
10
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
-- GNU General Public License for more details.
13
-- 
14
-- You should have received a copy of the GNU General Public License
15
-- along with SCARTS.  If not, see <http://www.gnu.org/licenses/>.
16
-----------------------------------------------------------------------
17
 
18
 
19
 
20
library ieee;
21
use ieee.std_logic_1164.all;
22
use ieee.numeric_std.all;
23
 
24
use work.scarts_pkg.all;
25
use work.ext_key_matrix_pkg.all;
26
use work.key_matrix_pkg.all;
27
 
28
architecture behaviour of ext_key_matrix is
29
 
30
subtype BYTE is std_logic_vector(7 downto 0);
31
type register_set is array (0 to 7) of BYTE;
32
 
33
constant STATUSREG_CUST : integer := 1;
34
constant CONFIGREG_CUST : integer := 3;
35
 
36
constant ZEROVALUE      : std_logic_vector(15 downto 0) := (others => '0');
37
 
38
constant KEYPRESSED_REG : integer := 4;
39
constant NOKEY : std_logic_vector(3 downto 0) := (others => '0');
40
 
41
type reg_type is record
42
  ifacereg  : register_set;
43
end record;
44
 
45
 
46
signal r_next : reg_type;
47
signal r : reg_type :=
48
  (
49
    ifacereg => (others => (others => '0'))
50
  );
51
 
52
signal rstint : std_ulogic;
53
signal currentKey    : std_logic_vector(3 downto 0);
54
signal lastKey : std_logic_vector(3 downto 0);
55
 
56
begin
57
 
58
  key_matrix_unit : key_matrix
59
    generic map
60
    (
61
      CLK_FREQ => CLK_FREQ,
62
      SCAN_TIME_INTERVAL => 100 ms,
63
      DEBOUNCE_TIMEOUT => 1 ms,
64
      SYNC_STAGES => 2,
65
      COLUMN_COUNT => 3,
66
      ROW_COUNT => 4
67
    )
68
    port map
69
    (
70
      sys_clk => clk,
71
      sys_res_n => exti.reset,
72
      columns => columns,
73
      rows => rows,
74
      key => currentKey
75
    );
76
 
77
 
78
  comb : process(r, exti, extsel)
79
  variable v : reg_type;
80
  begin
81
    v := r;
82
 
83
    --schreiben
84
    if ((extsel = '1') and (exti.write_en = '1')) then
85
      case exti.addr(4 downto 2) is
86
        when "000" =>
87
          if ((exti.byte_en(0) = '1') or (exti.byte_en(1) = '1')) then
88
            v.ifacereg(STATUSREG)(STA_INT) := '1';
89
            v.ifacereg(CONFIGREG)(CONF_INTA) :='0';
90
          else
91
            if ((exti.byte_en(2) = '1')) then
92
              v.ifacereg(2) := exti.data(23 downto 16);
93
            end if;
94
            if ((exti.byte_en(3) = '1')) then
95
              v.ifacereg(3) := exti.data(31 downto 24);
96
            end if;
97
          end if;
98
        when "001" =>
99
          if ((exti.byte_en(0) = '1')) then
100
            v.ifacereg(4) := exti.data(7 downto 0);
101
          end if;
102
          if ((exti.byte_en(1) = '1')) then
103
            v.ifacereg(5) := exti.data(15 downto 8);
104
          end if;
105
          if ((exti.byte_en(2) = '1')) then
106
            v.ifacereg(6) := exti.data(23 downto 16);
107
          end if;
108
          if ((exti.byte_en(3) = '1')) then
109
            v.ifacereg(7) := exti.data(31 downto 24);
110
          end if;
111
        when others =>
112
          null;
113
      end case;
114
    end if;
115
 
116
    --auslesen
117
    exto.data <= (others => '0');
118
    if ((extsel = '1') and (exti.write_en = '0')) then
119
      case exti.addr(4 downto 2) is
120
        when "000" =>
121
          exto.data <= r.ifacereg(3) & r.ifacereg(2) & r.ifacereg(1) & r.ifacereg(0);
122
        when "001" =>
123
          if (r.ifacereg(CONFIGREG)(CONF_ID) = '1') then
124
            exto.data <= MODULE_VER & MODULE_ID;
125
          else
126
            exto.data <= r.ifacereg(7) & r.ifacereg(6) & r.ifacereg(5) & r.ifacereg(4);
127
          end if;
128
        when others =>
129
          null;
130
      end case;
131
    end if;
132
 
133
 
134
    --berechnen der neuen status flags
135
    v.ifacereg(STATUSREG)(STA_LOOR) := r.ifacereg(CONFIGREG)(CONF_LOOW);
136
    v.ifacereg(STATUSREG)(STA_FSS) := '0';
137
    v.ifacereg(STATUSREG)(STA_RESH) := '0';
138
    v.ifacereg(STATUSREG)(STA_RESL) := '0';
139
    v.ifacereg(STATUSREG)(STA_BUSY) := '0';
140
    v.ifacereg(STATUSREG)(STA_ERR) := '0';
141
    v.ifacereg(STATUSREG)(STA_RDY) := '1';
142
 
143
    -- Output soll Defaultmassig eingeschalten sein
144
    v.ifacereg(CONFIGREG)(CONF_OUTD) := '1';
145
 
146
 
147
    --soft- und hard-reset vereinen
148
    rstint <= not RST_ACT;
149
    if exti.reset = RST_ACT or r.ifacereg(CONFIGREG)(CONF_SRES) = '1' then
150
      rstint <= RST_ACT;
151
    end if;
152
 
153
    -- Interrupt
154
    if r.ifacereg(CONFIGREG)(CONF_INTA) ='1' then
155
      v.ifacereg(STATUSREG)(STA_INT) := '0';
156
      v.ifacereg(CONFIGREG)(CONF_INTA) := '0';
157
    end if;
158
    exto.intreq <= r.ifacereg(STATUSREG)(STA_INT);
159
 
160
    --module specific part
161
    if lastKey = NOKEY and currentKey /= NOKEY then
162
      v.ifacereg(KEYPRESSED_REG) := (others => '0');
163
      v.ifacereg(KEYPRESSED_REG)(currentKey'high downto currentKey'low) := currentKey;
164
      v.ifacereg(STATUSREG)(STA_INT) := '1';
165
    end if;
166
 
167
    r_next <= v;
168
  end process;
169
 
170
  reg : process(clk)
171
  begin
172
    if rising_edge(clk) then
173
      if rstint = RST_ACT then
174
        r.ifacereg <= (others => (others => '0'));
175
        lastKey <= NOKEY;
176
      else
177
        r <= r_next;
178
        lastKey <= currentKey;
179
      end if;
180
    end if;
181
  end process;
182
 
183
end behaviour;

powered by: WebSVN 2.1.0

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