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

Subversion Repositories bu_pacman

[/] [bu_pacman/] [tags/] [arelease/] [Sources/] [ps2/] [ps2_receive.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 soloist_hu
//////////////////////////////////////////////////////////////////////////////////
2
// Company: BU PACMAN TEAM
3
// Engineer: Huaxin Dai
4
// 
5
// Create Date:    21:02:09 11/14/2008 
6
// Design Name:          PS/2 Interface
7
// Module Name:    ps2_rcv 
8
// Project Name:   BU PACMAN
9
// Target Devices: Spartan3 XC3S1000
10
// Tool versions:  ISE 10.1
11
// Description:          PS/2 interface, data receiving part.
12
//
13
// Dependencies:   Nothing
14
//
15
// Revision: 
16
// Revision 0.01 - File Created
17
// Additional Comments: Currently the parity check and start/stop bit detection
18
//                                                              hasn't been done, will do it in later version.
19
//////////////////////////////////////////////////////////////////////////////////
20
module ps2_receive(
21
                                input in_clk,
22
                                input in_reset,
23
                                input in_ps2_clk,
24
                                input in_ps2_data,
25
                                output reg [7:0] out_data
26
                                );
27
 
28
reg [3:0] i;//Counter
29
reg [10:0] data_in;//keycode register, including start bit, keycode, parity bit and stop bit
30
reg flag_break;
31
reg [2:0] ps2_clkr;//a fifo to detect ps2 clk
32
 
33
wire ps2_clk_fallingedge = (ps2_clkr[2:1]==2'b10); //re-generate the falling edge
34
 
35
always @(posedge in_clk)
36
ps2_clkr <= {ps2_clkr[1:0], in_ps2_clk};                                 //Buffer the incoming PS/2 clock
37
 
38
always @(posedge in_clk)
39
        if(in_reset)                                                                                                            //Reset
40
                begin
41
                i <= 0;
42
                data_in <= 0;
43
                out_data <= 8'h00;
44
                end
45
        else
46
                if(ps2_clk_fallingedge)                                                         //Incoming clock falling edge, read data
47
                        begin
48
                                data_in[i] <= in_ps2_data;
49
                                if(i<10)                                                                                //If it's still in the middle of some word
50
                                        i <= i+1;
51
                                else                                                                                            //Word processing
52
                                        begin
53
                                        i <= 0;
54
                                        if(data_in[8:1]==8'hF0)                                 //If it's the break code
55
                                                begin
56
                                                        out_data <= 8'h00;                                              //Output an Idle
57
                                                        flag_break <= 1;                                        //Set the break flag
58
                                                end
59
                                        else if(flag_break == 1)                                //If the break flag is on, which means this is a keycode for break action
60
                                                begin
61
                                                        out_data <= 8'h00;                                              //Output an Idle
62
                                                        flag_break <= 0;                                 //Clear the break flag
63
                                                end
64
                                        else                                                                                    //If it's a make code
65
                                                out_data <= data_in[8:1];                               //Output the keycode
66
                                        end
67
                        end
68
endmodule

powered by: WebSVN 2.1.0

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