Verilog自动生成 CRC 校验代码

CRC 循环冗余码

表示形式:多项式G(x):G(x) = X4+X3+1

假设:输入数据 Data,选定的多项式G(x)是x4 + x3 + 1.
所以G(M) = 11001.
CRC = Data mod G
注:CRC的位数要始终比G少1位,因为余数肯定比除数小且只小1位,高位为0不能省略

CRC校验码的产生方式:模2除法

在这里插入图片描述示例:
在这里插入图片描述
在这里插入图片描述

发送端通过CRC校验码将Data转换成NewData发送;
接收端接收到NewData对同样的G(M)进行模2运算,若没有余数,则数据正确传输,否则传输出现错误。

CRC代码生成链接
在这里插入图片描述
在这里插入图片描述代码示例


// Copyright (C) 1999-2008 Easics NV.
// This source file may be used and distributed without restriction
// provided that this copyright statement is not removed from the file
// and that any derivative work contains the original copyright notice
// and the associated disclaimer.
//
// THIS SOURCE FILE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
// WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Purpose : synthesizable CRC function
//   * polynomial: x^8 + x^5 + x^3 + x^2 + x^1 + 1
//   * data width: 24
//
// Info : tools@easics.be
//        http://www.easics.com

module CRC8_D24;

  // polynomial: x^8 + x^5 + x^3 + x^2 + x^1 + 1
  // data width: 24
  // convention: the first serial bit is D[23]
  function [7:0] nextCRC8_D24;

    input [23:0] Data;
    input [7:0] crc;
    reg [23:0] d;
    reg [7:0] c;
    reg [7:0] newcrc;
  begin
    d = Data;
    c = crc;

    newcrc[0] = d[23] ^ d[22] ^ d[21] ^ d[15] ^ d[12] ^ d[11] ^ d[10] ^ d[9] ^ d[8] ^ d[7] ^ d[5] ^ d[3] ^ d[0] ^ c[5] ^ c[6] ^ c[7];
    newcrc[1] = d[21] ^ d[16] ^ d[15] ^ d[13] ^ d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[0] ^ c[5];
    newcrc[2] = d[23] ^ d[21] ^ d[17] ^ d[16] ^ d[15] ^ d[14] ^ d[12] ^ d[11] ^ d[10] ^ d[9] ^ d[6] ^ d[4] ^ d[3] ^ d[2] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[5] ^ c[7];
    newcrc[3] = d[23] ^ d[21] ^ d[18] ^ d[17] ^ d[16] ^ d[13] ^ d[9] ^ d[8] ^ d[4] ^ d[2] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[2] ^ c[5] ^ c[7];
    newcrc[4] = d[22] ^ d[19] ^ d[18] ^ d[17] ^ d[14] ^ d[10] ^ d[9] ^ d[5] ^ d[3] ^ d[2] ^ d[1] ^ c[1] ^ c[2] ^ c[3] ^ c[6];
    newcrc[5] = d[22] ^ d[21] ^ d[20] ^ d[19] ^ d[18] ^ d[12] ^ d[9] ^ d[8] ^ d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[2] ^ d[0] ^ c[2] ^ c[3] ^ c[4] ^ c[5] ^ c[6];
    newcrc[6] = d[23] ^ d[22] ^ d[21] ^ d[20] ^ d[19] ^ d[13] ^ d[10] ^ d[9] ^ d[8] ^ d[7] ^ d[6] ^ d[5] ^ d[3] ^ d[1] ^ c[3] ^ c[4] ^ c[5] ^ c[6] ^ c[7];
    newcrc[7] = d[23] ^ d[22] ^ d[21] ^ d[20] ^ d[14] ^ d[11] ^ d[10] ^ d[9] ^ d[8] ^ d[7] ^ d[6] ^ d[4] ^ d[2] ^ c[4] ^ c[5] ^ c[6] ^ c[7];
    nextCRC8_D24 = newcrc;
  end
  endfunction
endmodule
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值