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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64/] [rtl/] [bench/] [soc/] [keyboard/] [Ps2Keyboard_sim.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_sim(rst_i, clk_i, cyc_i, stb_i, ack_o, we_i, adr_i, dat_i, dat_o, kclk, kd, irq_o);
35
parameter pIOAddress = 32'hFFDC0000;
36
parameter pAckStyle = 1'b0;
37
input rst_i;
38
input clk_i;
39
input cyc_i;
40
input stb_i;
41
output ack_o;
42
input we_i;
43
input [31: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
wire write_data;
52
wire cs_kbd = cyc_i & stb_i && adr_i[31:4]==pIOAddress[31:4];
53
assign ack_o = cs_kbd;
54
assign irq_o = rd;
55
reg read_data;
56
reg busy;
57
reg err;
58
reg [7:0] rx_data;
59
reg [19:0] cnt;
60
always @(posedge clk_i)
61
if (rst_i)
62
    cnt <= 20'd0;
63
else
64
    cnt <= cnt + 1;
65
 
66
always @(posedge clk_i)
67
if (rst_i) begin
68
    read_data <= 1'b0;
69
    rx_data <= 8'h00;
70
    busy <= 1'b0;
71
    err <= 1'b0;
72
end
73
else begin
74
read_data <= 0;
75
case(cnt)
76
300:
77
    begin
78
        read_data <= 1'b1;
79
        rx_data <= 8'h41;
80
    end
81
350:
82
    begin
83
        read_data <= 1'b1;
84
        rx_data <= 8'h42;
85
    end
86
400:
87
    begin
88
        read_data <= 1'b1;
89
        rx_data <= 8'h43;
90
    end
91
endcase
92
end
93
 
94
always @(posedge clk_i)
95
if (rst_i)
96
        rd <= 1'b0;
97
else begin
98
        if (read_data)
99
                rd <= 1'b1;
100
        else if (cs_kbd & ~we_i)
101
                rd <= 1'b0;
102
end
103
 
104
always @*
105
        if (cs_kbd & ~we_i) begin
106
                if (adr_i[0])
107
                        dat_o <= {rd,busy,5'b0,err};
108
                else
109
                        dat_o <= rx_data;
110
        end
111
        else
112
                dat_o <= 8'h00;
113
 
114
assign write_data = cs_kbd & we_i & ~adr_i[0];
115
 
116
endmodule

powered by: WebSVN 2.1.0

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