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

Subversion Repositories System09

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

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

powered by: WebSVN 2.1.0

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