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

Subversion Repositories System09

[/] [System09/] [rev_86/] [rtl/] [VHDL/] [keyboard.vhd] - Blame information for rev 118

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

Line No. Rev Author Line
1 19 dilbert57
---------------------------------------------------------------------------------------
2
--
3
-- Author: John Kent
4
-- Date  : April 2, 2004
5
-- Interface to John Clayton's PS2 keyboard
6
--
7
---------------------------------------------------------------------------------------
8
--
9
-- 7th Februaury 2007 - John Kent
10
-- Added Generics for Keyboard Timing
11
--
12
 
13
library ieee;
14
   use ieee.std_logic_1164.all;
15
   use IEEE.STD_LOGIC_ARITH.ALL;
16
   use IEEE.STD_LOGIC_UNSIGNED.ALL;
17
   use ieee.numeric_std.all;
18
 
19
 
20
entity keyboard is
21
  generic (
22
  KBD_Clock_Frequency : integer
23
  );
24
 
25
  port(
26
  clk             : in    std_logic;
27
  rst             : in    std_logic;
28
  cs              : in    std_logic;
29
  rw              : in    std_logic;
30
  addr            : in    std_logic;
31
  data_in         : in    std_logic_vector(7 downto 0);
32
  data_out        : out   std_logic_vector(7 downto 0);
33
  irq             : out   std_logic;
34
  kbd_clk         : inout std_logic;
35
  kbd_data        : inout std_logic
36
  );
37
end keyboard;
38
 
39
architecture rtl of keyboard is
40
 
41
constant Clock_Frequency_MHz : integer := KBD_Clock_Frequency / 1000000;
42
 
43
signal kbd_stat       : std_logic_vector(7 downto 0);
44
signal kbd_ctrl       : std_logic_vector(7 downto 6);
45
signal kbd_ascii_code : std_logic_vector(7 downto 0);
46
signal kbd_tx_data    : std_logic_vector(7 downto 0);
47
signal kbd_read       : std_logic;
48
signal kbd_write      : std_logic;
49
signal kbd_write_ack  : std_logic;
50
 
51
component ps2_keyboard_interface
52
  generic (
53
  Frequency_MHz    : integer := Clock_Frequency_MHz
54
  );
55
 
56
  port(
57
  clk             : in    std_logic;
58
  reset           : in    std_logic;
59
  ps2_clk         : inout std_logic;
60
  ps2_data        : inout std_logic;
61
  rx_extended     : out   std_logic;
62
  rx_released     : out   std_logic;
63
  rx_shift_key_on : out   std_logic;
64
--  rx_scan_code    : out   std_logic_vector(7 downto 0);
65
  rx_ascii        : out   std_logic_vector(7 downto 0);
66
  rx_data_ready   : out   std_logic;       -- rx_read_o
67
  rx_read         : in    std_logic;       -- rx_read_ack_i
68
  tx_data         : in    std_logic_vector(7 downto 0);
69
  tx_write        : in    std_logic;
70
  tx_write_ack    : out   std_logic;
71
  tx_error_no_keyboard_ack      : out  std_logic
72
  );
73
end component;
74
 
75
begin
76
 
77
my_ps2_keyboard_interface : ps2_keyboard_interface
78
  generic map (
79
  Frequency_MHz   => Clock_Frequency_MHz
80
  )
81
 
82
  port map(
83
  clk             => clk,
84
  reset           => rst,
85
  ps2_clk         => kbd_clk,
86
  ps2_data        => kbd_data,
87
  rx_extended     => kbd_stat(2),
88
  rx_released     => kbd_stat(3),
89
  rx_shift_key_on => kbd_stat(4),
90
  rx_ascii        => kbd_ascii_code,
91
  rx_data_ready   => kbd_stat(0),
92
  rx_read         => kbd_read,
93
  tx_data         => kbd_tx_data,
94
  tx_write        => kbd_write,
95
  tx_write_ack    => kbd_write_ack,
96
  tx_error_no_keyboard_ack      => kbd_stat(5)
97
  );
98
 
99
keyboard_strobe : process( clk, rst, cs, rw, kbd_stat  )
100
begin
101
        if( rst = '1' ) then
102
                kbd_read <= '0';
103
        elsif( clk'event and clk='0' ) then
104
                if( cs='1' and rw='1' and addr='1' ) then
105
                        kbd_read <= '1';
106
                elsif( kbd_stat(0)='1' ) then
107
                        kbd_read <= '0';
108
                else
109
                        kbd_read <= kbd_read;
110
                end if;
111
        end if;
112
end process;
113
 
114
--
115
-- read keyboard registers
116
--
117
keyboard_read : process( addr, kbd_ascii_code, kbd_stat )
118
begin
119
        if( addr = '1' ) then
120
                data_out <= kbd_ascii_code;
121
        else
122
                data_out <= kbd_stat;
123
   end if;
124
end process;
125
 
126
--
127
-- Write to keyboard register
128
--
129
keyboard_write : process( clk, rst, cs, rw, addr, data_in, kbd_tx_data,
130
                                                                         kbd_write, kbd_write_ack )
131
begin
132
        if(rst = '1' ) then
133
           kbd_ctrl   <= "00";
134
           kbd_tx_data <= "00000000";
135
                kbd_write  <= '0';
136
        elsif( clk'event and clk='0' ) then
137
                if( cs='1' and rw='0' ) then
138
                        if( addr='1' ) then
139
                                kbd_tx_data  <= data_in;
140
                                kbd_ctrl    <= kbd_ctrl;
141
                                kbd_write   <= '1';
142
                        else
143
                                kbd_tx_data  <= kbd_tx_data;
144
                                kbd_ctrl    <= data_in(7 downto 6);
145
                                kbd_write   <= kbd_write;
146
                        end if;
147
                elsif( kbd_write_ack='1' ) then
148
                        kbd_write <= '0';
149
                else
150
                        kbd_write <= kbd_write;
151
                end if;
152
                kbd_stat(1) <= not kbd_write;
153
        end if;
154
end process;
155
 
156
keyboard_interrupt : process( kbd_ctrl, kbd_stat )
157
begin
158
        kbd_stat(6)     <= kbd_ctrl(6);
159
        kbd_stat(7) <= kbd_ctrl(7) and kbd_stat(0);
160
        irq         <= kbd_stat(7);
161
end process;
162
end rtl;
163
 

powered by: WebSVN 2.1.0

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