
function [processData, countReset, countEn, dumpControl, PrePadding]= PaddingController(PrePadFlag, OnLineFlag, PostPadFlag, DumpingFlag, BlankingFlag)
%#codegen

persistent FSMState;


S0 = fi(0,0,3,0);
S1 = fi(1,0,3,0);
S2 = fi(2,0,3,0);
S3 = fi(3,0,3,0);
S4 = fi(4,0,3,0);


if isempty(FSMState)
    FSMState = fi(0,0,3,0);
end





switch FSMState
    
    case S0 %% Blanking
    processData = false;
    countReset = true;
    countEn = false;
    dumpControl = false;
    PrePadding = false;
    
    if PrePadFlag
      FSMState(:) = 1;  
    else
      FSMState(:) = 0;  
    end
    
        
    case S1 %% PrePadding
    processData = true;
    countReset = false;
    countEn = true;
    dumpControl = false;
    PrePadding = true;
    
    if OnLineFlag
      FSMState(:) = 2;  
    else
      FSMState(:) = 1;  
    end      
        
        
    case S2 %% OnLine
    processData = true;
    countReset = false;
    countEn = false;
    dumpControl = false;
    PrePadding = false;

    
    if DumpingFlag
      FSMState(:) = 3; 
      
    else
      FSMState(:) = 2;  
    end       
    
    case S3 %% Dumping
    processData = true;
    countReset = false;
    countEn = false;
    dumpControl = true;
    PrePadding = false;

    
    if PostPadFlag
      FSMState(:) = 4;  
    else
      FSMState(:) = 3;  
    end  
    
    case S4 %% PostPadding
    processData = true;
    countReset = false;
    countEn = true;
    dumpControl = true;
    PrePadding = false;
 
    
    if BlankingFlag
      FSMState(:) = 0;  
    else
      FSMState(:) = 4;  
    end          
            
  
        
    otherwise
    processData = false;
    countReset = false;    
    countEn = false;
    dumpControl = false;
    PrePadding = false;
        
     
end