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

Subversion Repositories ps2

[/] [ps2/] [tags/] [rel_9/] [rtl/] [verilog/] [ps2_keyboard.v] - Diff between revs 17 and 24

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 17 Rev 24
Line 129... Line 129...
  rx_read,             // rx_read_ack_i
  rx_read,             // rx_read_ack_i
  tx_data,
  tx_data,
  tx_write,
  tx_write,
  tx_write_ack_o,
  tx_write_ack_o,
  tx_error_no_keyboard_ack,
  tx_error_no_keyboard_ack,
  translate
  translate,
 
  devide_reg_i
  );
  );
 
 
// Parameters
// Parameters
 
 
 
 
// The timer value can be up to (2^bits) inclusive.
// The timer value can be up to (2^bits) inclusive.
parameter TIMER_60USEC_VALUE_PP = 2950; // Number of sys_clks for 60usec.
parameter TIMER_60USEC_VALUE_PP = 2950; // Number of sys_clks for 60usec.
parameter TIMER_60USEC_BITS_PP  = 12;   // Number of bits needed for timer
parameter TIMER_60USEC_BITS_PP  = 12;   // Number of bits needed for timer
parameter TIMER_5USEC_VALUE_PP = 186;   // Number of sys_clks for debounce
parameter TIMER_5USEC_VALUE_PP = 186;   // Number of sys_clks for debounce
parameter TIMER_5USEC_BITS_PP  = 8;     // Number of bits needed for timer
parameter TIMER_5USEC_BITS_PP  = 8;     // Number of bits needed for timer
Line 189... Line 191...
input tx_write;
input tx_write;
output tx_write_ack_o;
output tx_write_ack_o;
output tx_error_no_keyboard_ack;
output tx_error_no_keyboard_ack;
input  translate ;
input  translate ;
 
 
 
input [15:0] devide_reg_i;
 
 
reg rx_released;
reg rx_released;
reg [7:0] rx_scan_code;
reg [7:0] rx_scan_code;
reg rx_data_ready;
reg rx_data_ready;
reg tx_error_no_keyboard_ack;
reg tx_error_no_keyboard_ack;
 
 
Line 228... Line 232...
reg hold_released;    // Holds prior value, cleared at rx_output_strobe
reg hold_released;    // Holds prior value, cleared at rx_output_strobe
reg ps2_clk_s;        // Synchronous version of this input
reg ps2_clk_s;        // Synchronous version of this input
reg ps2_data_s;       // Synchronous version of this input
reg ps2_data_s;       // Synchronous version of this input
reg ps2_clk_hi_z;     // Without keyboard, high Z equals 1 due to pullups.
reg ps2_clk_hi_z;     // Without keyboard, high Z equals 1 due to pullups.
reg ps2_data_hi_z;    // Without keyboard, high Z equals 1 due to pullups.
reg ps2_data_hi_z;    // Without keyboard, high Z equals 1 due to pullups.
 
reg ps2_clk_ms;
 
reg ps2_data_ms;
 
 
 
 
 
reg [15:0] timer_5usec;
 
reg  timer_done;
 
 
 
 
 
 
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Module code
// Module code
 
 
assign ps2_clk_en_o_  = ps2_clk_hi_z  ;
assign ps2_clk_en_o_  = ps2_clk_hi_z  ;
Line 240... Line 252...
// Input "synchronizing" logic -- synchronizes the inputs to the state
// Input "synchronizing" logic -- synchronizes the inputs to the state
// machine clock, thus avoiding errors related to
// machine clock, thus avoiding errors related to
// spurious state machine transitions.
// spurious state machine transitions.
always @(posedge clk)
always @(posedge clk)
begin
begin
  ps2_clk_s <= ps2_clk_i;
  ps2_clk_ms <= ps2_clk_i;
  ps2_data_s <= ps2_data_i;
  ps2_data_ms <= ps2_data_i;
 
 
 
  ps2_clk_s <= ps2_clk_ms;
 
  ps2_data_s <= ps2_data_ms;
 
 
end
end
 
 
// State register
// State register
always @(posedge clk)
always @(posedge clk or posedge reset)
begin : m1_state_register
begin : m1_state_register
  if (reset) m1_state <= m1_rx_clk_h;
  if (reset) m1_state <= m1_rx_clk_h;
  else m1_state <= m1_next_state;
  else m1_state <= m1_next_state;
end
end
 
 
Line 395... Line 411...
    default : m1_next_state <= m1_rx_clk_h;
    default : m1_next_state <= m1_rx_clk_h;
  endcase
  endcase
end
end
 
 
// State register
// State register
always @(posedge clk)
always @(posedge clk or posedge reset)
begin : m2_state_register
begin : m2_state_register
  if (reset) m2_state <= m2_rx_data_ready_ack;
  if (reset) m2_state <= m2_rx_data_ready_ack;
  else m2_state <= m2_next_state;
  else m2_state <= m2_next_state;
end
end
 
 
Line 422... Line 438...
    default : m2_next_state <= m2_rx_data_ready_ack;
    default : m2_next_state <= m2_rx_data_ready_ack;
  endcase
  endcase
end
end
 
 
// This is the bit counter
// This is the bit counter
always @(posedge clk)
always @(posedge clk or posedge reset)
begin
begin
  if (   reset
  if ( reset) bit_count <= 0;
      || rx_shifting_done
  else if ( rx_shifting_done || (m1_state == m1_tx_wait_keyboard_ack)        // After tx is done.
      || (m1_state == m1_tx_wait_keyboard_ack)        // After tx is done.
 
      ) bit_count <= 0;  // normal reset
      ) bit_count <= 0;  // normal reset
  else if (timer_60usec_done
  else if (timer_60usec_done
           && (m1_state == m1_rx_clk_h)
           && (m1_state == m1_rx_clk_h)
           && (ps2_clk_s)
           && (ps2_clk_s)
      ) bit_count <= 0;  // rx watchdog timer reset
      ) bit_count <= 0;  // rx watchdog timer reset
Line 451... Line 466...
 
 
// This is the ODD parity bit for the transmitted word.
// This is the ODD parity bit for the transmitted word.
assign tx_parity_bit = ~^tx_data;
assign tx_parity_bit = ~^tx_data;
 
 
// This is the shift register
// This is the shift register
always @(posedge clk)
always @(posedge clk or posedge reset)
begin
begin
  if (reset) q <= 0;
  if (reset) q <= 0;
  else if (tx_write_ack_o) q <= {1'b1,tx_parity_bit,tx_data,1'b0};
  else if (tx_write_ack_o) q <= {1'b1,tx_parity_bit,tx_data,1'b0};
  else if ( (m1_state == m1_rx_falling_edge_marker)
  else if ( (m1_state == m1_rx_falling_edge_marker)
           ||(m1_state == m1_tx_rising_edge_marker) )
           ||(m1_state == m1_tx_rising_edge_marker) )
Line 464... Line 479...
 
 
// This is the 60usec timer counter
// This is the 60usec timer counter
always @(posedge clk)
always @(posedge clk)
begin
begin
  if (~enable_timer_60usec) timer_60usec_count <= 0;
  if (~enable_timer_60usec) timer_60usec_count <= 0;
  else if (~timer_60usec_done) timer_60usec_count <= timer_60usec_count + 1;
  else if ( timer_done && !timer_60usec_done)
 
         timer_60usec_count<= timer_60usec_count +1;
 
  end
 
assign timer_60usec_done = (timer_60usec_count == (TIMER_60USEC_VALUE_PP ));
 
 
 
 
 
 
 
always @(posedge clk or posedge reset)
 
if (reset) timer_5usec <= 1;
 
else if (!enable_timer_60usec) timer_5usec <= 1;
 
else if (timer_5usec == devide_reg_i)
 
 begin
 
   timer_5usec <= 1;
 
   timer_done  <= 1;
 
  end
 
else
 
  begin
 
    timer_5usec<= timer_5usec +1;
 
    timer_done  <= 0;
end
end
assign timer_60usec_done = (timer_60usec_count == (TIMER_60USEC_VALUE_PP - 1));
 
 
 
// This is the 5usec timer counter
// This is the 5usec timer counter
always @(posedge clk)
always @(posedge clk)
begin
begin
  if (~enable_timer_5usec) timer_5usec_count <= 0;
  if (~enable_timer_5usec) timer_5usec_count <= 0;
  else if (~timer_5usec_done) timer_5usec_count <= timer_5usec_count + 1;
  else if (~timer_5usec_done) timer_5usec_count <= timer_5usec_count + 1;
end
end
assign timer_5usec_done = (timer_5usec_count == TIMER_5USEC_VALUE_PP - 1);
assign timer_5usec_done = (timer_5usec_count == devide_reg_i -1);
 
 
 
 
// Create the signals which indicate special scan codes received.
// Create the signals which indicate special scan codes received.
// These are the "unlatched versions."
// These are the "unlatched versions."
assign released = (q[8:1] == `RELEASE_CODE) && rx_shifting_done && translate ;
assign released = (q[8:1] == `RELEASE_CODE) && rx_shifting_done && translate ;
 
 
// Store the special scan code status bits
// Store the special scan code status bits
// Not the final output, but an intermediate storage place,
// Not the final output, but an intermediate storage place,
// until the entire set of output data can be assembled.
// until the entire set of output data can be assembled.
always @(posedge clk)
always @(posedge clk or posedge reset)
begin
begin
  if (reset || rx_output_event)
  if (reset) hold_released <= 0;
 
  else if (rx_output_event)
  begin
  begin
    hold_released <= 0;
    hold_released <= 0;
  end
  end
  else
  else
  begin
  begin
    if (rx_shifting_done && released) hold_released <= 1;
    if (rx_shifting_done && released) hold_released <= 1;
  end
  end
end
end
 
 
// Output the special scan code flags, the scan code and the ascii
// Output the special scan code flags, the scan code and the ascii
always @(posedge clk)
always @(posedge clk or posedge reset)
begin
begin
  if (reset)
  if (reset)
  begin
  begin
    rx_released <= 0;
    rx_released <= 0;
    rx_scan_code <= 0;
    rx_scan_code <= 0;

powered by: WebSVN 2.1.0

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