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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fpga/] [mc-sim/] [src/] [kbd/] [kbd.v] - Blame information for rev 323

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 301 hellwig
//
2
// kbd.v -- PS/2 keyboard interface
3
//
4
 
5
 
6
`timescale 1ns/10ps
7
`default_nettype none
8
 
9
 
10
module kbd(clk, rst,
11
           stb, we, addr,
12
           data_in, data_out,
13
           ack, irq);
14
    input clk;
15
    input rst;
16
    input stb;
17
    input we;
18
    input addr;
19
    input [7:0] data_in;
20
    output [7:0] data_out;
21
    output ack;
22
    output irq;
23
 
24
  reg [39:0] kbd_data[0:255];             // space for 256 data requests
25
  reg [7:0] kbd_data_index;              // next location to read
26
  wire [39:0] next_full;         // 40 bits from kbd_data
27
  wire [31:0] next_time;         // 32 bits delta clock ticks
28
  wire [7:0] next_code;                  // 8 bits character code
29
  reg [31:0] counter;                    // delta tick counter
30
  wire next_rdy;                        // delta time expired
31
 
32
  reg [7:0] data;
33
  reg rdy;
34
  reg ien;
35
  reg [7:2] other_bits;
36
 
37
  initial begin
38
    $readmemh("kbd.dat", kbd_data);
39
  end
40
 
41
  assign next_full[39:0] = kbd_data[kbd_data_index];
42
  assign next_time[31:0] = next_full[39:8];
43
  assign next_code[7:0] = next_full[7:0];
44
 
45
  always @(posedge clk) begin
46
    if (rst) begin
47
      kbd_data_index <= 0;
48
      counter <= 0;
49
    end else begin
50
      if (counter == 0) begin
51
        counter <= next_time;
52
      end else
53
      if (counter == 1) begin
54
        kbd_data_index <= kbd_data_index + 1;
55
        counter <= counter - 1;
56
      end else begin
57
        if (counter != 32'hFFFFFFFF) begin
58
          counter <= counter - 1;
59
        end
60
      end
61
    end
62
  end
63
 
64
  assign next_rdy = (counter == 1) ? 1 : 0;
65
 
66
  always @(posedge clk) begin
67
    if (rst) begin
68
      data <= 8'h00;
69
      rdy <= 0;
70
      ien <= 0;
71
      other_bits <= 6'b000000;
72
    end else begin
73
      if (next_rdy) begin
74
        data <= next_code;
75
      end
76
      if (next_rdy == 1 ||
77
          (stb == 1 && we == 0 && addr == 1)) begin
78
        rdy <= next_rdy;
79
      end
80
      if (stb == 1 && we == 1 && addr == 0) begin
81
        rdy <= data_in[0];
82
        ien <= data_in[1];
83
        other_bits <= data_in[7:2];
84
      end
85
    end
86
  end
87
 
88
  assign data_out =
89
    (addr == 0) ? { other_bits[7:2], ien, rdy } : data[7:0];
90
  assign ack = stb;
91
  assign irq = ien & rdy;
92
 
93
endmodule

powered by: WebSVN 2.1.0

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