From 3f24079b118cd40f63112ca3dcff74d0f0e1964c Mon Sep 17 00:00:00 2001 From: lekernel Date: Thu, 12 Nov 2009 15:06:33 +0100 Subject: [PATCH] PS/2 cleanup --- boards/xilinx-ml401/rtl/setup.v | 2 +- boards/xilinx-ml401/rtl/system.v | 22 ++++----- boards/xilinx-ml401/synthesis/common.ucf | 13 ++--- cores/ps2/rtl/ps2.v | 61 ++++++++++-------------- software/include/hw/gpio.h | 6 +-- 5 files changed, 45 insertions(+), 59 deletions(-) diff --git a/boards/xilinx-ml401/rtl/setup.v b/boards/xilinx-ml401/rtl/setup.v index 6452b397..a58bdbc7 100644 --- a/boards/xilinx-ml401/rtl/setup.v +++ b/boards/xilinx-ml401/rtl/setup.v @@ -26,7 +26,7 @@ `define ENABLE_AC97 `define ENABLE_PFPU `define ENABLE_TMU -`define ENABLE_PS2_KEYBOARD +`define ENABLE_PS2 /* * System clock frequency in Hz. diff --git a/boards/xilinx-ml401/rtl/system.v b/boards/xilinx-ml401/rtl/system.v index 0b4ce9c7..60115326 100644 --- a/boards/xilinx-ml401/rtl/system.v +++ b/boards/xilinx-ml401/rtl/system.v @@ -94,8 +94,8 @@ module system( output ac97_sync, // PS2 - inout ps2_clk1, - inout ps2_data1 + input ps2_clk1, + input ps2_data1 ); //------------------------------------------------------------------ @@ -1005,22 +1005,22 @@ assign fml_tmuw_dw = 64'bx; //--------------------------------------------------------------------------- // PS2 Interface //--------------------------------------------------------------------------- -`ifdef ENABLE_PS2_KEYBOARD +`ifdef ENABLE_PS2 ps2 # ( .csr_addr(4'h7), .clk_freq(`CLOCK_FREQUENCY) ) ps2_keyboard ( - .sys_clk (sys_clk), - .sys_rst (sys_rst), + .sys_clk(sys_clk), + .sys_rst(sys_rst), - .csr_a (csr_a), - .csr_we (csr_we), - .csr_di (csr_dw), - .csr_do (csr_dr_ps2), + .csr_a(csr_a), + .csr_we(csr_we), + .csr_di(csr_dw), + .csr_do(csr_dr_ps2), - .irq (ps2_irq), + .irq(ps2_irq), - .ps2_clk (ps2_clk1), + .ps2_clk(ps2_clk1), .ps2_data(ps2_data1) ); `else diff --git a/boards/xilinx-ml401/synthesis/common.ucf b/boards/xilinx-ml401/synthesis/common.ucf index 27710797..48cd89f2 100644 --- a/boards/xilinx-ml401/synthesis/common.ucf +++ b/boards/xilinx-ml401/synthesis/common.ucf @@ -119,9 +119,6 @@ NET "sram_zz" DRIVE = 8; NET "uart_rxd" LOC = W2 | IOSTANDARD = LVCMOS33; NET "uart_txd" LOC = W1 | IOSTANDARD = LVCMOS33; -NET "uart_rxd" TIG; -NET "uart_txd" TIG; - # ==== Push buttons ==== NET "btn(0)" LOC = E7 | IOSTANDARD = LVCMOS25; # N NET "btn(1)" LOC = E9 | IOSTANDARD = LVCMOS25; # W @@ -324,12 +321,12 @@ NET "ace_clkin" TNM_NET = "ace_clkin"; TIMESPEC "TSace" = PERIOD "ace_clkin" 30 ns HIGH 50% INPUT_JITTER 1 ns; NET "ace_mpce_n" LOC = AD5 | IOSTANDARD = LVCMOS33 | SLEW = FAST | DRIVE = 8; -NET "ace_mpirq" LOC = AD4 | IOSTANDARD = LVCMOS33 | TIG | PULLDOWN; +NET "ace_mpirq" LOC = AD4 | IOSTANDARD = LVCMOS33 | PULLDOWN; # USB signals NET "usb_cs_n" LOC = AF10 | IOSTANDARD = LVCMOS33 | SLEW = FAST | DRIVE = 8; -NET "usb_hpi_reset_n" LOC = A7 | IOSTANDARD = LVCMOS25 | TIG; -NET "usb_hpi_int" LOC = V5 | IOSTANDARD = LVCMOS33 | TIG | PULLDOWN; +NET "usb_hpi_reset_n" LOC = A7 | IOSTANDARD = LVCMOS25; +NET "usb_hpi_int" LOC = V5 | IOSTANDARD = LVCMOS33 | PULLDOWN; # ==== AC97 ==== NET "ac97_clk" LOC = AE10 | IOSTANDARD = LVCMOS33; @@ -342,5 +339,5 @@ NET "ac97_clk" TNM_NET = "clkac97"; TIMESPEC "TSclkac97" = PERIOD "clkac97" 80 HIGH 50%; # PS2 signals -NET "ps2_clk1" LOC = D2 | SLEW = SLOW | DRIVE = 2 | TIG; -NET "ps2_data1" LOC = G9 | SLEW = SLOW | DRIVE = 2 | TIG; +NET "ps2_clk1" LOC = D2 | IOSTANDARD = LVCMOS25; +NET "ps2_data1" LOC = G9 | IOSTANDARD = LVCMOS25; diff --git a/cores/ps2/rtl/ps2.v b/cores/ps2/rtl/ps2.v index 38887247..b287e784 100644 --- a/cores/ps2/rtl/ps2.v +++ b/cores/ps2/rtl/ps2.v @@ -28,7 +28,7 @@ module ps2 #( input [31:0] csr_di, output reg [31:0] csr_do, - output irq, + output reg irq, input ps2_clk, input ps2_data @@ -41,17 +41,17 @@ wire csr_selected = csr_a[13:10] == csr_addr; // divisor //----------------------------------------------------------------- reg [9:0] enable_counter; -wire enable; -assign enable = ( enable_counter == 10'd0); +wire enable; +assign enable = (enable_counter == 10'd0); parameter divisor = clk_freq/12800/16; always @(posedge sys_clk) begin - if ( sys_rst ) + if(sys_rst) enable_counter <= divisor - 10'd1; else begin enable_counter <= enable_counter - 10'd1; - if (enable) + if(enable) enable_counter <= divisor - 10'd1; end end @@ -75,57 +75,46 @@ end // PS2 RX Logic //----------------------------------------------------------------- reg [7:0] kcode; -reg rx_irq; -reg rx_clk_data; +reg rx_clk_data; reg [5:0] rx_clk_count; reg [4:0] rx_bitcount; reg [10:0] rx_data; always @(posedge sys_clk) begin - if( sys_rst ) begin + if(sys_rst) begin rx_clk_data <= 1'd1; - rx_clk_count<= 5'd0; + rx_clk_count <= 5'd0; rx_bitcount <= 4'd0; - rx_data <= 11'b11111111111; - rx_irq <= 1'd0; - csr_do <= 32'd0; + rx_data <= 11'b11111111111; + irq <= 1'd0; + csr_do <= 32'd0; end else begin -rx_irq <= 1'b0; // IRQ ack - csr_do <= 32'd0; - if (csr_selected) begin -//rx_irq <= 1'b0; // IRQ ack -// if (csr_we) begin -// case(csr_a[1:0]) -// 2'b01: rx_irq <= 1'b0; // IRQ ack -// endcase -// end - case(csr_a[1:0]) - 2'b00: csr_do <= kcode; // PS2 code - endcase + irq <= 1'b0; + csr_do <= 32'd0; + if(csr_selected) begin + csr_do <= kcode; end - if (enable) begin - if ( rx_clk_data == ps2_clk_2 ) begin + if(enable) begin + if(rx_clk_data == ps2_clk_2) begin rx_clk_count <= rx_clk_count + 5'd1; end else begin rx_clk_count <= 5'd0; - rx_clk_data <= ps2_clk_2; + rx_clk_data <= ps2_clk_2; end - if ( rx_clk_data == 1'd0 && rx_clk_count == 5'd4 ) begin - rx_data <= {ps2_data_2, rx_data[10:1]}; + if(rx_clk_data == 1'd0 && rx_clk_count == 5'd4) begin + rx_data <= {ps2_data_2, rx_data[10:1]}; rx_bitcount <= rx_bitcount + 4'd1; - if ( rx_bitcount == 4'd10 ) begin - rx_irq <= 1'b1; - kcode <= rx_data[9:2]; + if(rx_bitcount == 4'd10) begin + irq <= 1'b1; + kcode <= rx_data[9:2]; end end - if ( rx_clk_count == 5'd16 ) begin + if(rx_clk_count == 5'd16) begin rx_bitcount <= 4'd0; - rx_data <= 11'b11111111111; + rx_data <= 11'b11111111111; end end end end -assign irq = rx_irq; - endmodule diff --git a/software/include/hw/gpio.h b/software/include/hw/gpio.h index 9e4bb889..6e801fba 100644 --- a/software/include/hw/gpio.h +++ b/software/include/hw/gpio.h @@ -1,16 +1,16 @@ /* * Milkymist VJ SoC (Software) * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */