data/full_repos/permissive/479082840/TLS.v
data/verilator_xmls/6385f5c3-1c9b-45b8-9bd3-6434b3355f6c.xml
module TLS(clk, reset, Set, Stop, Jump, Gin, Yin, Rin, Gout, Yout, Rout);
input           clk;
input           reset;
input           Set;
input           Stop;
input           Jump;
input     [3:0] Gin;
input     [3:0] Yin;
input     [3:0] Rin;
output reg         Gout;
output reg         Yout;
output reg         Rout;

reg [1:0] state, next_state;
reg [1:0] state_g = 2'd0;
reg [1:0] state_y = 2'd1;
reg [1:0] state_r = 2'd2;
reg [3:0] g_duration, y_duration, r_duration, count, next_count;


always@(posedge clk) begin
  if (Set) begin
    next_count = 0;
    next_state = state_g;
    g_duration = Gin;
    y_duration  =Yin;
    r_duration = Rin;  
    count = next_count;
    state = next_state;
  end
  
  else if (Stop) begin


  end
  
  else if (Jump) begin
    next_count = 0;
    next_state = state_r; 
    count = next_count;
    state = next_state;
  end
  
  else begin 
    count = next_count;
    state = next_state;
  end

end




always@(*) begin
  case(state)
    state_g: begin
      if (count == g_duration-1) begin
        next_state = state_y;
        next_count = 4'd0;
      end
      else begin
        next_state = state;
        next_count = count+4'd1;
      end
    end
    
    state_y: begin
      if (count == y_duration-1) begin
        next_state = state_r;
        next_count = 4'd0;
      end
      else begin
        next_state = state;
        next_count = count+4'd1;
      end
    end
    
    state_r: begin
      if (count == r_duration-1) begin
        next_state = state_g;
        next_count = 4'd0;
      end
      else begin
        next_state = state;
        next_count = count+4'd1;
      end
    end
  endcase 
end



always@(state) begin
  case(state) 
    state_g: begin
      Gout = 1'b1; Yout = 1'b0; Rout = 1'b0;
    end
    
    state_y:begin
      Gout = 1'b0; Yout = 1'b1; Rout = 1'b0;
    end
    
    state_r:begin
      Gout = 1'b0; Yout =1'b0; Rout = 1'b1;
    end
  endcase
end      
  
  
endmodule
module TLS(clk, reset, Set, Stop, Jump, Gin, Yin, Rin, Gout, Yout, Rout);

input           clk;
input           reset;
input           Set;
input           Stop;
input           Jump;
input     [3:0] Gin;
input     [3:0] Yin;
input     [3:0] Rin;
output reg         Gout;
output reg         Yout;
output reg         Rout;

reg [1:0] state, next_state;
reg [1:0] state_g = 2'd0;
reg [1:0] state_y = 2'd1;
reg [1:0] state_r = 2'd2;
reg [3:0] g_duration, y_duration, r_duration, count, next_count;


always@(posedge clk) begin
  if (Set) begin
    next_count = 0;
    next_state = state_g;
    g_duration = Gin;
    y_duration  =Yin;
    r_duration = Rin;  
    count = next_count;
    state = next_state;
  end
  
  else if (Stop) begin


  end
  
  else if (Jump) begin
    next_count = 0;
    next_state = state_r; 
    count = next_count;
    state = next_state;
  end
  
  else begin 
    count = next_count;
    state = next_state;
  end

end




always@(*) begin
  case(state)
    state_g: begin
      if (count == g_duration-1) begin
        next_state = state_y;
        next_count = 4'd0;
      end
      else begin
        next_state = state;
        next_count = count+4'd1;
      end
    end
    
    state_y: begin
      if (count == y_duration-1) begin
        next_state = state_r;
        next_count = 4'd0;
      end
      else begin
        next_state = state;
        next_count = count+4'd1;
      end
    end
    
    state_r: begin
      if (count == r_duration-1) begin
        next_state = state_g;
        next_count = 4'd0;
      end
      else begin
        next_state = state;
        next_count = count+4'd1;
      end
    end
  endcase 
end



always@(state) begin
  case(state) 
    state_g: begin
      Gout = 1'b1; Yout = 1'b0; Rout = 1'b0;
    end
    
    state_y:begin
      Gout = 1'b0; Yout = 1'b1; Rout = 1'b0;
    end
    
    state_r:begin
      Gout = 1'b0; Yout =1'b0; Rout = 1'b1;
    end
  endcase
end      
  
  
endmodule