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

Subversion Repositories ps2_host_controller

[/] [ps2_host_controller/] [trunk/] [hdl/] [ps2_host_rx.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tesla
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  ps2_host_rx.v                                               ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Receiver part, gathering bits from the ps2_data line        ////
7
////                                                              ////
8
////  Author:                                                     ////
9
////      - Piotr Foltyn, piotr.foltyn@gmail.com                  ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2011 Author                                    ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
// synopsys translate_off
39
`include "timescale.v"
40
// synopsys translate_on
41
 
42
module ps2_host_rx(
43
  input  wire sys_clk,
44
  input  wire sys_rst,
45
  input  wire ps2_clk_negedge,
46
  input  wire ps2_data,
47 4 tesla
  output reg [7:0] rx_data,
48
  output reg ready,
49
  output reg error
50 2 tesla
);
51
 
52 4 tesla
// Read in 11 bit long frame.
53 2 tesla
reg [11:0] frame;
54
always @(posedge sys_clk)
55
begin
56
  if (sys_rst | ready) begin
57
    frame <= 1;
58
  end
59
  else begin
60
    frame <= (ps2_clk_negedge) ? {frame[10:0], ps2_data} : frame;
61
  end
62
end
63
 
64 4 tesla
// 12th bit marks end of frame.
65
always @(posedge sys_clk)
66
begin
67
  ready <= (sys_rst) ? 0 : frame[11];
68
end
69
 
70 2 tesla
// Return rx_data in most significant bit first order.
71 4 tesla
always @(posedge sys_clk)
72
begin
73
  if (sys_rst) begin
74
    rx_data <= 0;
75
  end
76
  else begin
77
    rx_data <= (frame[11]) ? {frame[2], frame[3], frame[4], frame[5],
78
                              frame[6], frame[7], frame[8], frame[9]} : rx_data;
79
  end
80
end
81 2 tesla
 
82
// Check that 1st bit is 0, odd parity bit is correct and last bit is 1.
83 4 tesla
always @(posedge sys_clk)
84
begin
85
  if (sys_rst) begin
86
    error <= 0;
87
  end
88
  else begin
89
    error <= (frame[11]) ? ~(~frame[10] & (~frame[1] == ^frame[9:2]) & frame[0]) : error;
90
  end
91
end
92 2 tesla
 
93
endmodule

powered by: WebSVN 2.1.0

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