- 1、求並行 CRC8 的 verilog 代碼,多項式為 X8+X5+X4+X3+1(0x39)
- 2、用C語言編寫,crc8校驗9個字節的數據,生成多項式為x8+x2+x+1,
- 3、CRC校驗的算法有幾種?
- 4、如何用java實現CRC8驗證算法
- 5、CAN總線通信里的這個字符的CRC運算是CRC8,還是CRC16還是CRC32運算?
- 6、nodejs 怎麼執行 crc32
在線生成工具
這個生成的是function,不可綜合的。自己改成module就行了
////////////////////////////////////////////////////////////////////////////////
// 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: (0 3 4 5 8)
// * data width: 8
//
// Info : tools@easics.be
//
////////////////////////////////////////////////////////////////////////////////
module CRC8_D8;
// polynomial: (0 3 4 5 8)
// data width: 8
// convention: the first serial bit is D[7]
function [7:0] nextCRC8_D8;
input [7:0] Data;
input [7:0] crc;
reg [7:0] d;
reg [7:0] c;
reg [7:0] newcrc;
begin
d = Data;
c = crc;
newcrc[0] = d[6] ^ d[5] ^ d[4] ^ d[3] ^ d[0] ^ c[0] ^ c[3] ^ c[4] ^ c[5] ^ c[6];
newcrc[1] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[1] ^ c[1] ^ c[4] ^ c[5] ^ c[6] ^ c[7];
newcrc[2] = d[7] ^ d[6] ^ d[5] ^ d[2] ^ c[2] ^ c[5] ^ c[6] ^ c[7];
newcrc[3] = d[7] ^ d[5] ^ d[4] ^ d[0] ^ c[0] ^ c[4] ^ c[5] ^ c[7];
newcrc[4] = d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[3] ^ c[4];
newcrc[5] = d[6] ^ d[3] ^ d[2] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[2] ^ c[3] ^ c[6];
newcrc[6] = d[7] ^ d[4] ^ d[3] ^ d[2] ^ d[1] ^ c[1] ^ c[2] ^ c[3] ^ c[4] ^ c[7];
newcrc[7] = d[5] ^ d[4] ^ d[3] ^ d[2] ^ c[2] ^ c[3] ^ c[4] ^ c[5];
nextCRC8_D8 = newcrc;
end
endfunction
endmodule
// 8bit CRC (X(8) + X(2) + X(1) + 1)
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned char BYTE;
#define AL2_FCS_COEF ((1 7) + (1 6) + (1 5))
//data為指向校驗數據的指針,length為長度,返回一個字節的校驗碼
BYTE GetCrc8(unsigned char * data, int length)
{
BYTE cFcs = 0;
int i, j;
for( i = 0; i length; i ++ )
{
cFcs ^= data[i];
for(j = 0; j 8; j ++)
{
if(cFcs 1)
{
cFcs = (BYTE)((cFcs 1) ^ AL2_FCS_COEF);
}
else
{
cFcs = 1;
}
}
}
return cFcs;
}
具體的找些參考資料吧,一兩句話也說不清楚
;hl=zh-CNct=clnkcd=1gl=cnst_usg=ALhdy2_AJ0YjhnCWFMb5xtYPvXTzPgd_2Q
下面的還有程序實現:
/*
*—————————————————————————
* Copyright (C) 1999,2000 Dallas Semiconductor Corporation, All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the “Software”),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Dallas Semiconductor
* shall not be used except as stated in the Dallas Semiconductor
* Branding Policy.
*—————————————————————————
*/
package com.dalsemi.onewire.utils;
/**
* CRC8 is a class to contain an implementation of the
* Cyclic-Redundency-Check CRC8 for the iButton. The CRC8 is used
* in the 1-Wire Network address of all iButtons and 1-Wire
* devices.
* p
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @version 0.00, 28 Aug 2000
* @author DS
*
*/
public class CRC8
{
//——–
//——– Variables
//——–
/**
* CRC 8 lookup table
*/
private static byte dscrc_table [];
/*
* Create the lookup table
*/
static
{
//Translated from the assembly code in iButton Standards, page 129.
dscrc_table = new byte [256];
int acc;
int crc;
for (int i = 0; i 256; i++)
{
acc = i;
crc = 0;
for (int j = 0; j 8; j++)
{
if (((acc ^ crc) 0x01) == 0x01)
{
crc = ((crc ^ 0x18) 1) | 0x80;
}
else
crc = crc 1;
acc = acc 1;
}
dscrc_table [i] = ( byte ) crc;
}
}
//——–
//——– Constructor
//——–
/**
* Private constructor to prevent instantiation.
*/
private CRC8 ()
{
}
//——–
//——– Methods
//——–
/**
* Perform the CRC8 on the data element based on the provided seed.
* p
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc data element on which to perform the CRC8
* @param seed seed the CRC8 with this value
* @return CRC8 value
*/
public static int compute (int dataToCRC, int seed)
{
return (dscrc_table [(seed ^ dataToCRC) 0x0FF] 0x0FF);
}
/**
* Perform the CRC8 on the data element based on a zero seed.
* p
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc data element on which to perform the CRC8
* @return CRC8 value
*/
public static int compute (int dataToCRC)
{
return (dscrc_table [dataToCRC 0x0FF] 0x0FF);
}
/**
* Perform the CRC8 on an array of data elements based on a
* zero seed.
* p
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc array of data elements on which to perform the CRC8
* @return CRC8 value
*/
public static int compute (byte dataToCrc [])
{
return compute(dataToCrc, 0, dataToCrc.length);
}
/**
* Perform the CRC8 on an array of data elements based on a
* zero seed.
* p
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc array of data elements on which to perform the CRC8
* @param off offset into array
* @param len length of data to crc
* @return CRC8 value
*/
public static int compute (byte dataToCrc [], int off, int len)
{
return compute(dataToCrc, off, len, 0);
}
/**
* Perform the CRC8 on an array of data elements based on the
* provided seed.
* p
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc array of data elements on which to perform the CRC8
* @param off offset into array
* @param len length of data to crc
* @param seed seed to use for CRC8
* @return CRC8 value
*/
public static int compute (byte dataToCrc [], int off, int len, int seed)
{
// loop to do the crc on each data element
int CRC8 = seed;
for (int i = 0; i len; i++)
CRC8 = dscrc_table [(CRC8 ^ dataToCrc [i + off]) 0x0FF];
return (CRC8 0x0FF);
}
/**
* Perform the CRC8 on an array of data elements based on the
* provided seed.
* p
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc array of data elements on which to perform the CRC8
* @param seed seed to use for CRC8
* @return CRC8 value
*/
public static int compute (byte dataToCrc [], int seed)
{
return compute(dataToCrc, 0, dataToCrc.length, seed);
}
}
CAN總線的CRC場共16bit,其中最後1bit為CRC序列後隨的CRC界定符僅由單個“隱性”位構成。所以用於CRC校驗的是15bit即CRC15。用於幀校驗的CRC序列由特別適用於位數小於127位幀的循環冗餘碼校驗(BCH碼)驅動。為實現CRC計算,被除的多項式被定義為這樣一個多項式,其係數由幀起始、仲裁場、控制場、數據場(如果存在)和15位最低係數為0組成的解除填充的位流給定。此多項式被下列生成多項式
X15+X14+X10+X8+X7+X4+X3+1
除(係數按模-2計算),該多項式相除的餘數即為發至總線的CRC序列。
為實現這一功能,可以使用15位移位寄存器CRC-RG(14:0)。若NXTBIT標示由幀起始直至數據場結束的解除填充位序列給定位流的下一位,則CRC序列計算如下:
CRC—RG(14:0)=(0); //初始化移位寄存器
REPEAT
CRCNXT=NXTBIT EXOR CRC—RG(14);
CRC—RG(14:1)= CRC—RG(13:0); //左移一位
CRC—RG(0)=0;
IF CRCNXT THEN
CRC—RG(14:0)=CRC—RG(14:0)EXOR(4599H);
END IF
UNTIL(NXTBIT=數據結束或存在一個錯誤條件)。
數據場最後一位發送/接收後,CRC—RG中含有CRC序列。CRC序列後隨的CRC界定符僅由單個“隱性”位構成。
const crc=require(‘node-crc’);
var result = crc.crc32(Buffer.from(‘hello’, ‘utf8’)).toString(‘hex’);
var result2 = crc.crc64(Buffer.from(‘world’, ‘utf8’)).toString(‘hex’);
鏈接在這裡:網頁鏈接
你品,你細品
原創文章,作者:XZB0O,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/126798.html