CRC generator

In reply to chr_sue:



Please check the following code:

class driver extends uvm_driver #(sequence_item);
   `uvm_component_utils_begin(driver)
   `uvm_component_utils_end
      
   uvm_analysis_port #(sequence_item)drv2scb_port;
   sequence_item seq_item;
   

   virtual interface interface vif;
   
   
   agent agent_ptr;
      
   int bit_q_size;
   typedef bit crc_size[];                       //Debug purpose for CRC
   
   
   function new(string name,uvm_component parent);
      super.new(name,parent);
   endfunction
   
   function void build();
      super.build();
      drv2scb_port=new("drv2scb_port",this);
   endfunction

// START_ENCRYPTION
      task run();
         //body
      endtask
  
   rand bit eof_bit;
   task frame(sequence_item obj);
      byte crc_data;
      int crc_bits = 14;
      int crc_polynomial;
      
      bit crc_reg[];          //Debug purpose for CRC
      bit crc_reg_cur[];      //Debug purpose for CRC
      obj.bit_q={};
      //body to send different frames
      
       crc_bits = 14;             // Need to update condition for 3 different scenarios
        crc_polynomial = 'h4599; // Need to update condition for 3 different scenarios
        
        for(int i=0; i<obj.bit_q.size;i++) begin
         for(int i=0;i<obj.bit_q.size;i++)begin
            crc_reg = new[crc_bits+1]; 
            crc_reg_cur = new[crc_bits+1]; 
      	    crc_reg = crc_calc(crc_reg_cur , obj.bit_q[i],crc_bits,crc_polynomial); 			 
            crc_reg_cur = crc_reg;
         end
         
   endtask :create_frame
///////////////////////////////////////////////////////////////////////////////
// crc calculation using frames sof -> data(if present) (else) controlled field 
///////////////////////////////////////////////////////////////////////////////

/*   function bit [14:0] crc_calc(bit [14:0]crc ,bit data); //Initial CRC calculation
      bit crc_nxt=0;
      crc_nxt = data ^ crc[14];
      crc[14:1] = crc[13:0];
      crc[0] = 0;
      if(crc_nxt)begin
         crc[14:0]=crc ^ 'h4599;
      end
      return crc;
   endfunction */

    //CRC calculation function updated by me
   function crc_size crc_calc(crc_size crc ,bit data, int crc_bits, int crc_polynomial); 
      bit crc_nxt=0;
      crc_calc = new [crc_bits+1];
      crc_nxt = data ^ crc[crc_bits];
      crc[crc_bits:1] = crc[crc_bits-1:0];
      crc[0] = 0;
      if(crc_nxt)begin
         crc[crc_bits:0]=crc ^ crc_polynomial;
      end
      return crc;
   endfunction

endclass