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_clk_ctrl.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tesla
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  ps2_host_clk_ctrl.v                                         ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Taking care of all interactions with ps2_clk 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
`include "ps2_host_defines.v"
42
 
43
module ps2_host_clk_ctrl(
44
  input  wire sys_clk,
45
  input  wire sys_rst,
46
  input  wire send_req,
47
  inout  wire ps2_clk,
48
  output wire ps2_clk_posedge,
49
  output wire ps2_clk_negedge
50
);
51
 
52
// Sample ps2_clk and detect rising and falling edge
53
reg [1:0] ps2_clk_samples;
54
always @(posedge sys_clk)
55
begin
56
  ps2_clk_samples <= (sys_rst) ? 2'b11 : {ps2_clk_samples[0], ps2_clk};
57
end
58
 
59
assign ps2_clk_posedge = (~ps2_clk_samples[1] &  ps2_clk_samples[0]);
60
assign ps2_clk_negedge = ( ps2_clk_samples[1] & ~ps2_clk_samples[0]);
61
 
62
// When send_req pulse arrives pull ps2_clk to zero for 100us
63
reg [`T_100_MICROSECONDS_SIZE - 1:0] inhibit_timer;
64
wire timer_is_zero = ~|inhibit_timer;
65
always @(posedge sys_clk)
66
begin
67
  if (sys_rst | (~send_req & timer_is_zero)) begin
68
    inhibit_timer <= 0;
69
  end
70
  else begin
71
    inhibit_timer <= (timer_is_zero) ? `T_100_MICROSECONDS : inhibit_timer - 1;
72
  end
73
end
74
 
75
assign ps2_clk = (timer_is_zero) ? 1'bz : 1'b0;
76
 
77
endmodule

powered by: WebSVN 2.1.0

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