data/full_repos/permissive/117026779/sim/Test_ServoController.v
 line:67: before: ";"
1: b'%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:62: Unsupported: Ignoring delay on this delayed statement.\n    #5\n    ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:64: Unsupported: Ignoring delay on this delayed statement.\n    #5\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:75: Unsupported: Ignoring delay on this delayed statement.\n  #5\n  ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:77: Unsupported: Ignoring delay on this delayed statement.\n  #5\n  ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:99: Unsupported: Ignoring delay on this delayed statement.\n #1\n ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:105: Unsupported: Ignoring delay on this delayed statement.\n #1\n ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:108: Unsupported: Ignoring delay on this delayed statement.\n #1\n ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:115: Unsupported: Ignoring delay on this delayed statement.\n    #10\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:114: Unsupported: Ignoring delay on this delayed statement.\n    #10\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:190: Unsupported: Ignoring delay on this delayed statement.\n    #10 $stop;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/117026779/sim/Test_ServoController.v:191: Unsupported: Ignoring delay on this delayed statement.\n    #5 $finish;\n    ^\n%Error: data/full_repos/permissive/117026779/sim/Test_ServoController.v:42: Cannot find file containing module: \'ServoController\'\nServoController servo(\n^~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/117026779/sim,data/full_repos/permissive/117026779/ServoController\n             data/full_repos/permissive/117026779/sim,data/full_repos/permissive/117026779/ServoController.v\n             data/full_repos/permissive/117026779/sim,data/full_repos/permissive/117026779/ServoController.sv\n             ServoController\n             ServoController.v\n             ServoController.sv\n             obj_dir/ServoController\n             obj_dir/ServoController.v\n             obj_dir/ServoController.sv\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:90: Bit extraction of var[3:0] requires 2 bit index, not 3 bits.\n                                                                                  : ... In instance Test_ServoController\n  $display("!!ERROR!! @ %d signal[%d] = 0x%X !== 0x%X", $time, select, signal[select], level);\n                                                                             ^\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:87: Bit extraction of var[3:0] requires 2 bit index, not 3 bits.\n                                                                                  : ... In instance Test_ServoController\n if(signal[select] != level)\n          ^\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:101: Operator ASSIGN expects 2 bits on the Assign RHS, but Assign RHS\'s VARREF \'select\' generates 32 bits.\n                                                                                   : ... In instance Test_ServoController\n addr = select;\n      ^\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:117: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n LOAD_COMPARE_VALUE(2\'b00, 32\'d1000);\n ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:120: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:122: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:124: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:127: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n LOAD_COMPARE_VALUE(2\'b00, 32\'d1500);\n ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:128: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n    LOAD_COMPARE_VALUE(2\'b01, 32\'d1500);\n    ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:131: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:132: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:134: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:135: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:137: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:138: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:140: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:141: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:144: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n LOAD_COMPARE_VALUE(2\'b00, 32\'d2500);\n ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:145: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n    LOAD_COMPARE_VALUE(2\'b01, 32\'d2500);\n    ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:146: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h2\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n    LOAD_COMPARE_VALUE(2\'b10, 32\'d2500);\n    ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:147: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h3\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n    LOAD_COMPARE_VALUE(2\'b11, 32\'d2500);\n    ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:150: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n    LOAD_COMPARE_VALUE(2\'b00, 32\'d500);\n    ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:151: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n    LOAD_COMPARE_VALUE(2\'b01, 32\'d1000);\n    ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:152: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h2\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n    LOAD_COMPARE_VALUE(2\'b10, 32\'d1500);\n    ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:153: Operator TASKREF \'LOAD_COMPARE_VALUE\' expects 32 bits on the Function Argument, but Function Argument\'s CONST \'2\'h3\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n    LOAD_COMPARE_VALUE(2\'b11, 32\'d2000);\n    ^~~~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:156: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:157: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:158: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h2\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b10, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:159: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h3\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b11, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:161: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:162: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:163: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h2\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b10, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:164: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h3\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b11, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:166: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:167: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:168: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h2\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b10, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:169: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h3\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b11, 1);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:171: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:172: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:173: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h2\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b10, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:174: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h3\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b11, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:176: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b00, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:177: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h1\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b01, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:178: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h2\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b10, 0);\n ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/sim/Test_ServoController.v:179: Operator TASKREF \'CHECK_OUTPUT\' expects 3 bits on the Function Argument, but Function Argument\'s CONST \'2\'h3\' generates 2 bits.\n                                                                                   : ... In instance Test_ServoController\n CHECK_OUTPUT(2\'b11, 0);\n ^~~~~~~~~~~~\n%Error: Exiting due to 1 error(s), 56 warning(s)\n        ... See the manual and https://verilator.org for more assistance.\n'
module Test_ServoController;

parameter SIGNAL_BIT_WIDTH  = 15;
parameter ADDRESS_BIT_WIDTH = 2;
parameter PWM_SIGNAL_COUNT  = 4;
parameter FULL_CYCLE 		= 32'd20_000;

reg success_flag;

reg clk, rst, cs;

reg [31:0] data_reg;
wire [31:0] data;
reg test_write_enable;

reg  [ADDRESS_BIT_WIDTH-1:0] addr;
wire  [PWM_SIGNAL_COUNT-1:0] signal;

ServoController servo(
    .clk(clk),
    .rst(rst),
    .cs(cs),
    .addr(addr[1:0]),
    .data(data[14:0]),
    .signal(signal)
);

assign data = (test_write_enable) ? data_reg : 32'bZ;

integer i;

task RESET;
begin
	success_flag = 1;
    rst = 0;
    clk = 0;
    cs = 0;
    test_write_enable = 0;
    #5
    rst = 1;
    #5
    rst = 0;
end
endtask;

task CLOCK;
	input [31:0] count;
	integer k;
begin
	for (k=0; k < count; k = k+1)
	begin
		#5
		clk = 1;
		#5
		clk = 0;
	end
end
endtask

task CHECK_OUTPUT;
	input [2:0] select;
	input level;
begin
	if(signal[select] != level)
	begin
		success_flag = 0;
		$display("!!ERROR!! @ %d signal[%d] = 0x%X !== 0x%X", $time, select, signal[select], level);
	end
end
endtask;

task LOAD_COMPARE_VALUE;
	input [31:0] select;
	input [31:0] value;
begin
	#1
	cs = 1;
	addr = select;
	test_write_enable = 1;
	data_reg = value;
	CLOCK(1);
	#1
	test_write_enable = 0;
	cs = 0;
	#1
	addr = 0;
end
endtask

initial begin
    #10
    #10
	RESET;
	LOAD_COMPARE_VALUE(2'b00, 32'd1000);
	CLOCK(FULL_CYCLE);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 1);
	CLOCK(505);
	CHECK_OUTPUT(2'b00, 0);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CLOCK(FULL_CYCLE-1505);

	LOAD_COMPARE_VALUE(2'b00, 32'd1500);
    LOAD_COMPARE_VALUE(2'b01, 32'd1500);
	CLOCK(FULL_CYCLE);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 1);
	CHECK_OUTPUT(2'b01, 1);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 1);
	CHECK_OUTPUT(2'b01, 1);
	CLOCK(400);
	CHECK_OUTPUT(2'b00, 1);
	CHECK_OUTPUT(2'b01, 1);
	CLOCK(200);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CLOCK(FULL_CYCLE-(500+500+400+200));

	LOAD_COMPARE_VALUE(2'b00, 32'd2500);
    LOAD_COMPARE_VALUE(2'b01, 32'd2500);
    LOAD_COMPARE_VALUE(2'b10, 32'd2500);
    LOAD_COMPARE_VALUE(2'b11, 32'd2500);
	CLOCK(FULL_CYCLE);
	CLOCK(FULL_CYCLE);
    LOAD_COMPARE_VALUE(2'b00, 32'd500);
    LOAD_COMPARE_VALUE(2'b01, 32'd1000);
    LOAD_COMPARE_VALUE(2'b10, 32'd1500);
    LOAD_COMPARE_VALUE(2'b11, 32'd2000);
    CLOCK(FULL_CYCLE);
    CLOCK(500);
	CHECK_OUTPUT(2'b00, 1);
	CHECK_OUTPUT(2'b01, 1);
	CHECK_OUTPUT(2'b10, 1);
	CHECK_OUTPUT(2'b11, 1);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CHECK_OUTPUT(2'b10, 1);
	CHECK_OUTPUT(2'b11, 1);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CHECK_OUTPUT(2'b10, 0);
	CHECK_OUTPUT(2'b11, 1);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CHECK_OUTPUT(2'b10, 0);
	CHECK_OUTPUT(2'b11, 0);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CHECK_OUTPUT(2'b10, 0);
	CHECK_OUTPUT(2'b11, 0);
	CLOCK(FULL_CYCLE-(500*5));


	if (success_flag == 0) begin
		$display("*FAILED* TEST!");
	end
	else begin
		$display("**PASSED** TEST!");
	end

    #10 $stop;
    #5 $finish;
end

endmodule
module Test_ServoController;


parameter SIGNAL_BIT_WIDTH  = 15;
parameter ADDRESS_BIT_WIDTH = 2;
parameter PWM_SIGNAL_COUNT  = 4;
parameter FULL_CYCLE 		= 32'd20_000;

reg success_flag;

reg clk, rst, cs;

reg [31:0] data_reg;
wire [31:0] data;
reg test_write_enable;

reg  [ADDRESS_BIT_WIDTH-1:0] addr;
wire  [PWM_SIGNAL_COUNT-1:0] signal;

ServoController servo(
    .clk(clk),
    .rst(rst),
    .cs(cs),
    .addr(addr[1:0]),
    .data(data[14:0]),
    .signal(signal)
);

assign data = (test_write_enable) ? data_reg : 32'bZ;

integer i;

task RESET;
begin
	success_flag = 1;
    rst = 0;
    clk = 0;
    cs = 0;
    test_write_enable = 0;
    #5
    rst = 1;
    #5
    rst = 0;
end
endtask;

task CLOCK;
	input [31:0] count;
	integer k;
begin
	for (k=0; k < count; k = k+1)
	begin
		#5
		clk = 1;
		#5
		clk = 0;
	end
end
endtask

task CHECK_OUTPUT;
	input [2:0] select;
	input level;
begin
	if(signal[select] != level)
	begin
		success_flag = 0;
		$display("!!ERROR!! @ %d signal[%d] = 0x%X !== 0x%X", $time, select, signal[select], level);
	end
end
endtask;

task LOAD_COMPARE_VALUE;
	input [31:0] select;
	input [31:0] value;
begin
	#1
	cs = 1;
	addr = select;
	test_write_enable = 1;
	data_reg = value;
	CLOCK(1);
	#1
	test_write_enable = 0;
	cs = 0;
	#1
	addr = 0;
end
endtask

initial begin
    #10
    #10
	RESET;
	LOAD_COMPARE_VALUE(2'b00, 32'd1000);
	CLOCK(FULL_CYCLE);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 1);
	CLOCK(505);
	CHECK_OUTPUT(2'b00, 0);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CLOCK(FULL_CYCLE-1505);

	LOAD_COMPARE_VALUE(2'b00, 32'd1500);
    LOAD_COMPARE_VALUE(2'b01, 32'd1500);
	CLOCK(FULL_CYCLE);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 1);
	CHECK_OUTPUT(2'b01, 1);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 1);
	CHECK_OUTPUT(2'b01, 1);
	CLOCK(400);
	CHECK_OUTPUT(2'b00, 1);
	CHECK_OUTPUT(2'b01, 1);
	CLOCK(200);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CLOCK(FULL_CYCLE-(500+500+400+200));

	LOAD_COMPARE_VALUE(2'b00, 32'd2500);
    LOAD_COMPARE_VALUE(2'b01, 32'd2500);
    LOAD_COMPARE_VALUE(2'b10, 32'd2500);
    LOAD_COMPARE_VALUE(2'b11, 32'd2500);
	CLOCK(FULL_CYCLE);
	CLOCK(FULL_CYCLE);
    LOAD_COMPARE_VALUE(2'b00, 32'd500);
    LOAD_COMPARE_VALUE(2'b01, 32'd1000);
    LOAD_COMPARE_VALUE(2'b10, 32'd1500);
    LOAD_COMPARE_VALUE(2'b11, 32'd2000);
    CLOCK(FULL_CYCLE);
    CLOCK(500);
	CHECK_OUTPUT(2'b00, 1);
	CHECK_OUTPUT(2'b01, 1);
	CHECK_OUTPUT(2'b10, 1);
	CHECK_OUTPUT(2'b11, 1);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CHECK_OUTPUT(2'b10, 1);
	CHECK_OUTPUT(2'b11, 1);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CHECK_OUTPUT(2'b10, 0);
	CHECK_OUTPUT(2'b11, 1);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CHECK_OUTPUT(2'b10, 0);
	CHECK_OUTPUT(2'b11, 0);
	CLOCK(500);
	CHECK_OUTPUT(2'b00, 0);
	CHECK_OUTPUT(2'b01, 0);
	CHECK_OUTPUT(2'b10, 0);
	CHECK_OUTPUT(2'b11, 0);
	CLOCK(FULL_CYCLE-(500*5));


	if (success_flag == 0) begin
		$display("*FAILED* TEST!");
	end
	else begin
		$display("**PASSED** TEST!");
	end

    #10 $stop;
    #5 $finish;
end

endmodule