data/full_repos/permissive/120024308/src/LCDController/init_fsm.v
data/verilator_xmls/1ecf2181-6a83-4733-9edc-7bddc721a29b.xml
module InitFSM(
                input wire clk,
                input wire reset,
                input wire [19:0] count,
                output reg finished,
                output reg count_reset,
                output reg [3:0] sf_d,
                output reg lcd_e
                );

   reg [3:0]               state, next_state;

   always @(posedge clk)
     begin
        if(reset)
          begin
             state <= `RESET;
          end
        else
          begin
             state <= next_state;
          end
     end

   always @(*)
     begin
        lcd_e = 0;
        count_reset = 0;
        finished = 0;
        case(state)
          `RESET:
            begin
               count_reset = 1;
	       sf_d = 0;
               next_state = `INIT_WAIT;
            end
          `INIT_WAIT:
            begin
               if(count > 750000)
                 begin
                    next_state = `PHASE1_A;
                    count_reset = 1;
		    sf_d = 4'h3;		    
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `INIT_WAIT;
                 end
            end
          `PHASE1_A:
            begin

               lcd_e = 1;
               if(count > 12)
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE1_B;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE1_A;
                 end
               end
          `PHASE1_B:
            begin
               if(count > 205000)
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE2_A;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE1_B;
                 end
            end
          `PHASE2_A:
            begin
               lcd_e = 1;
               if(count > 12)
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE2_B;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE2_A;
                 end
               end
          `PHASE2_B:
            begin
               if(count > 5000)
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE3_A;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h3;	    
                    next_state = `PHASE2_B;
                 end
            end
          `PHASE3_A:
            begin
               lcd_e = 1;
               if(count > 12)
                 begin
                    next_state = `PHASE3_B;
                    count_reset = 1;
		    sf_d = 4'h3;
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE3_A;
                 end
               end
          `PHASE3_B:
            begin
               if(count > 2000)
                 begin
                    next_state = `PHASE4_A;
                    count_reset = 1;
		    sf_d = 4'h2;
                 end
               else
                 begin
                    next_state = `PHASE3_B;
		    if (count > 1920)
		      begin
			 sf_d = 4'h2;
		      end
		    else begin
		       sf_d = 4'h3;
		    end
                 end	      
            end
          `PHASE4_A:
            begin
               lcd_e = 1;
               if(count > 12)
                 begin
                    next_state = `PHASE4_B;
                    count_reset = 1;
		    sf_d = 4'h2;
                 end
               else
                 begin
		    sf_d = 4'h2;
                    next_state = `PHASE4_A;
                 end
               end
          `PHASE4_B:
            begin
               if(count > 2000)
                 begin
		    sf_d = 4'h2;
                    next_state = `INIT_HALT;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h2;
                    next_state = `PHASE4_B;
                 end
            end
          `INIT_HALT:
            begin
               next_state = `INIT_HALT;
               finished = 1;
	       sf_d = 0;
            end
          `INIT_DEFAULT:
            begin
	       sf_d = 0;
	       
               next_state = `INIT_DEFAULT;
            end
          default:
            begin
	       sf_d = 0;
	       
               next_state = `INIT_DEFAULT;
            end
          endcase
        end
endmodule
module InitFSM(
                input wire clk,
                input wire reset,
                input wire [19:0] count,
                output reg finished,
                output reg count_reset,
                output reg [3:0] sf_d,
                output reg lcd_e
                );


   reg [3:0]               state, next_state;

   always @(posedge clk)
     begin
        if(reset)
          begin
             state <= `RESET;
          end
        else
          begin
             state <= next_state;
          end
     end

   always @(*)
     begin
        lcd_e = 0;
        count_reset = 0;
        finished = 0;
        case(state)
          `RESET:
            begin
               count_reset = 1;
	       sf_d = 0;
               next_state = `INIT_WAIT;
            end
          `INIT_WAIT:
            begin
               if(count > 750000)
                 begin
                    next_state = `PHASE1_A;
                    count_reset = 1;
		    sf_d = 4'h3;		    
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `INIT_WAIT;
                 end
            end
          `PHASE1_A:
            begin

               lcd_e = 1;
               if(count > 12)
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE1_B;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE1_A;
                 end
               end
          `PHASE1_B:
            begin
               if(count > 205000)
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE2_A;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE1_B;
                 end
            end
          `PHASE2_A:
            begin
               lcd_e = 1;
               if(count > 12)
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE2_B;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE2_A;
                 end
               end
          `PHASE2_B:
            begin
               if(count > 5000)
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE3_A;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h3;	    
                    next_state = `PHASE2_B;
                 end
            end
          `PHASE3_A:
            begin
               lcd_e = 1;
               if(count > 12)
                 begin
                    next_state = `PHASE3_B;
                    count_reset = 1;
		    sf_d = 4'h3;
                 end
               else
                 begin
		    sf_d = 4'h3;
                    next_state = `PHASE3_A;
                 end
               end
          `PHASE3_B:
            begin
               if(count > 2000)
                 begin
                    next_state = `PHASE4_A;
                    count_reset = 1;
		    sf_d = 4'h2;
                 end
               else
                 begin
                    next_state = `PHASE3_B;
		    if (count > 1920)
		      begin
			 sf_d = 4'h2;
		      end
		    else begin
		       sf_d = 4'h3;
		    end
                 end	      
            end
          `PHASE4_A:
            begin
               lcd_e = 1;
               if(count > 12)
                 begin
                    next_state = `PHASE4_B;
                    count_reset = 1;
		    sf_d = 4'h2;
                 end
               else
                 begin
		    sf_d = 4'h2;
                    next_state = `PHASE4_A;
                 end
               end
          `PHASE4_B:
            begin
               if(count > 2000)
                 begin
		    sf_d = 4'h2;
                    next_state = `INIT_HALT;
                    count_reset = 1;
                 end
               else
                 begin
		    sf_d = 4'h2;
                    next_state = `PHASE4_B;
                 end
            end
          `INIT_HALT:
            begin
               next_state = `INIT_HALT;
               finished = 1;
	       sf_d = 0;
            end
          `INIT_DEFAULT:
            begin
	       sf_d = 0;
	       
               next_state = `INIT_DEFAULT;
            end
          default:
            begin
	       sf_d = 0;
	       
               next_state = `INIT_DEFAULT;
            end
          endcase
        end
endmodule