data/full_repos/permissive/528014597/vending_machine.v
1: b'%Warning-WIDTH: data/full_repos/permissive/528014597/vending_machine.v:54: Operator SUB expects 32 or 7 bits on the LHS, but LHS\'s VARREF \'origin\' generates 3 bits.\n                                                                         : ... In instance vending_machine\n     costOfTicket = 5 +  (origin-destination) * 5  ;\n                                ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/528014597/vending_machine.v:54: Operator SUB expects 32 or 7 bits on the RHS, but RHS\'s VARREF \'destination\' generates 3 bits.\n                                                                         : ... In instance vending_machine\n     costOfTicket = 5 +  (origin-destination) * 5  ;\n                                ^\n%Warning-WIDTH: data/full_repos/permissive/528014597/vending_machine.v:56: Operator SUB expects 32 or 7 bits on the LHS, but LHS\'s VARREF \'destination\' generates 3 bits.\n                                                                         : ... In instance vending_machine\n     costOfTicket =  5 + (destination-origin) * 5 ; \n                                     ^\n%Warning-WIDTH: data/full_repos/permissive/528014597/vending_machine.v:56: Operator SUB expects 32 or 7 bits on the RHS, but RHS\'s VARREF \'origin\' generates 3 bits.\n                                                                         : ... In instance vending_machine\n     costOfTicket =  5 + (destination-origin) * 5 ; \n                                     ^\n%Error: Exiting due to 4 warning(s)\n'
module vending_machine( costOfTicket, moneyToPay, totalMoney, clk, reset, howManyTicket, origin, destination, money );

input clk, reset ;
input [2:0] howManyTicket, origin, destination;
input [5:0] money ;
output reg [6:0] costOfTicket, moneyToPay, totalMoney;

reg [2:0] state;
reg [2:0] next_state;
 
parameter s0 = 3'd0; 
parameter s1 = 3'd1;  
parameter s2 = 3'd2;  
parameter s3 = 3'd3;

initial begin
	costOfTicket = 0 ;
	moneyToPay = 0 ;
	totalMoney = 0 ;
	state = s0 ;
	next_state = s0;
end


always @( posedge clk ) 
	begin
	if ( reset ) 
		begin
		costOfTicket = 0;
		moneyToPay = 0;

		state = s3;
		end
	else 
		begin	
		state = next_state;

		end
	end


always @(state or posedge clk)     
	begin
	case( state ) 
		s0: begin
			totalMoney = 7'd0 ;
			moneyToPay = 7'd0 ;
			costOfTicket = 7'd0 ;
		end
		s1: begin
				if( origin == destination )
					costOfTicket =  5 ;
				else if ( origin > destination )
					costOfTicket = 5 +  (origin-destination) * 5  ;
				else
					costOfTicket =  5 + (destination-origin) * 5 ;	
				$display( "costOfTicket : ",  costOfTicket);
			if ( howManyTicket > 0 && howManyTicket < 6 ) begin
				costOfTicket = howManyTicket *  costOfTicket ;
				$display( "total Need Money : ",  costOfTicket);
			end
		end
		s2 : begin
			$display( "money",  money );
			totalMoney = totalMoney + money;
			if ( totalMoney <= costOfTicket ) 
				moneyToPay = costOfTicket - totalMoney ;
			else 
				moneyToPay = 0 ;
			$display( "total ",  totalMoney , " dollars,  left ", moneyToPay , " dollars" );
		end
		s3: begin
			if ( reset )
				$display( "cancel !! ticket : 0", "  return: ", totalMoney, " dollars" );
			else if ( totalMoney >= moneyToPay )
				$display(" tickets : ", howManyTicket,  "  return change: ", totalMoney - costOfTicket, " dollars" );
		end
	endcase
	
	end
	

always @(state or posedge clk)
	begin
	case (state)
	s0: begin
		if ( origin > 0 && origin < 6 && destination > 0 && destination < 6 )
			next_state = s1 ;
		else 
			next_state = s0 ;

		end
	s1: begin
		if (reset )
			next_state = s3 ;
		if ( howManyTicket > 0 && howManyTicket < 6	)
			next_state = s2;
		else 
			next_state = s1;

		end
	s2: begin
		if ( reset )
			next_state = s3;
		else if ( costOfTicket > totalMoney )
			next_state = s2;
		else 
			next_state = s3;

		end
	s3: begin

		next_state = s0 ;

		end
		
	default: next_state = s0;
	endcase
	end
	
endmodule
module vending_machine( costOfTicket, moneyToPay, totalMoney, clk, reset, howManyTicket, origin, destination, money );


input clk, reset ;
input [2:0] howManyTicket, origin, destination;
input [5:0] money ;
output reg [6:0] costOfTicket, moneyToPay, totalMoney;

reg [2:0] state;
reg [2:0] next_state;
 
parameter s0 = 3'd0; 
parameter s1 = 3'd1;  
parameter s2 = 3'd2;  
parameter s3 = 3'd3;

initial begin
	costOfTicket = 0 ;
	moneyToPay = 0 ;
	totalMoney = 0 ;
	state = s0 ;
	next_state = s0;
end


always @( posedge clk ) 
	begin
	if ( reset ) 
		begin
		costOfTicket = 0;
		moneyToPay = 0;

		state = s3;
		end
	else 
		begin	
		state = next_state;

		end
	end


always @(state or posedge clk)     
	begin
	case( state ) 
		s0: begin
			totalMoney = 7'd0 ;
			moneyToPay = 7'd0 ;
			costOfTicket = 7'd0 ;
		end
		s1: begin
				if( origin == destination )
					costOfTicket =  5 ;
				else if ( origin > destination )
					costOfTicket = 5 +  (origin-destination) * 5  ;
				else
					costOfTicket =  5 + (destination-origin) * 5 ;	
				$display( "costOfTicket : ",  costOfTicket);
			if ( howManyTicket > 0 && howManyTicket < 6 ) begin
				costOfTicket = howManyTicket *  costOfTicket ;
				$display( "total Need Money : ",  costOfTicket);
			end
		end
		s2 : begin
			$display( "money",  money );
			totalMoney = totalMoney + money;
			if ( totalMoney <= costOfTicket ) 
				moneyToPay = costOfTicket - totalMoney ;
			else 
				moneyToPay = 0 ;
			$display( "total ",  totalMoney , " dollars,  left ", moneyToPay , " dollars" );
		end
		s3: begin
			if ( reset )
				$display( "cancel !! ticket : 0", "  return: ", totalMoney, " dollars" );
			else if ( totalMoney >= moneyToPay )
				$display(" tickets : ", howManyTicket,  "  return change: ", totalMoney - costOfTicket, " dollars" );
		end
	endcase
	
	end
	

always @(state or posedge clk)
	begin
	case (state)
	s0: begin
		if ( origin > 0 && origin < 6 && destination > 0 && destination < 6 )
			next_state = s1 ;
		else 
			next_state = s0 ;

		end
	s1: begin
		if (reset )
			next_state = s3 ;
		if ( howManyTicket > 0 && howManyTicket < 6	)
			next_state = s2;
		else 
			next_state = s1;

		end
	s2: begin
		if ( reset )
			next_state = s3;
		else if ( costOfTicket > totalMoney )
			next_state = s2;
		else 
			next_state = s3;

		end
	s3: begin

		next_state = s0 ;

		end
		
	default: next_state = s0;
	endcase
	end
	
endmodule