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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64/] [rtl/] [bench/] [soc/] [keyboard/] [Ps2Keyboard.v] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//      Ps2Keyboard.v - PS2 compatible keyboard interface
4
//
5
//      2015 Robert Finch
6
//      robfinch<remove>@finitron.ca
7
//
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//                                                                          
22
//      Reg
23
//      0        keyboard transmit/receive register
24
//      1       status reg.             itk xxxx p
25
//              i = interrupt status
26
//              t = transmit complete
27
//              k = transmit acknowledge receipt (from keyboard)
28
//              p = parity error
29
//              A write to the status register clears the transmitter
30
//              state
31
//
32
// ============================================================================
33
//
34
module Ps2Keyboard(rst_i, clk_i, cs_i, cyc_i, stb_i, ack_o, we_i, adr_i, dat_i, dat_o, kclk, kd, irq_o);
35
parameter pAckStyle = 1'b0;
36
input rst_i;
37
input clk_i;
38
input cs_i;
39
input cyc_i;
40
input stb_i;
41
output ack_o;
42
input we_i;
43
input [3:0] adr_i;
44
input [7:0] dat_i;
45
output reg [7:0] dat_o;
46
inout tri kclk;
47
inout tri kd;
48
output irq_o;
49
 
50
reg rd;
51
reg [3:0] cd;
52
wire busy;
53
wire err;
54
wire read_data;
55
wire write_data;
56
wire [7:0] rx_data;
57
assign ack_o = cs_i & cyc_i & stb_i;
58
assign irq_o = rd;
59
 
60
Ps2Interface u1
61
(
62
        .clk(clk_i),
63
        .rst(rst_i),
64
        .ps2_clk(kclk),
65
        .ps2_data(kd),
66
        .tx_data(dat_i),
67
        .write_data(write_data),
68
        .rx_data(rx_data),
69
        .read_data(read_data),
70
        .busy(busy),
71
        .err(err)
72
);
73
 
74
always @(posedge clk_i)
75
if (rst_i) begin
76
        rd <= 1'b0;
77
end
78
else begin
79
    cd <= {cd[2:0],1'b0};
80
        if (read_data)
81
                rd <= 1'b1;
82
        else if (ack_o & ~we_i)
83
                cd[0] <= 1'b1;
84
        if (cd[3])
85
        rd <= 1'b0;
86
end
87
 
88
always @*
89
    if (adr_i[0])
90
        dat_o <= {rd,busy,5'b0,err};
91
    else
92
        dat_o <= rx_data;
93
 
94
assign write_data = ack_o & we_i & ~adr_i[0];
95
 
96
endmodule

powered by: WebSVN 2.1.0

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