FPGA CRC-16/XMODEM x16+x12+x5+1

module crc_16(
    input clk,
    input [47:0]mac,
    input rst,
    input hash_enable,//哈希控制器使能位
    output reg hash_complete,//哈希转换完成标志位
    output reg [15:0]crc_16  
    );

    
       wire[63:0]stemp; 
       reg[63:0]temp=0;
       reg temp_flag;
       parameter polynomial=17'b1_0001_0000_0010_0001;
       assign stemp={mac,16'b0000000000000000};
       
       always @ (*) begin//posedge clk or negedge rst
            if(rst) begin
               hash_complete<=0;
               crc_16<=0;               
               temp<=0; 
			   temp_flag<=0;
              end
           else if(hash_enable && temp_flag)begin           
               if(temp[63]) temp[63:47]<=temp[63:47]^polynomial;
               else if(temp[62]) temp[62:46]<=temp[62:46]^polynomial;
               else if(temp[61]) temp[61:45]<=temp[61:45]^polynomial;
               else if(temp[60]) temp[60:44]<=temp[60:44]^polynomial;
               else if(temp[59]) temp[59:43]<=temp[59:43]^polynomial;
               else if(temp[58]) temp[58:42]<=temp[58:42]^polynomial;
               else if(temp[57]) temp[57:41]<=temp[57:41]^polynomial;
               else if(temp[56]) temp[56:40]<=temp[56:40]^polynomial;
               else if(temp[55]) temp[55:39]<=temp[55:39]^polynomial;
               else if(temp[54]) temp[54:38]<=temp[54:38]^polynomial;
               else if(temp[53]) temp[53:37]<=temp[53:37]^polynomial;
               else if(temp[52]) temp[52:36]<=temp[52:36]^polynomial;
               else if(temp[51]) temp[51:35]<=temp[51:35]^polynomial;
               else if(temp[50]) temp[50:34]<=temp[50:34]^polynomial;
               else if(temp[49]) temp[49:33]<=temp[49:33]^polynomial;
               else if(temp[48]) temp[48:32]<=temp[48:32]^polynomial;
               else if(temp[47]) temp[47:31]<=temp[47:31]^polynomial;
               else if(temp[46]) temp[46:30]<=temp[46:30]^polynomial;
               else if(temp[45]) temp[45:29]<=temp[45:29]^polynomial;
               else if(temp[44]) temp[44:28]<=temp[44:28]^polynomial;
               else if(temp[43]) temp[43:27]<=temp[43:27]^polynomial;
               else if(temp[42]) temp[42:26]<=temp[42:26]^polynomial;
               else if(temp[41]) temp[41:25]<=temp[41:25]^polynomial;
               else if(temp[40]) temp[40:24]<=temp[40:24]^polynomial;
               else if(temp[39]) temp[39:23]<=temp[39:23]^polynomial;
               else if(temp[38]) temp[38:22]<=temp[38:22]^polynomial;
               else if(temp[37]) temp[37:21]<=temp[37:21]^polynomial;
               else if(temp[36]) temp[36:20]<=temp[36:20]^polynomial;
               else if(temp[35]) temp[35:19]<=temp[35:19]^polynomial;
               else if(temp[34]) temp[34:18]<=temp[34:18]^polynomial;
               else if(temp[33]) temp[33:17]<=temp[33:17]^polynomial;
               else if(temp[32]) temp[32:16]<=temp[32:16]^polynomial;
               else if(temp[31]) temp[31:15]<=temp[31:15]^polynomial;
               else if(temp[30]) temp[30:14]<=temp[30:14]^polynomial;
               else if(temp[29]) temp[29:13]<=temp[29:13]^polynomial;
               else if(temp[28]) temp[28:12]<=temp[28:12]^polynomial;
               else if(temp[27]) temp[27:11]<=temp[27:11]^polynomial;
               else if(temp[26]) temp[26:10]<=temp[26:10]^polynomial;
               else if(temp[25]) temp[25:9]<=temp[25:9]^polynomial;
               else if(temp[24]) temp[24:8]<=temp[24:8]^polynomial;
               else if(temp[23]) temp[23:7]<=temp[23:7]^polynomial;
               else if(temp[22]) temp[22:6]<=temp[22:6]^polynomial;
               else if(temp[21]) temp[21:5]<=temp[21:5]^polynomial;
               else if(temp[20]) temp[20:4]<=temp[20:4]^polynomial;
               else if(temp[19]) temp[19:3]<=temp[19:3]^polynomial;
               else if(temp[18]) temp[18:2]<=temp[18:2]^polynomial;
               else if(temp[17]) temp[17:1]<=temp[17:1]^polynomial;
               else if(temp[16]) temp[16:0]<=temp[16:0]^polynomial;
               else begin  crc_16<=temp[15:0];  hash_complete <= 1;end               
               end
			   else if(hash_enable)begin
					temp<=stemp;
					temp_flag<=1;
			   end
               else begin 
					hash_complete<=0;
					temp_flag<=0;
			   end
        end  
endmodule

 

你可能感兴趣的:(FPGA,FPGA,CRC16,x16,x12,x5,1)