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

Subversion Repositories ps2

[/] [ps2/] [tags/] [rel_6/] [bench/] [verilog/] [ps2_test_bench.v] - Diff between revs 7 and 12

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

Rev 7 Rev 12
Line 41... Line 41...
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
//
// CVS Revision History
// CVS Revision History
//
//
// $Log: not supported by cvs2svn $
// $Log: not supported by cvs2svn $
 
// Revision 1.4  2002/02/20 16:35:34  mihad
 
// Little/big endian changes continued
 
//
// Revision 1.3  2002/02/20 15:20:02  mihad
// Revision 1.3  2002/02/20 15:20:02  mihad
// Little/big endian changes incorporated
// Little/big endian changes incorporated
//
//
// Revision 1.2  2002/02/18 18:08:31  mihad
// Revision 1.2  2002/02/18 18:08:31  mihad
// One bug fixed
// One bug fixed
Line 93... Line 96...
`define KBD_EKI             32'h01_00_00_00
`define KBD_EKI             32'h01_00_00_00
`define KBD_SYS             32'h04_00_00_00
`define KBD_SYS             32'h04_00_00_00
`define KBD_DMS             32'h20_00_00_00
`define KBD_DMS             32'h20_00_00_00
`define KBD_KCC             32'h40_00_00_00
`define KBD_KCC             32'h40_00_00_00
`define KBD_DISABLE_COMMAND 32'h10_00_00_00
`define KBD_DISABLE_COMMAND 32'h10_00_00_00
 
`define AUX_OBUF_FULL       8'h20               /* output buffer (from device) full */
 
`define AUX_INTERRUPT_ON    32'h02_000000       /* enable controller interrupts */
 
 
 
`ifdef PS2_AUX
 
`define AUX_ENABLE      32'ha8_000000       /* enable aux */
 
`define AUX_DISABLE         32'ha7_000000       /* disable aux */
 
`define AUX_MAGIC_WRITE 32'hd4_000000       /* value to send aux device data */
 
`define AUX_SET_SAMPLE  32'hf3_000000       /* set sample rate */
 
`define AUX_SET_RES     32'he8_000000       /* set resolution */
 
`define AUX_SET_SCALE21 32'he7_000000       /* set 2:1 scaling */
 
`define AUX_INTS_OFF    32'h65_000000       /* disable controller interrupts */
 
`define AUX_INTS_ON     32'h47_000000       /* enable controller interrupts */
 
`define AUX_ENABLE_DEV  32'hf4_000000       /* enable aux device */
 
`endif
 
 
module ps2_test_bench() ;
module ps2_test_bench() ;
 
 
parameter [31:0] MAX_SEQUENCE_LENGTH = 10 ;
parameter [31:0] MAX_SEQUENCE_LENGTH = 10 ;
wire kbd_clk_cable  ;
wire kbd_clk_cable  ;
wire kbd_data_cable ;
wire kbd_data_cable ;
 
 
pullup(kbd_clk_cable)  ;
pullup(kbd_clk_cable)  ;
pullup(kbd_data_cable) ;
pullup(kbd_data_cable) ;
 
 
 
`ifdef PS2_AUX
 
pullup(aux_clk_cable)  ;
 
pullup(aux_data_cable) ;
 
wire   wb_intb ;
 
reg    stop_mouse_tests ;
 
`endif
 
 
reg wb_clock ;
reg wb_clock ;
reg wb_reset ;
reg wb_reset ;
 
 
wire [7:0] received_char ;
wire [7:0] received_char ;
wire       char_valid ;
wire       char_valid ;
Line 120... Line 144...
    .kbd_data_io (kbd_data_cable),
    .kbd_data_io (kbd_data_cable),
    .last_char_received_o (received_char),
    .last_char_received_o (received_char),
    .char_valid_o (char_valid)
    .char_valid_o (char_valid)
) ;
) ;
 
 
 
`ifdef PS2_AUX
 
wire [7:0] aux_received_char ;
 
ps2_keyboard_model i_ps2_mouse_model
 
(
 
    .kbd_clk_io  (aux_clk_cable),
 
    .kbd_data_io (aux_data_cable),
 
    .last_char_received_o (aux_received_char),
 
    .char_valid_o (aux_char_valid)
 
) ;
 
`endif
 
 
reg ok ;
reg ok ;
reg error ;
reg error ;
 
 
integer watchdog_timer ;
integer watchdog_timer ;
reg     watchdog_reset ;
reg     watchdog_reset ;
Line 183... Line 218...
    @(posedge wb_clock) ;
    @(posedge wb_clock) ;
    #1 initialize_controler ;
    #1 initialize_controler ;
 
 
    test_scan_code_receiving ;
    test_scan_code_receiving ;
 
 
 
    `ifdef PS2_AUX
 
    fork
 
    begin
 
    `endif
    test_normal_scancodes ;
    test_normal_scancodes ;
 
 
    test_extended_scancodes ;
    test_extended_scancodes ;
 
 
    test_print_screen_and_pause_scancodes ;
    test_print_screen_and_pause_scancodes ;
 
    `ifdef PS2_AUX
 
    stop_mouse_tests = 1'b1 ;
 
    end
 
    begin
 
        stop_mouse_tests = 0 ;
 
        receive_mouse_movement ;
 
    end
 
    join
 
    `endif
 
 
    test_keyboard_inhibit ;
    test_keyboard_inhibit ;
 
 
    #400 $stop ;
    #400 $stop ;
end
end
Line 226... Line 274...
 
 
    .wb_int_o        (wb_int),
    .wb_int_o        (wb_int),
 
 
    .ps2_kbd_clk_io  (kbd_clk_cable),
    .ps2_kbd_clk_io  (kbd_clk_cable),
    .ps2_kbd_data_io (kbd_data_cable)
    .ps2_kbd_data_io (kbd_data_cable)
 
    `ifdef PS2_AUX
 
    ,
 
    .wb_intb_o(wb_intb),
 
 
 
    .ps2_aux_clk_io(aux_clk_cable),
 
    .ps2_aux_data_io(aux_data_cable)
 
    `endif
) ;
) ;
 
 
WB_MASTER_BEHAVIORAL i_wb_master
WB_MASTER_BEHAVIORAL i_wb_master
(
(
    .CLK_I    (wb_clock),
    .CLK_I    (wb_clock),
Line 267... Line 322...
    reg [7:0] data ;
    reg [7:0] data ;
    reg status ;
    reg status ;
begin:main
begin:main
 
 
    // simulate keyboard driver's behaviour 
    // simulate keyboard driver's behaviour 
 
    data   = `KBD_OBF ;
 
    status = 1 ;
 
    while ( data & `KBD_OBF )
 
    begin
    read_status_reg(data, status) ;
    read_status_reg(data, status) ;
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
            #1 disable main ;
 
 
    if ( data & `KBD_OBF )
    if ( data & `KBD_OBF )
 
        begin
        read_data_reg(data, status) ;
        read_data_reg(data, status) ;
 
            data = `KBD_OBF ;
 
        end
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
            #1 disable main ;
 
 
 
    end
 
 
    kbd_write(`KBD_CNTL_REG, `KBD_SELF_TEST, status) ;
    kbd_write(`KBD_CNTL_REG, `KBD_SELF_TEST, status) ;
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
        #1 disable main ;
 
 
    // command sent - wait for commands output to be ready
    // command sent - wait for commands output to be ready
    data = 0 ;
    data = 0 ;
    while( status && !( data & `KBD_OBF ) )
    while( !( data & `KBD_OBF ) )
 
    begin
        read_status_reg(data, status) ;
        read_status_reg(data, status) ;
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
            #1 disable main ;
 
    end
 
 
    read_data_reg( data, status ) ;
    read_data_reg( data, status ) ;
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
        #1 disable main ;
 
 
    if ( data !== 8'h55 )
    if ( data !== 8'h55 )
    begin
    begin
        $display("Error! Keyboard controler should respond to self test command with hard coded value 0x55! ") ;
        $display("Error! Keyboard controler should respond to self test command with hard coded value 0x55! ") ;
        #400 $stop ;
        #400 $stop ;
Line 305... Line 370...
 
 
    // perform self test 2
    // perform self test 2
    kbd_write(`KBD_CNTL_REG, `KBD_SELF_TEST2, status) ;
    kbd_write(`KBD_CNTL_REG, `KBD_SELF_TEST2, status) ;
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
        #1 disable main ;
 
 
    // command sent - wait for commands output to be ready
    // command sent - wait for commands output to be ready
    data = 0 ;
    data = 0 ;
    while( status && !( data & `KBD_OBF ) )
    while( status && !( data & `KBD_OBF ) )
        read_status_reg(data, status) ;
        read_status_reg(data, status) ;
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
        #1 disable main ;
 
 
    read_data_reg( data, status ) ;
    read_data_reg( data, status ) ;
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
        #1 disable main ;
 
 
    if ( data !== 8'h00 )
    if ( data !== 8'h00 )
    begin
    begin
        $display("Error! Keyboard controler should respond to self test command 2 with hard coded value 0x00! ") ;
        $display("Error! Keyboard controler should respond to self test command 2 with hard coded value 0x00! ") ;
        #400 $stop ;
        #400 $stop ;
    end
    end
 
 
    kbd_write(`KBD_CNTL_REG, `KBD_CNTL_ENABLE, status);
    kbd_write(`KBD_CNTL_REG, `KBD_CNTL_ENABLE, status);
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
        #1 disable main ;
 
 
    // send reset command to keyboard
    // send reset command to keyboard
    kbd_write(`KBD_DATA_REG, `KBD_RESET, status) ;
    kbd_write(`KBD_DATA_REG, `KBD_RESET, status) ;
 
 
    if ( status !== 1 )
    if ( status !== 1 )
        disable main ;
        #1 disable main ;
 
 
    fork
    fork
    begin
    begin
        // wait for keyboard to respond with acknowledge
        // wait for keyboard to respond with acknowledge
        data = 0 ;
        data = 0 ;
        while( status && !( data & `KBD_OBF ) )
        while( status && !( data & `KBD_OBF ) )
            read_status_reg(data, status) ;
            read_status_reg(data, status) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        read_data_reg( data, status ) ;
        read_data_reg( data, status ) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        if ( data !== `KBD_ACK )
        if ( data !== `KBD_ACK )
        begin
        begin
            $display("Error! Expected character from keyboard was 0x%h, actualy received 0x%h!", `KBD_ACK, data ) ;
            $display("Error! Expected character from keyboard was 0x%h, actualy received 0x%h!", `KBD_ACK, data ) ;
            #400 $stop ;
            #400 $stop ;
Line 364... Line 429...
        data = 0 ;
        data = 0 ;
        while( status && !( data & `KBD_OBF ) )
        while( status && !( data & `KBD_OBF ) )
            read_status_reg(data, status) ;
            read_status_reg(data, status) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        read_data_reg( data, status ) ;
        read_data_reg( data, status ) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        if ( data !== `KBD_POR )
        if ( data !== `KBD_POR )
        begin
        begin
            $display("Error! Expected character from keyboard was 0x%h, actualy received 0x%h!", `KBD_POR, data ) ;
            $display("Error! Expected character from keyboard was 0x%h, actualy received 0x%h!", `KBD_POR, data ) ;
            #400 $stop ;
            #400 $stop ;
Line 381... Line 446...
 
 
        // send disable command to keyboard
        // send disable command to keyboard
        kbd_write(`KBD_DATA_REG, `KBD_DISABLE, status) ;
        kbd_write(`KBD_DATA_REG, `KBD_DISABLE, status) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        // wait for keyboard to respond with acknowledge
        // wait for keyboard to respond with acknowledge
        data = 0 ;
        data = 0 ;
        while( status && !( data & `KBD_OBF ) )
        while( status && !( data & `KBD_OBF ) )
            read_status_reg(data, status) ;
            read_status_reg(data, status) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        read_data_reg( data, status ) ;
        read_data_reg( data, status ) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        if ( data !== `KBD_ACK )
        if ( data !== `KBD_ACK )
        begin
        begin
            $display("Error! Expected character from keyboard was 0x%h, actualy received 0x%h!", `KBD_ACK, data ) ;
            $display("Error! Expected character from keyboard was 0x%h, actualy received 0x%h!", `KBD_ACK, data ) ;
            #400 $stop ;
            #400 $stop ;
        end
        end
 
 
        kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, status);
        kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, status);
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC, status);
        kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC, status);
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        // send disable command to keyboard
        // send disable command to keyboard
        kbd_write(`KBD_DATA_REG, `KBD_ENABLE, status) ;
        kbd_write(`KBD_DATA_REG, `KBD_ENABLE, status) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        // wait for keyboard to respond with acknowledge
        // wait for keyboard to respond with acknowledge
        data = 0 ;
        data = 0 ;
        while( status && !( data & `KBD_OBF ) )
        while( status && !( data & `KBD_OBF ) )
            read_status_reg(data, status) ;
            read_status_reg(data, status) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        read_data_reg( data, status ) ;
        read_data_reg( data, status ) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        if ( data !== `KBD_ACK )
        if ( data !== `KBD_ACK )
        begin
        begin
            $display("Error! Expected character from keyboard was 0x%h, actualy received 0x%h!", `KBD_ACK, data ) ;
            $display("Error! Expected character from keyboard was 0x%h, actualy received 0x%h!", `KBD_ACK, data ) ;
            #400 $stop ;
            #400 $stop ;
        end
        end
 
 
        // now check if command byte is as expected
        // now check if command byte is as expected
        kbd_write(`KBD_CNTL_REG, `KBD_READ_MODE, status);
        kbd_write(`KBD_CNTL_REG, `KBD_READ_MODE, status);
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        data = 0 ;
        data = 0 ;
        while( status && !( data & `KBD_OBF ) )
        while( status && !( data & `KBD_OBF ) )
            read_status_reg(data, status) ;
            read_status_reg(data, status) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        read_data_reg(data, status) ;
        read_data_reg(data, status) ;
 
 
        if ( status !== 1 )
        if ( status !== 1 )
            disable main ;
            #1 disable main ;
 
 
        if ( ({data, 24'h0} & (`KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC)) !== (`KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC)  )
        if ( ({data, 24'h0} & (`KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC)) !== (`KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC)  )
        begin
        begin
            $display("Error! Read command byte returned wrong value!") ;
            $display("Error! Read command byte returned wrong value!") ;
            #400 $stop ;
            #400 $stop ;
Line 513... Line 578...
    end
    end
    join
    join
 
 
    watchdog_reset = !watchdog_reset ;
    watchdog_reset = !watchdog_reset ;
 
 
 
    `ifdef PS2_AUX
 
    kbd_write(`KBD_CNTL_REG, `AUX_ENABLE, status) ;
 
 
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    // simulate aux driver's behaviour
 
    data   = 1 ;
 
    status = 1 ;
 
 
 
    kbd_write(`KBD_CNTL_REG, `AUX_MAGIC_WRITE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    data = 1 ;
 
 
 
    kbd_write(`KBD_DATA_REG, `AUX_SET_SAMPLE, status) ;
 
 
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    @(aux_char_valid) ;
 
    if ( {aux_received_char, 24'h000000} !== `AUX_SET_SAMPLE)
 
    begin
 
        $display("Time %t ", $time) ;
 
        $display("PS2 mouse didn't receive expected character! Expected %h, actual %h !", `AUX_SET_SAMPLE, aux_received_char ) ;
 
    end
 
 
 
    data   = 1 ;
 
    status = 1 ;
 
 
 
    kbd_write(`KBD_CNTL_REG, `AUX_MAGIC_WRITE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    data = 1 ;
 
 
 
    kbd_write(`KBD_DATA_REG, `AUX_SET_RES, status) ;
 
 
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
 
 
    @(aux_char_valid) ;
 
    if ( {aux_received_char, 24'h000000} !== `AUX_SET_RES )
 
    begin
 
        $display("Time %t ", $time) ;
 
        $display("PS2 mouse didn't receive expected character! Expected %h, actual %h !", `AUX_SET_RES, aux_received_char ) ;
 
    end
 
 
 
    data   = 1 ;
 
    status = 1 ;
 
 
 
    kbd_write(`KBD_CNTL_REG, `AUX_MAGIC_WRITE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    data = 1 ;
 
 
 
    kbd_write(`KBD_DATA_REG, {8'd100, 24'h000000}, status) ;
 
 
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    @(aux_char_valid) ;
 
    if ( aux_received_char !== 8'd100 )
 
    begin
 
        $display("Time %t ", $time) ;
 
        $display("PS2 mouse didn't receive expected character! Expected %h, actual %h !", 100, aux_received_char ) ;
 
    end
 
 
 
    data   = 1 ;
 
    status = 1 ;
 
 
 
    kbd_write(`KBD_CNTL_REG, `AUX_MAGIC_WRITE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    data = 1 ;
 
 
 
    kbd_write(`KBD_DATA_REG, {8'd3, 24'h000000}, status) ;
 
 
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
 
 
    @(aux_char_valid) ;
 
    if ( aux_received_char !== 8'd3 )
 
    begin
 
        $display("Time %t ", $time) ;
 
        $display("PS2 mouse didn't receive expected character! Expected %h, actual %h !", 3, aux_received_char ) ;
 
    end
 
 
 
    data   = 1 ;
 
    status = 1 ;
 
 
 
    kbd_write(`KBD_CNTL_REG, `AUX_MAGIC_WRITE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    data = 1 ;
 
 
 
    kbd_write(`KBD_DATA_REG, `AUX_SET_SCALE21, status) ;
 
 
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    @(aux_char_valid) ;
 
    if ( {aux_received_char, 24'h000000} !== `AUX_SET_SCALE21)
 
    begin
 
        $display("Time %t ", $time) ;
 
        $display("PS2 mouse didn't receive expected character! Expected %h, actual %h !", `AUX_SET_SCALE21, aux_received_char ) ;
 
    end
 
 
 
    kbd_write(`KBD_CNTL_REG, `AUX_DISABLE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    kbd_write(`KBD_DATA_REG, `AUX_INTS_OFF, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    data = 1 ;
 
 
 
    kbd_write(`KBD_CNTL_REG, `AUX_ENABLE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    kbd_write(`KBD_CNTL_REG, `AUX_MAGIC_WRITE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    data = 1 ;
 
 
 
    kbd_write(`KBD_DATA_REG, `AUX_ENABLE_DEV, status) ;
 
 
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    @(aux_char_valid) ;
 
    if ( {aux_received_char, 24'h000000} !== `AUX_ENABLE_DEV)
 
    begin
 
        $display("Time %t ", $time) ;
 
        $display("PS2 mouse didn't receive expected character! Expected %h, actual %h !", `AUX_ENABLE_DEV, aux_received_char ) ;
 
    end
 
 
 
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    kbd_write(`KBD_DATA_REG, `AUX_INTS_ON, status) ;
 
    if ( status !== 1 )
 
        #1 disable main ;
 
 
 
    watchdog_reset = !watchdog_reset ;
 
    `endif
 
 
end
end
endtask // initialize_controler 
endtask // initialize_controler 
 
 
task read_data_reg ;
task read_data_reg ;
    output [7:0] return_byte_o ;
    output [7:0] return_byte_o ;
    output ok_o ;
    output ok_o ;
    reg `READ_STIM_TYPE    read_data ;
    reg `READ_STIM_TYPE    read_data ;
    reg `READ_RETURN_TYPE  read_status ;
    reg `READ_RETURN_TYPE  read_status ;
    reg `WB_TRANSFER_FLAGS flags ;
    reg `WB_TRANSFER_FLAGS flags ;
 
    reg in_use ;
 
begin:main
 
    if ( in_use === 1 )
begin
begin
 
        $display("Task read_data_reg re-entered! Time %t", $time) ;
 
        #1 disable main ;
 
    end
 
    else
 
        in_use = 1 ;
 
 
    ok_o = 1 ;
    ok_o = 1 ;
    flags`WB_TRANSFER_SIZE     = 1 ;
    flags`WB_TRANSFER_SIZE     = 1 ;
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
    flags`WB_TRANSFER_CAB      = 0 ;
    flags`WB_TRANSFER_CAB      = 0 ;
    flags`INIT_WAITS           = 0 ;
    flags`INIT_WAITS           = 0 ;
Line 546... Line 781...
        ok_o = 0 ;
        ok_o = 0 ;
    end
    end
    else
    else
        return_byte_o = read_status`READ_DATA ;
        return_byte_o = read_status`READ_DATA ;
 
 
 
    in_use = 0 ;
 
 
end
end
endtask //read_data_reg
endtask //read_data_reg
 
 
task read_status_reg ;
task read_status_reg ;
    output [7:0] return_byte_o ;
    output [7:0] return_byte_o ;
    output ok_o ;
    output ok_o ;
    reg `READ_STIM_TYPE    read_data ;
    reg `READ_STIM_TYPE    read_data ;
    reg `READ_RETURN_TYPE  read_status ;
    reg `READ_RETURN_TYPE  read_status ;
    reg `WB_TRANSFER_FLAGS flags ;
    reg `WB_TRANSFER_FLAGS flags ;
 
    reg in_use ;
 
begin:main
 
    if ( in_use === 1 )
begin
begin
 
        $display("Task read_status_reg re-entered! Time %t !", $time) ;
 
        #1 disable main ;
 
    end
 
    else
 
        in_use = 1 ;
 
 
    ok_o = 1 ;
    ok_o = 1 ;
    flags`WB_TRANSFER_SIZE     = 1 ;
    flags`WB_TRANSFER_SIZE     = 1 ;
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
    flags`WB_TRANSFER_AUTO_RTY = 0 ;
    flags`WB_TRANSFER_CAB      = 0 ;
    flags`WB_TRANSFER_CAB      = 0 ;
    flags`INIT_WAITS           = 0 ;
    flags`INIT_WAITS           = 0 ;
Line 579... Line 825...
        ok_o = 0 ;
        ok_o = 0 ;
    end
    end
    else
    else
        return_byte_o = read_status`READ_DATA ;
        return_byte_o = read_status`READ_DATA ;
 
 
 
    in_use = 0 ;
end
end
endtask // read_status_reg
endtask // read_status_reg
 
 
task kbd_write ;
task kbd_write ;
    input [31:0] address_i ;
    input [31:0] address_i ;
Line 611... Line 858...
    begin
    begin
        read_status_reg(kbd_status, ok_o) ;
        read_status_reg(kbd_status, ok_o) ;
    end
    end
 
 
    if ( ok_o !== 1 )
    if ( ok_o !== 1 )
        disable main ;
        #1 disable main ;
 
 
    i_wb_master.wb_single_write( write_data, flags, write_status ) ;
    i_wb_master.wb_single_write( write_data, flags, write_status ) ;
 
 
    if ( write_status`CYC_ACK !== 1 )
    if ( write_status`CYC_ACK !== 1 )
    begin
    begin
Line 658... Line 905...
 
 
    fork
    fork
    begin
    begin
        send_sequence( keyboard_sequence, 6, ok_keyboard ) ;
        send_sequence( keyboard_sequence, 6, ok_keyboard ) ;
        if ( ok_keyboard !== 1 )
        if ( ok_keyboard !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    begin
    begin
        receive_sequence( controler_sequence, 4, ok_controler ) ;
        receive_sequence( controler_sequence, 4, ok_controler ) ;
 
 
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    join
    join
 
 
    // test same thing with translation disabled!
    // test same thing with translation disabled!
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS, ok);
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`AUX_INTERRUPT_ON, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    // since translation is disabled, controler sequence is the same as keyboard sequence
    // since translation is disabled, controler sequence is the same as keyboard sequence
    controler_sequence = keyboard_sequence ;
    controler_sequence = keyboard_sequence ;
 
 
    fork
    fork
    begin
    begin
 
 
        send_sequence( keyboard_sequence, 6, ok_keyboard ) ;
        send_sequence( keyboard_sequence, 6, ok_keyboard ) ;
        if ( ok_keyboard !== 1 )
        if ( ok_keyboard !== 1 )
            disable main ;
            #1 disable main ;
 
 
    end
    end
    begin
    begin
        receive_sequence( controler_sequence, 6, ok_controler ) ;
        receive_sequence( controler_sequence, 6, ok_controler ) ;
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    join
    join
 
 
    // turn translation on again
    // turn translation on again
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC, ok);
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`AUX_INTERRUPT_ON|`KBD_KCC, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    // test extended character receiving - rctrl + s combination
    // test extended character receiving - rctrl + s combination
    // prepare sequence to send from keyboard to controler
    // prepare sequence to send from keyboard to controler
    // R CTRL make
    // R CTRL make
    keyboard_sequence[7:0]   = 8'hE0 ;
    keyboard_sequence[7:0]   = 8'hE0 ;
Line 735... Line 982...
 
 
    fork
    fork
    begin
    begin
        send_sequence( keyboard_sequence, 8, ok_keyboard ) ;
        send_sequence( keyboard_sequence, 8, ok_keyboard ) ;
        if ( ok_keyboard !== 1 )
        if ( ok_keyboard !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    begin
    begin
 
 
        receive_sequence( controler_sequence, 6, ok_controler ) ;
        receive_sequence( controler_sequence, 6, ok_controler ) ;
 
 
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    join
    join
 
 
     // test same thing with translation disabled!
     // test same thing with translation disabled!
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS, ok);
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`AUX_INTERRUPT_ON, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    // since translation is disabled, controler sequence is the same as keyboard sequence
    // since translation is disabled, controler sequence is the same as keyboard sequence
    controler_sequence = keyboard_sequence ;
    controler_sequence = keyboard_sequence ;
 
 
    fork
    fork
    begin
    begin
        send_sequence( keyboard_sequence, 8, ok_keyboard ) ;
        send_sequence( keyboard_sequence, 8, ok_keyboard ) ;
        if ( ok_keyboard !== 1 )
        if ( ok_keyboard !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    begin
    begin
 
 
        receive_sequence( controler_sequence, 8, ok_controler ) ;
        receive_sequence( controler_sequence, 8, ok_controler ) ;
 
 
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    join
    join
 
 
    watchdog_reset = !watchdog_reset ;
    watchdog_reset = !watchdog_reset ;
end
end
Line 788... Line 1035...
    reg [(MAX_SEQUENCE_LENGTH*8 - 1) : 0] controler_sequence ;
    reg [(MAX_SEQUENCE_LENGTH*8 - 1) : 0] controler_sequence ;
begin:main
begin:main
    // turn translation on
    // turn translation on
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC, ok);
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`AUX_INTERRUPT_ON|`KBD_KCC, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    for ( i = 0 ; i < `PS2_NUM_OF_NORMAL_SCANCODES ; i = i + 1 )
    for ( i = 0 ; i < `PS2_NUM_OF_NORMAL_SCANCODES ; i = i + 1 )
    begin
    begin
        keyboard_sequence[7:0]   = normal_scancode_set2_mem[i] ;
        keyboard_sequence[7:0]   = normal_scancode_set2_mem[i] ;
        keyboard_sequence[15:8]  = 8'hF0 ;
        keyboard_sequence[15:8]  = 8'hF0 ;
Line 806... Line 1053...
        controler_sequence[15:8] = normal_scancode_set1_mem[i] | 8'h80 ;
        controler_sequence[15:8] = normal_scancode_set1_mem[i] | 8'h80 ;
        fork
        fork
        begin
        begin
            send_sequence( keyboard_sequence, 3, ok_keyboard ) ;
            send_sequence( keyboard_sequence, 3, ok_keyboard ) ;
            if ( ok_keyboard !== 1 )
            if ( ok_keyboard !== 1 )
                disable main ;
                #1 disable main ;
        end
        end
        begin
        begin
            receive_sequence( controler_sequence, 2, ok_controler ) ;
            receive_sequence( controler_sequence, 2, ok_controler ) ;
            if ( ok_controler !== 1 )
            if ( ok_controler !== 1 )
                disable main ;
                #1 disable main ;
        end
        end
        join
        join
    end
    end
 
 
    watchdog_reset = !watchdog_reset ;
    watchdog_reset = !watchdog_reset ;
Line 832... Line 1079...
    reg [(MAX_SEQUENCE_LENGTH*8 - 1) : 0] controler_sequence ;
    reg [(MAX_SEQUENCE_LENGTH*8 - 1) : 0] controler_sequence ;
begin:main
begin:main
    // turn translation on
    // turn translation on
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC, ok);
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`AUX_INTERRUPT_ON|`KBD_KCC, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    for ( i = 0 ; i < `PS2_NUM_OF_EXTENDED_SCANCODES ; i = i + 1 )
    for ( i = 0 ; i < `PS2_NUM_OF_EXTENDED_SCANCODES ; i = i + 1 )
    begin
    begin
        keyboard_sequence[7:0]   = 8'hE0 ;
        keyboard_sequence[7:0]   = 8'hE0 ;
        keyboard_sequence[15:8]  = extended_scancode_set2_mem[i] ;
        keyboard_sequence[15:8]  = extended_scancode_set2_mem[i] ;
Line 854... Line 1101...
        controler_sequence[31:24] = extended_scancode_set1_mem[i] | 8'h80 ;
        controler_sequence[31:24] = extended_scancode_set1_mem[i] | 8'h80 ;
        fork
        fork
        begin
        begin
            send_sequence( keyboard_sequence, 5, ok_keyboard ) ;
            send_sequence( keyboard_sequence, 5, ok_keyboard ) ;
            if ( ok_keyboard !== 1 )
            if ( ok_keyboard !== 1 )
                disable main ;
                #1 disable main ;
        end
        end
        begin
        begin
            receive_sequence( controler_sequence, 4, ok_controler ) ;
            receive_sequence( controler_sequence, 4, ok_controler ) ;
            if ( ok_controler !== 1 )
            if ( ok_controler !== 1 )
                disable main ;
                #1 disable main ;
        end
        end
        join
        join
    end
    end
 
 
    watchdog_reset = !watchdog_reset ;
    watchdog_reset = !watchdog_reset ;
Line 878... Line 1125...
begin:main
begin:main
    wait ( wb_int === 1 ) ;
    wait ( wb_int === 1 ) ;
    read_status_reg( temp_data, ok_o ) ;
    read_status_reg( temp_data, ok_o ) ;
 
 
    if ( ok_o !== 1'b1 )
    if ( ok_o !== 1'b1 )
        disable main ;
        #1 disable main ;
 
 
    if ( !( temp_data & `KBD_OBF ) )
    if ( !( temp_data & `KBD_OBF ) )
    begin
    begin
        $display("Error! Interrupt received from keyboard controler when OBF status not set!") ;
        $display("Error! Interrupt received from keyboard controler when OBF status not set!") ;
        #400 $stop ;
        #400 $stop ;
    end
    end
 
 
 
    if ( temp_data & `AUX_OBUF_FULL )
 
    begin
 
        $display("Error! Interrupt received from keyboard controler when AUX_OBUF_FULL status was set!") ;
 
        #400 $stop ;
 
    end
 
 
    read_data_reg( temp_data, ok_o ) ;
    read_data_reg( temp_data, ok_o ) ;
 
 
    if ( ok_o !== 1'b1 )
    if ( ok_o !== 1'b1 )
        disable main ;
        #1 disable main ;
 
 
    scan_code_o = temp_data ;
    scan_code_o = temp_data ;
end
end
endtask // return_scan_code_on_irq
endtask // return_scan_code_on_irq
 
 
Line 931... Line 1184...
        if ( error )
        if ( error )
        begin
        begin
            $display("Time %t", $time) ;
            $display("Time %t", $time) ;
            $display("Keyboard model signaled an error!") ;
            $display("Keyboard model signaled an error!") ;
            ok_o = 0 ;
            ok_o = 0 ;
            disable main ;
            #1 disable main ;
        end
        end
    end
    end
end
end
endtask // send_sequence
endtask // send_sequence
 
 
Line 957... Line 1210...
        sequence_i = sequence_i >> 8 ;
        sequence_i = sequence_i >> 8 ;
 
 
        return_scan_code_on_irq( data, ok_o ) ;
        return_scan_code_on_irq( data, ok_o ) ;
 
 
        if ( ok_o !== 1 )
        if ( ok_o !== 1 )
            disable main ;
            #1 disable main ;
 
 
        if ( data !== current_char )
        if ( data !== current_char )
        begin
        begin
            $display("Time %t", $time) ;
            $display("Time %t", $time) ;
            $display("Error! Character received was wrong!") ;
            $display("Error! Character received was wrong!") ;
Line 986... Line 1239...
    ) ;
    ) ;
 
 
    if ( error )
    if ( error )
    begin
    begin
        $display("Error! Keyboard signaled an error while sending character!") ;
        $display("Error! Keyboard signaled an error while sending character!") ;
        disable main ;
        #1 disable main ;
    end
    end
 
 
    if ( !ok_keyboard )
    if ( !ok_keyboard )
    begin
    begin
        $display("Something is wrong! Keyboard wasn't able to send a character!") ;
        $display("Something is wrong! Keyboard wasn't able to send a character!") ;
        disable main ;
        #1 disable main ;
    end
    end
 
 
    // wait 5 us to see, if keyboard is inhibited
    // wait 5 us to see, if keyboard is inhibited
    #5000 ;
    #5000 ;
 
 
    // now check, if clock line is low!
    // now check, if clock line is low!
    if ( kbd_clk_cable !== 0 )
    if ( kbd_clk_cable !== 0 )
    begin
    begin
        $display("Error! Keyboard wasn't inhibited when output buffer was filled!") ;
        $display("Error! Keyboard wasn't inhibited when output buffer was filled!") ;
        disable main ;
        #1 disable main ;
    end
    end
 
 
    // now read the character from input buffer and check if clock was released
    // now read the character from input buffer and check if clock was released
    return_scan_code_on_irq( data, ok_controler ) ;
    return_scan_code_on_irq( data, ok_controler ) ;
    if ( ok_controler !== 1'b1 )
    if ( ok_controler !== 1'b1 )
        disable main ;
        #1 disable main ;
 
 
    if ( data !== 8'hE0 )
    if ( data !== 8'hE0 )
    begin
    begin
        $display("Time %t", $time) ;
        $display("Time %t", $time) ;
        $display("Error! Character read from controler not as expected!") ;
        $display("Error! Character read from controler not as expected!") ;
Line 1024... Line 1277...
            @(posedge wb_clock) ;
            @(posedge wb_clock) ;
 
 
        if ( kbd_clk_cable !== 1 )
        if ( kbd_clk_cable !== 1 )
        begin
        begin
            $display("Error! Keyboard wasn't released from inhibited state when output buffer was read!") ;
            $display("Error! Keyboard wasn't released from inhibited state when output buffer was read!") ;
            disable main ;
            #1 disable main ;
        end
        end
    end
    end
    begin
    begin
        i_ps2_keyboard_model.kbd_send_char
        i_ps2_keyboard_model.kbd_send_char
        (
        (
Line 1037... Line 1290...
            error
            error
        ) ;
        ) ;
        if ( !ok_keyboard )
        if ( !ok_keyboard )
        begin
        begin
            $display("Something is wrong! Keyboard wasn't able to send a character!") ;
            $display("Something is wrong! Keyboard wasn't able to send a character!") ;
            disable main ;
            #1 disable main ;
        end
        end
    end
    end
    begin
    begin
        return_scan_code_on_irq( data, ok_controler ) ;
        return_scan_code_on_irq( data, ok_controler ) ;
        if ( ok_controler !== 1'b1 )
        if ( ok_controler !== 1'b1 )
            disable main ;
            #1 disable main ;
 
 
        if ( data !== 8'h1E )
        if ( data !== 8'h1E )
        begin
        begin
            $display("Time %t", $time) ;
            $display("Time %t", $time) ;
            $display("Error! Character read from controler not as expected!") ;
            $display("Error! Character read from controler not as expected!") ;
Line 1056... Line 1309...
    join
    join
 
 
    // disable keyboard controler
    // disable keyboard controler
    kbd_write( `KBD_CNTL_REG, `KBD_WRITE_MODE, ok_controler ) ;
    kbd_write( `KBD_CNTL_REG, `KBD_WRITE_MODE, ok_controler ) ;
    if ( ok_controler !== 1 )
    if ( ok_controler !== 1 )
        disable main ;
        #1 disable main ;
 
 
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC | `KBD_DISABLE_COMMAND, ok_controler);
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`AUX_INTERRUPT_ON|`KBD_KCC | `KBD_DISABLE_COMMAND, ok_controler);
 
 
    if ( ok_controler !== 1 )
    if ( ok_controler !== 1 )
        disable main ;
        #1 disable main ;
 
 
    repeat( 5 )
    repeat( 5 )
        @(posedge wb_clock) ;
        @(posedge wb_clock) ;
 
 
    // now check, if clock line is low!
    // now check, if clock line is high!
    if ( kbd_clk_cable !== 0 )
    if ( kbd_clk_cable !== 1 )
    begin
    begin
        $display("Error! Keyboard wasn't inhibited when keyboard controler was disabled!") ;
        $display("Error! Keyboard is not supposed to be inhibited when keyboard controler is disabled!") ;
        disable main ;
        #1 disable main ;
    end
    end
 
 
    // send character and enable keyboard controler at the same time
    // send character and enable keyboard controler at the same time
    fork
    fork
    begin
    begin
Line 1086... Line 1339...
        ) ;
        ) ;
 
 
        if ( !ok_keyboard )
        if ( !ok_keyboard )
        begin
        begin
            $display("Something is wrong! Keyboard wasn't able to send a character!") ;
            $display("Something is wrong! Keyboard wasn't able to send a character!") ;
            disable main ;
            #1 disable main ;
        end
        end
    end
    end
    begin
    begin
        // enable keyboard controler
        // enable keyboard controler
        kbd_write( `KBD_CNTL_REG, `KBD_WRITE_MODE, ok_controler ) ;
        kbd_write( `KBD_CNTL_REG, `KBD_WRITE_MODE, ok_controler ) ;
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
 
 
        kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC, ok_controler);
        kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`AUX_INTERRUPT_ON|`KBD_KCC, ok_controler);
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    begin
    begin
        return_scan_code_on_irq( data, ok_controler ) ;
        return_scan_code_on_irq( data, ok_controler ) ;
        if ( ok_controler !== 1'b1 )
        if ( ok_controler !== 1'b1 )
            disable main ;
            #1 disable main ;
 
 
        if ( data !== 8'hE0 )
        if ( data !== 8'hE0 )
        begin
        begin
            $display("Time %t", $time) ;
            $display("Time %t", $time) ;
            $display("Error! Character read from controler not as expected!") ;
            $display("Error! Character read from controler not as expected!") ;
Line 1115... Line 1368...
    join
    join
 
 
    // do D2 command, that copies parameter in input buffer to output buffer
    // do D2 command, that copies parameter in input buffer to output buffer
    kbd_write( `KBD_CNTL_REG, 32'hD2_00_00_00, ok_controler ) ;
    kbd_write( `KBD_CNTL_REG, 32'hD2_00_00_00, ok_controler ) ;
    if ( ok_controler !== 1 )
    if ( ok_controler !== 1 )
        disable main ;
        #1 disable main ;
 
 
    kbd_write(`KBD_DATA_REG, 32'h5555_5555, ok_controler) ;
    kbd_write(`KBD_DATA_REG, 32'h5555_5555, ok_controler) ;
 
 
    if ( ok_controler !== 1 )
    if ( ok_controler !== 1 )
        disable main ;
        #1 disable main ;
 
 
    return_scan_code_on_irq( data, ok_controler ) ;
    return_scan_code_on_irq( data, ok_controler ) ;
    if ( ok_controler !== 1 )
    if ( ok_controler !== 1 )
        disable main ;
        #1 disable main ;
 
 
    if ( data !== 8'h55 )
    if ( data !== 8'h55 )
    begin
    begin
        $display("Error! D2 command doesn't work properly") ;
        $display("Error! D2 command doesn't work properly") ;
    end
    end
Line 1145... Line 1398...
    reg [(MAX_SEQUENCE_LENGTH*8 - 1) : 0] controler_sequence ;
    reg [(MAX_SEQUENCE_LENGTH*8 - 1) : 0] controler_sequence ;
begin:main
begin:main
    // turn translation on
    // turn translation on
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    kbd_write(`KBD_CNTL_REG, `KBD_WRITE_MODE, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`KBD_DMS|`KBD_KCC, ok);
    kbd_write(`KBD_DATA_REG, `KBD_EKI|`KBD_SYS|`AUX_INTERRUPT_ON|`KBD_KCC, ok);
    if ( ok !== 1 )
    if ( ok !== 1 )
        disable main ;
        #1 disable main ;
 
 
    // prepare character sequence to send from keyboard to controler - pause
    // prepare character sequence to send from keyboard to controler - pause
    keyboard_sequence[7:0]   = 8'hE1 ;
    keyboard_sequence[7:0]   = 8'hE1 ;
    keyboard_sequence[15:8]  = 8'h14 ;
    keyboard_sequence[15:8]  = 8'h14 ;
    keyboard_sequence[23:16] = 8'h77 ;
    keyboard_sequence[23:16] = 8'h77 ;
Line 1173... Line 1426...
 
 
    fork
    fork
    begin
    begin
        send_sequence( keyboard_sequence, 8, ok_keyboard ) ;
        send_sequence( keyboard_sequence, 8, ok_keyboard ) ;
        if ( ok_keyboard !== 1 )
        if ( ok_keyboard !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    begin
    begin
        receive_sequence( controler_sequence, 6, ok_controler ) ;
        receive_sequence( controler_sequence, 6, ok_controler ) ;
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    join
    join
 
 
    // prepare character sequence to send from keyboard to controler - make print screen
    // prepare character sequence to send from keyboard to controler - make print screen
    keyboard_sequence[7:0]   = 8'hE0 ;
    keyboard_sequence[7:0]   = 8'hE0 ;
Line 1198... Line 1451...
 
 
    fork
    fork
    begin
    begin
        send_sequence( keyboard_sequence, 4, ok_keyboard ) ;
        send_sequence( keyboard_sequence, 4, ok_keyboard ) ;
        if ( ok_keyboard !== 1 )
        if ( ok_keyboard !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    begin
    begin
        receive_sequence( controler_sequence, 4, ok_controler ) ;
        receive_sequence( controler_sequence, 4, ok_controler ) ;
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    join
    join
 
 
    // prepare character sequence to send from keyboard to controler - break print screen
    // prepare character sequence to send from keyboard to controler - break print screen
    keyboard_sequence[7:0]   = 8'hE0 ;
    keyboard_sequence[7:0]   = 8'hE0 ;
Line 1225... Line 1478...
 
 
    fork
    fork
    begin
    begin
        send_sequence( keyboard_sequence, 6, ok_keyboard ) ;
        send_sequence( keyboard_sequence, 6, ok_keyboard ) ;
        if ( ok_keyboard !== 1 )
        if ( ok_keyboard !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    begin
    begin
        receive_sequence( controler_sequence, 4, ok_controler ) ;
        receive_sequence( controler_sequence, 4, ok_controler ) ;
        if ( ok_controler !== 1 )
        if ( ok_controler !== 1 )
            disable main ;
            #1 disable main ;
    end
    end
    join
    join
end
end
endtask // test_print_screen_and_pause_scancodes
endtask // test_print_screen_and_pause_scancodes
 
 
 
`ifdef PS2_AUX
 
task receive_mouse_movement;
 
    reg [7:0] mouse_data_received ;
 
    reg ok_mouse ;
 
    reg ok_wb ;
 
    reg error ;
 
    integer num_of_mouse_data_sent ;
 
begin:main
 
    error    = 0 ;
 
    num_of_mouse_data_sent     = 0 ;
 
    while ( !stop_mouse_tests )
 
    begin
 
        fork
 
        begin
 
            ok_mouse = 0 ;
 
            while ( !ok_mouse && !error )
 
            begin
 
                i_ps2_mouse_model.kbd_send_char
 
                (
 
                    num_of_mouse_data_sent[7:0],
 
                    ok_mouse,
 
                    error
 
                ) ;
 
            end
 
            if ( error )
 
            begin
 
                $display("Mouse model signaled an error while transmiting data! Time %t", $time) ;
 
                #1 disable main ;
 
            end
 
            else
 
                num_of_mouse_data_sent = num_of_mouse_data_sent + 1 ;
 
 
 
        end
 
        begin
 
            return_mouse_data_on_irq( mouse_data_received, ok_wb ) ;
 
            if ( !ok_wb )
 
                #1 disable main ;
 
 
 
            if ( mouse_data_received !== num_of_mouse_data_sent[7:0] )
 
            begin
 
                $display("Time %t", $time) ;
 
                $display("Data received from mouse has unexpected value! Expected %h, actual %h", num_of_mouse_data_sent[7:0], mouse_data_received) ;
 
            end
 
        end
 
        join
 
    end
 
 
 
    $display("Number of chars received from mouse %d", num_of_mouse_data_sent) ;
 
end
 
endtask //receive_mouse_movement
 
 
 
task return_mouse_data_on_irq ;
 
    output [7:0] mouse_data_o ;
 
    output       ok_o ;
 
    reg    [7:0] temp_data ;
 
begin:main
 
    wait ( wb_intb === 1 ) ;
 
 
 
    wait ( ps2_test_bench.read_status_reg.in_use !== 1'b1 );
 
 
 
    read_status_reg( temp_data, ok_o ) ;
 
 
 
    if ( ok_o !== 1'b1 )
 
        #1 disable main ;
 
 
 
    if ( !( temp_data & `AUX_OBUF_FULL ) || !(temp_data & `KBD_OBF))
 
    begin
 
        $display("Error! Interrupt b received from controler when AUX_OBF status or KBD_OBF statuses not set!") ;
 
        #400 $stop ;
 
    end
 
 
 
    wait ( ps2_test_bench.read_data_reg.in_use !== 1'b1 );
 
 
 
    read_data_reg( temp_data, ok_o ) ;
 
 
 
    if ( ok_o !== 1'b1 )
 
        #1 disable main ;
 
 
 
    mouse_data_o = temp_data ;
 
end
 
endtask // return_scan_code_on_irq
 
`endif
 
 
endmodule // ps2_test_bench
endmodule // ps2_test_bench
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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