data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v
 line:712: before: "@"
1: b'%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:18: Cannot find include file: ../../utils/sim/sim.v\n`include "../../utils/sim/sim.v" \n         ^~~~~~~~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/190755935/src/drivers/sim,data/full_repos/permissive/190755935/../../utils/sim/sim.v\n             data/full_repos/permissive/190755935/src/drivers/sim,data/full_repos/permissive/190755935/../../utils/sim/sim.v.v\n             data/full_repos/permissive/190755935/src/drivers/sim,data/full_repos/permissive/190755935/../../utils/sim/sim.v.sv\n             ../../utils/sim/sim.v\n             ../../utils/sim/sim.v.v\n             ../../utils/sim/sim.v.sv\n             obj_dir/../../utils/sim/sim.v\n             obj_dir/../../utils/sim/sim.v.v\n             obj_dir/../../utils/sim/sim.v.sv\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:20: Cannot find include file: ../../pipe/rtl/pipe_defs.v\n`include "../../pipe/rtl/pipe_defs.v" \n         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:24: Define or directive not defined: \'`OutputDebug\'\n    parameter Output=`OutputDebug;\n                     ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:24: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    parameter Output=`OutputDebug;\n                                 ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:29: Unsupported or unknown PLI call: $dumpfile\n        $dumpfile("camera_tb.vcd");\n        ^~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:30: Unsupported or unknown PLI call: $dumpvars\n        $dumpvars( 1, camera_tb );\n        ^~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:31: Unsupported or unknown PLI call: $dumpvars\n        $dumpvars( 1, camera_tb.cam );\n        ^~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:32: Unsupported or unknown PLI call: $dumpvars\n        $dumpvars( 1, camera_tb.cam.cam_conf );\n        ^~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:33: Unsupported or unknown PLI call: $dumpvars\n        $dumpvars( 1, camera_tb.cam.i2c_m );\n        ^~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:34: Unsupported or unknown PLI call: $dumpvars\n        $dumpvars( 1, camera_tb.cam_proxy );\n        ^~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:35: Unsupported or unknown PLI call: $dumpvars\n        $dumpvars( 0, camera_tb.cam_proxy.i2c_s );\n        ^~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:39: Define or directive not defined: \'`Realtime\'\n    `Realtime\n    ^~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:42: Define or directive not defined: \'`Clock10MHz\'\n    `Clock10MHz\n    ^~~~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:44: Define or directive not defined: \'`AssertSetup\'\n    `AssertSetup\n    ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:271: syntax error, unexpected \'@\'\n            @( posedge clock );\n            ^\n%Warning-STMTDLY: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:270: Unsupported: Ignoring delay on this delayed statement.\n            #2\n            ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Warning-STMTDLY: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:274: Unsupported: Ignoring delay on this delayed statement.\n            #2\n            ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:291: Define or directive not defined: \'`Info\'\n            `Info( "    Reset");\n            ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:291: syntax error, unexpected \';\'\n            `Info( "    Reset");\n                               ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:299: Define or directive not defined: \'`InfoDo\'\n            `InfoDo $display( "    Check Write [%3d,%3d]-[%3d,%3d]", x0, y0, x1, y1 );\n            ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:305: Define or directive not defined: \'`InfoDo\'\n            `InfoDo $display( "        Wait Not Busy" );\n            ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:314: Define or directive not defined: \'`InfoDo\'\n            `InfoDo $display( "    Set Snapshot Mode %d", in );\n            ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:330: Define or directive not defined: \'`InfoDo\'\n            `InfoDo $display( "    Set Window  X %3d Y %3d W %3d H %3d", cs, rs, ww, wh );\n            ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:346: Define or directive not defined: \'`Assert\'\n            `Assert( busy, "Should be busy for a while" );\n            ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:346: syntax error, unexpected \',\'\n            `Assert( busy, "Should be busy for a while" );\n                         ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:376: Define or directive not defined: \'`Info\'\n        `Info( "    Checking Idle State" );\n        ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:376: syntax error, unexpected \';\'\n        `Info( "    Checking Idle State" );\n                                          ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:378: Define or directive not defined: \'`Info\'\n        `Info( "    Configure" );\n        ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:378: syntax error, unexpected \';\'\n        `Info( "    Configure" );\n                                ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:386: Define or directive not defined: \'`Assert\'\n        `Assert( configuring, "Configuring" );\n        ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:386: syntax error, unexpected \',\'\n        `Assert( configuring, "Configuring" );\n                            ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:392: Define or directive not defined: \'`Info\'\n        `Info( "    Idle" );\n        ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:392: syntax error, unexpected \';\'\n        `Info( "    Idle" );\n                           ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:394: Define or directive not defined: \'`Assert\'\n        `Assert( idle, "Idle" );\n        ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:394: syntax error, unexpected \',\'\n        `Assert( idle, "Idle" );\n                     ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:408: Define or directive not defined: \'`Info\'\n        `Info( "    Set Window" );\n        ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:408: syntax error, unexpected \';\'\n        `Info( "    Set Window" );\n                                 ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:419: Define or directive not defined: \'`Info\'\n        `Info( "    Running" );\n        ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:419: syntax error, unexpected \';\'\n        `Info( "    Running" );\n                              ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:432: Define or directive not defined: \'`Assert\'\n        `Assert( running, "Running" );\n        ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:432: syntax error, unexpected \',\'\n        `Assert( running, "Running" );\n                        ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:470: Define or directive not defined: \'`Info\'\n        `Info( "    Frame Start" );\n        ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:470: syntax error, unexpected \';\'\n        `Info( "    Frame Start" );\n                                  ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:479: Define or directive not defined: \'`Assert\'\n        `Assert( c < count, "Frame Start too long" );\n        ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:479: syntax error, unexpected \',\'\n        `Assert( c < count, "Frame Start too long" );\n                          ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:486: Define or directive not defined: \'`Info\'\n            `Info( "        Wait for Line Start" );\n            ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:486: syntax error, unexpected \';\'\n            `Info( "        Wait for Line Start" );\n                                                  ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:495: Define or directive not defined: \'`Assert\'\n            `Assert( c < count, "Too long waiting for dropped hs after vs" );\n            ^~~~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:495: syntax error, unexpected \',\'\n            `Assert( c < count, "Too long waiting for dropped hs after vs" );\n                              ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:497: Define or directive not defined: \'`Info\'\n            `Info( "        Read Line Start" );\n            ^~~~~\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:497: syntax error, unexpected \';\'\n            `Info( "        Read Line Start" );\n                                              ^\n%Error: data/full_repos/permissive/190755935/src/drivers/sim/camera_tb.v:514: Define or directive not defined: \'`Info\'\n            `Info( "        Line End" );\n            ^~~~~\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module camera_tb();

    parameter Output=`OutputDebug;

    reg  reset;

    initial begin
        $dumpfile("camera_tb.vcd");
        $dumpvars( 1, camera_tb );
        $dumpvars( 1, camera_tb.cam );
        $dumpvars( 1, camera_tb.cam.cam_conf );
        $dumpvars( 1, camera_tb.cam.i2c_m );
        $dumpvars( 1, camera_tb.cam_proxy );
        $dumpvars( 0, camera_tb.cam_proxy.i2c_s );
    end


    `Realtime


    `Clock10MHz

    `AssertSetup





    localparam CameraWidth = 32;
    localparam CameraHeight = 16;

    localparam CoordinateWidth = 10;
    localparam BlankingWidth = 16;





    wire sda;
    wire scl;

    wire camera_scl_out;
    wire camera_sda_out;

    wire camera_proxy_scl_out;
    wire camera_proxy_sda_out;

    assign scl = ( camera_scl_out && camera_proxy_scl_out );
    assign sda = ( camera_sda_out && camera_proxy_sda_out );







    wire       out_vs;
    wire       out_hs;
    wire       out_valid;
    wire [9:0] out_d;

    wire       vs;
    wire       hs;
    wire       pclk;
    wire       xclk;
    wire [9:0] d;
    wire       rst;
    wire       led;
    wire       pwdn;

    wire       trigger;

    reg configure;
    reg start;
    reg stop;

    wire configuring;
    wire idle;
    wire running;
    wire error;
    wire busy;

    reg [CoordinateWidth-1:0] column_start;
    reg [CoordinateWidth-1:0] row_start;
    reg [CoordinateWidth-1:0] window_width;
    reg [CoordinateWidth-1:0] window_height;

    reg set_origin;
    reg set_window;

    reg [BlankingWidth-1:0]   horizontal_blanking;
    reg [BlankingWidth-1:0]   vertical_blanking;

    reg set_blanking;

    reg snapshot_mode;
    reg set_snapshot_mode;
    reg snapshot;

    localparam PixelWidth = 10;







    wire [PixelWidth-1:0] pixel_data;
    wire                  pixel_frame_start;
    wire                  pixel_frame_stop;
    wire                  pixel_line_start;
    wire                  pixel_line_stop;

    camera_core #(
            .Width( CameraWidth ),
            .Height( CameraHeight ),
            .I2CClockCount( 32 ),
            .I2CGapCount(1 << 8)
        ) cam (
            .clock( clock ),
            .reset( reset ),


            .configure( configure ),
            .start( start ),
            .stop( stop ),


            .running( running ),
            .idle( idle ),
            .configuring( configuring ),
            .busy( busy ),
            .error( error ),


            .column_start( column_start ),
            .row_start( row_start),
            .window_width( window_width ),
            .window_height( window_height ),

            .set_origin( set_origin ),
            .set_window( set_window ),


            .horizontal_blanking( horizontal_blanking ),
            .vertical_blanking( vertical_blanking ),

            .set_blanking( set_blanking ),


            .snapshot_mode( snapshot_mode ),
            .set_snapshot_mode( set_snapshot_mode ),

            .snapshot( snapshot ),


            .out_vs( out_vs ),
            .out_hs( out_hs ),
            .out_valid( out_valid ),
            .out_d( out_d ),


            .scl_in( scl ),
            .scl_out( camera_scl_out ),
            .sda_in( sda ),
            .sda_out( camera_sda_out ),
            .vs( vs ),
            .hs( hs ),
            .pclk( pclk ),
            .d( d ),
            .rst( rst ),
            .pwdn( pwdn ),
            .led( led ),
            .trigger( trigger )
        );

    camera_proxy #(
            .Width( CameraWidth ),
            .Height( CameraHeight )
        ) cam_proxy (
            .clock( clock ),
            .reset( reset ),

            .scl_in( scl ),
            .scl_out( camera_proxy_scl_out ),
            .sda_in( sda ),
            .sda_out( camera_proxy_sda_out ),

            .vs( vs ),
            .hs( hs ),
            .pclk( pclk ),
            .xclk( xclk ),
            .d( d ),

            .rst( rst ),
            .pwdn( pwdn ),

            .led( led ),
            .trigger( trigger )
        );

    assign xclk = ctb_xclk;

    integer i, j, k;
    integer c;
    integer timeout;
    integer count;

    reg [8*50:1] test_name;

    task camtb_init;
        begin

            configure = 0;
            start = 0;
            stop = 0;
            ctb_xclk = 0;

            snapshot = 0;

            c = 0;
            column_count = 0;
            row_count = 0;

            test_height = 0;
            test_width = 0;

            set_origin = 0;
            set_window = 0;
            set_blanking = 0;
            set_snapshot_mode = 0;

            column_start = 0;
            row_start = 0;
            window_width = 0;
            window_height = 0;

            horizontal_blanking = 0;
            vertical_blanking = 0;

            snapshot_mode = 0;
        end
    endtask

    reg ctb_xclk;

    task  camtb_clock;
        begin
            #2
            @( posedge clock );

            ctb_xclk = !ctb_xclk;
            #2
            ;
        end
    endtask

    task camtb_clock_multiple( input integer  n );
        begin
            for ( i = 0; i < n; i = i + 1 ) begin
                camtb_clock;
            end
        end
    endtask

    task  camtb_reset;
        begin
            reset = 1;
            camtb_clock;
            `Info( "    Reset");
            reset = 0;
            camtb_clock;
        end
    endtask

    task camtb_check_write_rect( input integer x0, input integer y0, input integer x1, input integer y1 );
        begin
            `InfoDo $display( "    Check Write [%3d,%3d]-[%3d,%3d]", x0, y0, x1, y1 );
        end
    endtask

    task camtb_wait_not_busy;
        begin
            `InfoDo $display( "        Wait Not Busy" );

            while ( busy )
                camtb_clock;
        end
    endtask

    task camtb_set_snapshot( input reg in ) ;
        begin
            `InfoDo $display( "    Set Snapshot Mode %d", in );
            snapshot_mode = in;

            while ( busy )
                camtb_clock;

            set_snapshot_mode = 1;

            camtb_clock;

            set_snapshot_mode = 0;
        end
    endtask

    task camtb_set_window( input integer cs, input integer rs, input integer ww, input integer wh );
        begin
            `InfoDo $display( "    Set Window  X %3d Y %3d W %3d H %3d", cs, rs, ww, wh );

            while ( busy )
                camtb_clock;

            column_start = cs;
            row_start = rs;
            window_width = ww;
            window_height = wh;

            set_window = 1;

            camtb_clock;

            set_window = 0;

            `Assert( busy, "Should be busy for a while" );

            while (!busy )
                camtb_clock;

            while (busy)
                camtb_clock;

        end
    endtask

    integer data_count;
    integer command_count;

    integer column_count;
    integer row_count;

    integer test_width;
    integer test_height;

    reg pclk_previous;

    initial begin
        $display( "\nCAMERA Test %s", `__FILE__ );

        camtb_init;
        camtb_reset;

        camtb_clock_multiple( 100 );

        `Info( "    Checking Idle State" );

        `Info( "    Configure" );

        configure = 1;

        camtb_clock;

        configure = 0;

        `Assert( configuring, "Configuring" );

        while ( configuring )
            camtb_clock;


        `Info( "    Idle" );

        `Assert( idle, "Idle" );

        camtb_clock_multiple( 1000 );









        camtb_wait_not_busy;

        `Info( "    Set Window" );

        test_width = 8;
        test_height = 8;

        camtb_set_window( 2, 2, test_width, test_height );

        camtb_wait_not_busy;

        camtb_clock_multiple( 1000 );

        `Info( "    Running" );

        start = 1;

        camtb_clock;

        start = 0;

        while ( running == 0 ) begin
            camtb_clock;
            $display( "        %d", running );
        end

        `Assert( running, "Running" );





































        `Info( "    Frame Start" );

        c = 0;
        count = 100000;
        while ( ( out_vs == 0 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Frame Start too long" );

        row_count = 0;
        column_count = 0;

        while ( ( out_vs == 1) && ( row_count < test_height  ) ) begin

            `Info( "        Wait for Line Start" );

            c = 0;
            count = 10000;
            while ( ( out_hs == 0 ) && ( c < count ) ) begin
                camtb_clock;
                c = c + 1;
            end

            `Assert( c < count, "Too long waiting for dropped hs after vs" );

            `Info( "        Read Line Start" );

            c  = 0;
            count = 1000;
            while ( ( out_hs == 1 ) && ( c < count ) ) begin

                while ( ( !out_valid ) && ( c < count ) )  begin
                    camtb_clock;
                    c = c + 1;
                end

                camtb_clock;

                c = c + 1;
                column_count = column_count + 1;
            end

            `Info( "        Line End" );

            `AssertEqual( column_count, test_width, "Wrong column count" );
            `Assert( c < count, "Too long in line" );

            `InfoDo $display( "        H %-d", column_count );

            column_count = 0;

            row_count = row_count + 1;
        end

        `InfoDo $display( "        V %-d", row_count );

        `Info( "    Frame End" );

        c = 0;
        count = 10000;
        while ( ( vs == 1 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Too long waiting for end of frame" );

        camtb_clock_multiple( 100 );

        `AssertEqual( row_count, test_height, "Wrong row count" );

        camtb_wait_not_busy;

        `Info( "    Idle" );

        stop = 1;

        camtb_clock;

        stop = 0;

        c = 0;
        count = 100000;
        while ( ( running == 1 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        camtb_clock;

        `Assert( c < count, "Stop took too long" );

        `Info( "    Set New Window = size of camera image" );


        test_width = CameraWidth - 1;

        test_height = CameraHeight - 4;

        camtb_set_window( 1, 4, test_width, test_height );

        camtb_wait_not_busy;

        camtb_clock_multiple( 1000 );

        `Info( "    Restart Start" );

        start = 1;

        camtb_clock;

        start = 0;

        camtb_clock;

        c = 0;
        count = 100000;
        while ( ( running == 0 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Start took too long" );





        `Info( "    Frame Start" );

        c = 0;
        count = 100000;
        while ( ( out_vs == 0 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Frame Start too long" );

        row_count = 0;
        column_count = 0;

        while ( ( out_vs == 1) && ( row_count < test_height  ) ) begin

            `Info( "        Wait for Line Start" );

            c = 0;
            count = 10000;
            while ( ( out_hs == 0 ) && ( c < count ) ) begin
                camtb_clock;
                c = c + 1;
            end

            `Assert( c < count, "Too long waiting for dropped hs after vs" );

            `Info( "        Read Line Start" );

            c  = 0;
            count = 1000;
            while ( ( out_hs == 1 ) && ( c < count ) ) begin

                while ( ( !out_valid ) && ( c < count ) )  begin
                    camtb_clock;
                    c = c + 1;
                end

                camtb_clock;

                c = c + 1;
                column_count = column_count + 1;
            end

            `Info( "        Line End" );

            `AssertEqual( column_count, test_width, "Wrong column count" );
            `Assert( c < count, "Too long in line" );

            `InfoDo $display( "        H %-d", column_count );

            column_count = 0;

            row_count = row_count + 1;
        end

        `InfoDo $display( "        V %-d", row_count );

        `Info( "    Frame End" );

        c = 0;
        count = 10000;
        while ( ( vs == 1 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Too long waiting for end of frame" );

        camtb_clock_multiple( 100 );

        `AssertEqual( row_count, test_height, "Wrong row count" );


        `AssertSummary

        $finish;
    end

endmodule
module camera_tb();


    parameter Output=`OutputDebug;

    reg  reset;

    initial begin
        $dumpfile("camera_tb.vcd");
        $dumpvars( 1, camera_tb );
        $dumpvars( 1, camera_tb.cam );
        $dumpvars( 1, camera_tb.cam.cam_conf );
        $dumpvars( 1, camera_tb.cam.i2c_m );
        $dumpvars( 1, camera_tb.cam_proxy );
        $dumpvars( 0, camera_tb.cam_proxy.i2c_s );
    end


    `Realtime


    `Clock10MHz

    `AssertSetup





    localparam CameraWidth = 32;
    localparam CameraHeight = 16;

    localparam CoordinateWidth = 10;
    localparam BlankingWidth = 16;





    wire sda;
    wire scl;

    wire camera_scl_out;
    wire camera_sda_out;

    wire camera_proxy_scl_out;
    wire camera_proxy_sda_out;

    assign scl = ( camera_scl_out && camera_proxy_scl_out );
    assign sda = ( camera_sda_out && camera_proxy_sda_out );







    wire       out_vs;
    wire       out_hs;
    wire       out_valid;
    wire [9:0] out_d;

    wire       vs;
    wire       hs;
    wire       pclk;
    wire       xclk;
    wire [9:0] d;
    wire       rst;
    wire       led;
    wire       pwdn;

    wire       trigger;

    reg configure;
    reg start;
    reg stop;

    wire configuring;
    wire idle;
    wire running;
    wire error;
    wire busy;

    reg [CoordinateWidth-1:0] column_start;
    reg [CoordinateWidth-1:0] row_start;
    reg [CoordinateWidth-1:0] window_width;
    reg [CoordinateWidth-1:0] window_height;

    reg set_origin;
    reg set_window;

    reg [BlankingWidth-1:0]   horizontal_blanking;
    reg [BlankingWidth-1:0]   vertical_blanking;

    reg set_blanking;

    reg snapshot_mode;
    reg set_snapshot_mode;
    reg snapshot;

    localparam PixelWidth = 10;







    wire [PixelWidth-1:0] pixel_data;
    wire                  pixel_frame_start;
    wire                  pixel_frame_stop;
    wire                  pixel_line_start;
    wire                  pixel_line_stop;

    camera_core #(
            .Width( CameraWidth ),
            .Height( CameraHeight ),
            .I2CClockCount( 32 ),
            .I2CGapCount(1 << 8)
        ) cam (
            .clock( clock ),
            .reset( reset ),


            .configure( configure ),
            .start( start ),
            .stop( stop ),


            .running( running ),
            .idle( idle ),
            .configuring( configuring ),
            .busy( busy ),
            .error( error ),


            .column_start( column_start ),
            .row_start( row_start),
            .window_width( window_width ),
            .window_height( window_height ),

            .set_origin( set_origin ),
            .set_window( set_window ),


            .horizontal_blanking( horizontal_blanking ),
            .vertical_blanking( vertical_blanking ),

            .set_blanking( set_blanking ),


            .snapshot_mode( snapshot_mode ),
            .set_snapshot_mode( set_snapshot_mode ),

            .snapshot( snapshot ),


            .out_vs( out_vs ),
            .out_hs( out_hs ),
            .out_valid( out_valid ),
            .out_d( out_d ),


            .scl_in( scl ),
            .scl_out( camera_scl_out ),
            .sda_in( sda ),
            .sda_out( camera_sda_out ),
            .vs( vs ),
            .hs( hs ),
            .pclk( pclk ),
            .d( d ),
            .rst( rst ),
            .pwdn( pwdn ),
            .led( led ),
            .trigger( trigger )
        );

    camera_proxy #(
            .Width( CameraWidth ),
            .Height( CameraHeight )
        ) cam_proxy (
            .clock( clock ),
            .reset( reset ),

            .scl_in( scl ),
            .scl_out( camera_proxy_scl_out ),
            .sda_in( sda ),
            .sda_out( camera_proxy_sda_out ),

            .vs( vs ),
            .hs( hs ),
            .pclk( pclk ),
            .xclk( xclk ),
            .d( d ),

            .rst( rst ),
            .pwdn( pwdn ),

            .led( led ),
            .trigger( trigger )
        );

    assign xclk = ctb_xclk;

    integer i, j, k;
    integer c;
    integer timeout;
    integer count;

    reg [8*50:1] test_name;

    task camtb_init;
        begin

            configure = 0;
            start = 0;
            stop = 0;
            ctb_xclk = 0;

            snapshot = 0;

            c = 0;
            column_count = 0;
            row_count = 0;

            test_height = 0;
            test_width = 0;

            set_origin = 0;
            set_window = 0;
            set_blanking = 0;
            set_snapshot_mode = 0;

            column_start = 0;
            row_start = 0;
            window_width = 0;
            window_height = 0;

            horizontal_blanking = 0;
            vertical_blanking = 0;

            snapshot_mode = 0;
        end
    endtask

    reg ctb_xclk;

    task  camtb_clock;
        begin
            #2
            @( posedge clock );

            ctb_xclk = !ctb_xclk;
            #2
            ;
        end
    endtask

    task camtb_clock_multiple( input integer  n );
        begin
            for ( i = 0; i < n; i = i + 1 ) begin
                camtb_clock;
            end
        end
    endtask

    task  camtb_reset;
        begin
            reset = 1;
            camtb_clock;
            `Info( "    Reset");
            reset = 0;
            camtb_clock;
        end
    endtask

    task camtb_check_write_rect( input integer x0, input integer y0, input integer x1, input integer y1 );
        begin
            `InfoDo $display( "    Check Write [%3d,%3d]-[%3d,%3d]", x0, y0, x1, y1 );
        end
    endtask

    task camtb_wait_not_busy;
        begin
            `InfoDo $display( "        Wait Not Busy" );

            while ( busy )
                camtb_clock;
        end
    endtask

    task camtb_set_snapshot( input reg in ) ;
        begin
            `InfoDo $display( "    Set Snapshot Mode %d", in );
            snapshot_mode = in;

            while ( busy )
                camtb_clock;

            set_snapshot_mode = 1;

            camtb_clock;

            set_snapshot_mode = 0;
        end
    endtask

    task camtb_set_window( input integer cs, input integer rs, input integer ww, input integer wh );
        begin
            `InfoDo $display( "    Set Window  X %3d Y %3d W %3d H %3d", cs, rs, ww, wh );

            while ( busy )
                camtb_clock;

            column_start = cs;
            row_start = rs;
            window_width = ww;
            window_height = wh;

            set_window = 1;

            camtb_clock;

            set_window = 0;

            `Assert( busy, "Should be busy for a while" );

            while (!busy )
                camtb_clock;

            while (busy)
                camtb_clock;

        end
    endtask

    integer data_count;
    integer command_count;

    integer column_count;
    integer row_count;

    integer test_width;
    integer test_height;

    reg pclk_previous;

    initial begin
        $display( "\nCAMERA Test %s", `__FILE__ );

        camtb_init;
        camtb_reset;

        camtb_clock_multiple( 100 );

        `Info( "    Checking Idle State" );

        `Info( "    Configure" );

        configure = 1;

        camtb_clock;

        configure = 0;

        `Assert( configuring, "Configuring" );

        while ( configuring )
            camtb_clock;


        `Info( "    Idle" );

        `Assert( idle, "Idle" );

        camtb_clock_multiple( 1000 );









        camtb_wait_not_busy;

        `Info( "    Set Window" );

        test_width = 8;
        test_height = 8;

        camtb_set_window( 2, 2, test_width, test_height );

        camtb_wait_not_busy;

        camtb_clock_multiple( 1000 );

        `Info( "    Running" );

        start = 1;

        camtb_clock;

        start = 0;

        while ( running == 0 ) begin
            camtb_clock;
            $display( "        %d", running );
        end

        `Assert( running, "Running" );





































        `Info( "    Frame Start" );

        c = 0;
        count = 100000;
        while ( ( out_vs == 0 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Frame Start too long" );

        row_count = 0;
        column_count = 0;

        while ( ( out_vs == 1) && ( row_count < test_height  ) ) begin

            `Info( "        Wait for Line Start" );

            c = 0;
            count = 10000;
            while ( ( out_hs == 0 ) && ( c < count ) ) begin
                camtb_clock;
                c = c + 1;
            end

            `Assert( c < count, "Too long waiting for dropped hs after vs" );

            `Info( "        Read Line Start" );

            c  = 0;
            count = 1000;
            while ( ( out_hs == 1 ) && ( c < count ) ) begin

                while ( ( !out_valid ) && ( c < count ) )  begin
                    camtb_clock;
                    c = c + 1;
                end

                camtb_clock;

                c = c + 1;
                column_count = column_count + 1;
            end

            `Info( "        Line End" );

            `AssertEqual( column_count, test_width, "Wrong column count" );
            `Assert( c < count, "Too long in line" );

            `InfoDo $display( "        H %-d", column_count );

            column_count = 0;

            row_count = row_count + 1;
        end

        `InfoDo $display( "        V %-d", row_count );

        `Info( "    Frame End" );

        c = 0;
        count = 10000;
        while ( ( vs == 1 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Too long waiting for end of frame" );

        camtb_clock_multiple( 100 );

        `AssertEqual( row_count, test_height, "Wrong row count" );

        camtb_wait_not_busy;

        `Info( "    Idle" );

        stop = 1;

        camtb_clock;

        stop = 0;

        c = 0;
        count = 100000;
        while ( ( running == 1 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        camtb_clock;

        `Assert( c < count, "Stop took too long" );

        `Info( "    Set New Window = size of camera image" );


        test_width = CameraWidth - 1;

        test_height = CameraHeight - 4;

        camtb_set_window( 1, 4, test_width, test_height );

        camtb_wait_not_busy;

        camtb_clock_multiple( 1000 );

        `Info( "    Restart Start" );

        start = 1;

        camtb_clock;

        start = 0;

        camtb_clock;

        c = 0;
        count = 100000;
        while ( ( running == 0 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Start took too long" );





        `Info( "    Frame Start" );

        c = 0;
        count = 100000;
        while ( ( out_vs == 0 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Frame Start too long" );

        row_count = 0;
        column_count = 0;

        while ( ( out_vs == 1) && ( row_count < test_height  ) ) begin

            `Info( "        Wait for Line Start" );

            c = 0;
            count = 10000;
            while ( ( out_hs == 0 ) && ( c < count ) ) begin
                camtb_clock;
                c = c + 1;
            end

            `Assert( c < count, "Too long waiting for dropped hs after vs" );

            `Info( "        Read Line Start" );

            c  = 0;
            count = 1000;
            while ( ( out_hs == 1 ) && ( c < count ) ) begin

                while ( ( !out_valid ) && ( c < count ) )  begin
                    camtb_clock;
                    c = c + 1;
                end

                camtb_clock;

                c = c + 1;
                column_count = column_count + 1;
            end

            `Info( "        Line End" );

            `AssertEqual( column_count, test_width, "Wrong column count" );
            `Assert( c < count, "Too long in line" );

            `InfoDo $display( "        H %-d", column_count );

            column_count = 0;

            row_count = row_count + 1;
        end

        `InfoDo $display( "        V %-d", row_count );

        `Info( "    Frame End" );

        c = 0;
        count = 10000;
        while ( ( vs == 1 ) && ( c < count ) ) begin
            camtb_clock;
            c = c + 1;
        end

        `Assert( c < count, "Too long waiting for end of frame" );

        camtb_clock_multiple( 100 );

        `AssertEqual( row_count, test_height, "Wrong row count" );


        `AssertSummary

        $finish;
    end

endmodule