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

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [VHDL/] [keyboard.vhd] - Blame information for rev 99

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

Line No. Rev Author Line
1 99 davidgb
--===========================================================================--
2
--                                                                           --
3
--  keyboard.vhd - Synthesizable Interface to PS/2 Keyboard Module           --
4
--                                                                           --
5
--===========================================================================--
6 19 dilbert57
--
7 99 davidgb
--  File name      : keyboard.vhd
8
--
9
--  Entity name    : keyboard
10 19 dilbert57
--
11 99 davidgb
--  Purpose        : Implements a CPU interface to John Clayton's PS/2 Keyboard
12
--                  
13
--  Dependencies   : ieee.std_logic_1164
14
--                   ieee.std_logic_arith
15
--                   ieee.std_logic_unsigned
16
--                   ieee.numeric_std
17
--                   unisim.vcomponents
18
--
19
--  Uses           : ps2_keyboard_interface
20
--
21
--  Author         : John E. Kent
22
--
23
--  Email          : dilbert57@opencores.org      
24
--
25
--  Web            : http://opencores.org/project,system09
26
--
27
--  Registers      :
28
--
29
--  IO address + 0 read - Status Register
30
--
31
--      Bit[0] - RX Data Ready
32
--      Bit[1] - TX Data Empty
33
--      Bit[2] - Extended
34
--      Bit[3] - Released
35
--      Bit[4] - Shift On
36
--      Bit[5] - Error (no keyboard acknowledge received)
37
--      Bit[6] - TX Interrupt Flag
38
--      Bit[7] - RX Interrupt Flag
39
--
40
--  IO address + 0 write - Control Register
41
--
42
--      Bit[0] - Undefined
43
--      Bit[1] - Undefined
44
--      Bit[2] - Undefined
45
--      Bit[3] - Undefined
46
--      Bit[4] - Undefined
47
--      Bit[5] - Undefined
48
--      Bit[6] - TX Interrupt Enable
49
--      Bit[7] - RX Interrupt Enable
50
--
51
--  IO address + 1 read - Receive Data Register
52
--
53
--  IO address + 1 write - Transmit Data Register
54
--
55
--  Copyright (C) 2004 - 2010 John Kent
56
--
57
--  This program is free software: you can redistribute it and/or modify
58
--  it under the terms of the GNU General Public License as published by
59
--  the Free Software Foundation, either version 3 of the License, or
60
--  (at your option) any later version.
61
--
62
--  This program is distributed in the hope that it will be useful,
63
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
64
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
65
--  GNU General Public License for more details.
66
--
67
--  You should have received a copy of the GNU General Public License
68
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
69
--
70
--===========================================================================--
71
--                                                                           --
72
--                              Revision  History                            --
73
--                                                                           --
74
--===========================================================================--
75
--
76
-- Version  Author     Date               Description
77
-- 0.1      John Kent  2nd April 2004     Interface to John Clayton's PS2 keyboard
78
-- 0.2      John Kent  7th Februaury 2007 Added Generics for Keyboard Timing
79
-- 0.3      John Kent  30th May 2010      Updated Header, added unisim library
80
-- 0.4      John Kent  17th June 2010     Cleaned up signal names, 
81
--                                        added TX interrupt enable
82
--                                        Modified assignment of status register
83
--                                        Revised hanshake control and input registers
84
--                                        
85 19 dilbert57
 
86
library ieee;
87
   use ieee.std_logic_1164.all;
88 99 davidgb
   use ieee.std_logic_arith.all;
89
   use ieee.std_logic_unsigned.all;
90 19 dilbert57
   use ieee.numeric_std.all;
91 99 davidgb
library unisim;
92
   use unisim.vcomponents.all;
93 19 dilbert57
 
94
entity keyboard is
95
  generic (
96 99 davidgb
  KBD_CLK_FREQ : integer
97 19 dilbert57
  );
98
 
99 99 davidgb
  port(
100
  --
101
  -- CPU Interface Signals
102
  --
103 19 dilbert57
  clk             : in    std_logic;
104
  rst             : in    std_logic;
105
  cs              : in    std_logic;
106 99 davidgb
  addr            : in    std_logic;
107 19 dilbert57
  rw              : in    std_logic;
108
  data_in         : in    std_logic_vector(7 downto 0);
109
  data_out        : out   std_logic_vector(7 downto 0);
110 99 davidgb
  irq             : out   std_logic;
111
  --
112
  -- Keyboard Interface Signals
113
  --
114 19 dilbert57
  kbd_clk         : inout std_logic;
115
  kbd_data        : inout std_logic
116
  );
117
end keyboard;
118
 
119
architecture rtl of keyboard is
120
 
121 99 davidgb
constant CLK_FREQ_MHZ : integer := KBD_CLK_FREQ / 1000000;
122 19 dilbert57
 
123 99 davidgb
signal kbd_status     : std_logic_vector(7 downto 0);
124
signal kbd_control    : std_logic_vector(7 downto 0);
125
signal kbd_rx_data    : std_logic_vector(7 downto 0);
126 19 dilbert57
signal kbd_tx_data    : std_logic_vector(7 downto 0);
127
signal kbd_read       : std_logic;
128
signal kbd_write      : std_logic;
129 99 davidgb
signal kbd_data_ready : std_logic; --  => kbd_status(0)
130
signal kbd_data_empty : std_logic; --  => kbd_status(1)
131
signal kbd_extended   : std_logic; --  => kbd_status(2)
132
signal kbd_released   : std_logic; --  => kbd_status(3)
133
signal kbd_shift_on   : std_logic; --  => kbd_status(4)
134
signal kbd_error      : std_logic; --  => kbd_status(5) (No receive acknowledge)
135 19 dilbert57
 
136 99 davidgb
component ps2_keyboard
137 19 dilbert57
  generic (
138 99 davidgb
  CLK_FREQ_MHZ    : integer := CLK_FREQ_MHZ
139 19 dilbert57
  );
140
 
141
  port(
142
  clk             : in    std_logic;
143
  reset           : in    std_logic;
144 99 davidgb
  rx_data         : out   std_logic_vector(7 downto 0);
145
  rx_read         : in    std_logic;
146
  rx_data_ready   : out   std_logic;
147 19 dilbert57
  rx_extended     : out   std_logic;
148
  rx_released     : out   std_logic;
149 99 davidgb
  rx_shift_on     : out   std_logic;
150 19 dilbert57
  tx_data         : in    std_logic_vector(7 downto 0);
151
  tx_write        : in    std_logic;
152 99 davidgb
  tx_data_empty   : out   std_logic;
153
  tx_error        : out   std_logic;
154
  ps2_clk         : inout std_logic;
155
  ps2_data        : inout std_logic
156 19 dilbert57
  );
157
end component;
158
 
159
begin
160
 
161 99 davidgb
my_ps2_keyboard : ps2_keyboard
162 19 dilbert57
  generic map (
163 99 davidgb
  CLK_FREQ_MHZ   => CLK_FREQ_MHz
164 19 dilbert57
  )
165
 
166
  port map(
167
  clk             => clk,
168
  reset           => rst,
169 99 davidgb
  rx_data         => kbd_rx_data,
170 19 dilbert57
  rx_read         => kbd_read,
171 99 davidgb
  rx_data_ready   => kbd_data_ready,
172
  rx_extended     => kbd_extended,
173
  rx_released     => kbd_released,
174
  rx_shift_on     => kbd_shift_on,
175 19 dilbert57
  tx_data         => kbd_tx_data,
176
  tx_write        => kbd_write,
177 99 davidgb
  tx_data_empty   => kbd_data_empty,
178
  tx_error        => kbd_error,
179
  ps2_clk         => kbd_clk,
180
  ps2_data        => kbd_data
181 19 dilbert57
  );
182 99 davidgb
 
183
  --
184
  -- Keyboard Read strobe
185
  --
186
  keyboard_read : process( clk, rst, cs, rw, kbd_data_ready  )
187
  begin
188
    if rst = '1' then
189
      kbd_read <= '0';
190
    elsif( clk'event and clk='0' ) then
191
      if( cs = '1' and addr = '1' and rw = '1' ) then
192
        kbd_read <= '1';
193
      elsif kbd_data_ready = '1' then
194
        kbd_read <= '0';
195
      end if;
196
    end if;
197
  end process;
198
 
199
  --
200
  -- Keyboard Write strobe
201
  --
202
  keyboard_write : process( clk, rst, cs, rw, addr,
203
                                                                         kbd_write, kbd_data_empty )
204
  begin
205
    if rst = '1' then
206
                kbd_write   <= '0';
207
    elsif( clk'event and clk='0' ) then
208
                if( cs = '1' and addr = '1' and rw = '0' ) then
209
         kbd_write <= '1';
210
      elsif kbd_data_empty = '1' then
211
         kbd_write <= '0';
212
      end if;
213
    end if;
214
  end process;
215 19 dilbert57
 
216 99 davidgb
  --
217
  -- Keyboard register input
218
  --
219
  keyboard_in : process( clk, rst, cs, rw, addr, data_in, kbd_rx_data )
220
  begin
221
    if rst = '1' then
222
                kbd_control <= (others => '0');
223
      kbd_tx_data <= (others => '0');
224
    elsif( clk'event and clk='0' ) then
225
                if( cs = '1' and rw = '0' ) then
226
         if addr = '0' then
227
            kbd_control <= data_in;
228
         else
229
            kbd_tx_data <= data_in;
230
         end if;
231
      end if;
232
    end if;
233
  end process;
234 19 dilbert57
 
235 99 davidgb
  --
236
  -- Keyboard register output
237
  --
238
  keyboard_out : process( addr, kbd_rx_data, kbd_status )
239
  begin
240
    if( addr = '0' ) then
241
      data_out <= kbd_status;
242
    else
243
      data_out <= kbd_rx_data;
244
    end if;
245
  end process;
246
 
247
  --
248
  -- Assign Keyboard Status bits
249
  --
250
  keyboard_status : process( kbd_data_ready, kbd_data_empty,
251
                             kbd_extended, kbd_released, kbd_shift_on, kbd_error,
252
                             kbd_control)
253
  begin
254
    kbd_status(0) <= kbd_data_ready;
255
    kbd_status(1) <= kbd_data_empty;
256
    kbd_status(2) <= kbd_extended;
257
    kbd_status(3) <= kbd_released;
258
    kbd_status(4) <= kbd_shift_on;
259
    kbd_status(5) <= kbd_error;
260
    kbd_status(6) <= kbd_control(6) and kbd_data_empty; -- TX Interrupt Flag
261
    kbd_status(7) <= kbd_control(7) and kbd_data_ready; -- RX Interrupt Flag
262
    irq           <= kbd_status(7) or kbd_status(6);
263
  end process;
264
 
265 19 dilbert57
end rtl;
266
 

powered by: WebSVN 2.1.0

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