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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [fpga/] [ps2/] [PS2Controller.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see .
17
 
18
module PS2Controller #(parameter clkf=50000000)
19
                      (input logic clk,
20
                       input logic reset,
21
                       // CPU port
22
                       input logic cs,
23
                       input logic data_m_access,
24
                       input logic data_m_wr_en,
25
                       output logic data_m_ack,
26
                       output logic [15:0] data_m_data_out,
27
                       input logic [15:0] data_m_data_in,
28
                       input logic [1:0] data_m_bytesel,
29
                       // Interrupt
30
                       output logic ps2_intr,
31
                       // PS/2 signals
32
                       inout ps2_clk,
33
                       inout ps2_dat);
34
 
35
wire do_read = data_m_access & cs & ~data_m_wr_en;
36
wire do_write = data_m_access & cs & data_m_wr_en;
37
 
38
wire [7:0] rx;
39
wire rx_valid;
40
wire [7:0] tx = data_m_data_in[7:0];
41
wire start_tx = do_write & data_m_bytesel[0];
42
wire tx_busy;
43
wire error;
44
wire empty;
45
wire full;
46
wire [7:0] fifo_rd_data;
47
wire fifo_wr_en = rx_valid & ~error & ~full;
48
 
49
wire fifo_rd_en = cs & data_m_wr_en & data_m_bytesel[1] & ~empty;
50
 
51
reg unread_error = 1'b0;
52
 
53
assign ps2_intr = fifo_wr_en;
54
 
55
Fifo    #(.data_width(8),
56
          .depth(8))
57
        Fifo(.rd_en(fifo_rd_en),
58
             .rd_data(fifo_rd_data),
59
             .wr_en(fifo_wr_en),
60
             .wr_data(rx),
61
             // verilator lint_off PINCONNECTEMPTY
62
             .nearly_full(),
63
             // verilator lint_on PINCONNECTEMPTY
64
             .*);
65
 
66
wire [7:0] status = {5'b0, tx_busy, unread_error, ~empty};
67
wire [7:0] data = empty ? 8'b0 : fifo_rd_data;
68
 
69
always_ff @(posedge clk)
70
    data_m_data_out <= do_read ? {status, data} : 16'b0;
71
 
72
always_ff @(posedge clk)
73
    data_m_ack <= data_m_access & cs;
74
 
75
always_ff @(posedge clk or posedge reset)
76
    if (reset)
77
        unread_error <= 1'b0;
78
    else if (rx_valid & error)
79
        unread_error <= 1'b1;
80
    else if (do_read & data_m_bytesel[1])
81
        unread_error <= 1'b0;
82
 
83
PS2Host #(.clkf(clkf))
84
        PS2Host(.*);
85
 
86
endmodule

powered by: WebSVN 2.1.0

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