LCDproc development and user support list

Text archives Help


[Lcdproc] "CLEAN" CRC algorithm for Crystalfontz CFA-633 & CFA-631


Chronological Thread 
  • From: brent AT crystalfontz.com (Brent A. Crosby)
  • Subject: [Lcdproc] "CLEAN" CRC algorithm for Crystalfontz CFA-633 & CFA-631
  • Date: Fri Jun 25 14:36:02 2004

LCDproc development team:

Since there has been some question as to whether the CRC=
algorithm in the sample code we provide is clean enough for the=
GPL, I have coded a new algorithm. This algorithm comes directly=
from the "shift & xor" hardware CRC definition (and my=
keyboard), so that there is no question of its origin or=
ownership.

I have also updated the headers of the sample code so that=
hopefully the sample code will be easier for you to integrate=
into the GPL code.

The complete project is here:

http://www.crystalfontz.com/backlight/633/633_WinTest_CLEAN_CRC.z=
ip

The clean CRC code is in in serial.cpp, look for=
"CLEAN_CRC_SOURCE". Here is a copy for reference:

typedef unsigned char ubyte;
typedef unsigned short word;
word get_crc(ubyte *bufptr,word len)
{
register unsigned int
newCRC;
//Put the current byte in here.
ubyte
data;
int
bit_count;
//This seed makes the output of this shift based algorithm=
match
//the table based algorithm. The center 16 bytes of the 32-bit
//"newCRC" are used for the CRC. The MSb of the lower byte is=
used
//to see what bit was shifted out of the center 16 bit CRC
//accumulator ("carry flag analog");
newCRC=3D0x00F32100;
while(len--)
{
//Get the next byte in the stream.
data=3D*bufptr++;
//Push this byte's bits through a software
//implementation of a hardware shift & xor.
for(bit_count=3D0;bit_count<=3D7;bit_count++)
{
//Shift the CRC accumulator
newCRC>>=3D1;

//The new MSB of the CRC accumulator comes
//from the LSB of the current data byte.
if(data&0x01)
newCRC|=3D0x00800000;

//If the low bit of the current CRC accumulator was set
//before the shift, then we need to XOR the accumulator
//with the polynomial (center 16 bits of 0x00840800)
if(newCRC&0x00000080)
newCRC^=3D0x00840800;
//Shift the data byte to put the next bit of the stream
//into position 0.
data>>=3D1;
}
}

//All the data has been done. Do 16 more bits of 0 data.
for(bit_count=3D0;bit_count<=3D15;bit_count++)
{
//Shift the CRC accumulator
newCRC>>=3D1;

//If the low bit of the current CRC accumulator was set
//before the shift we need to XOR the accumulator with
//0x00840800.
if(newCRC&0x00000080)
newCRC^=3D0x00840800;
}
//Return the center 16 bits, making this CRC match the one's
//complement that is sent in the packet.
return((~newCRC)>>8);
}

Hopefully with this new clean code the CFA-633 and CFA-631 can be=
integrated back into the release and nightly builds of LCDproc.

Thank you for your support of the Crystalfontz modules in=
LCDproc.

| Brent A. Crosby
| Crystalfontz America, Incorporated
| 15611 East Washington Road
| Valleyford, WA 99036
|
brent AT crystalfontz.com
http://www.crystalfontz.com
| voice (509) 291-3514 fax (509) 291-3345 US toll-free (888)=
206-9720




  • [Lcdproc] "CLEAN" CRC algorithm for Crystalfontz CFA-633 & CFA-631, Brent A. Crosby, 06/25/2004

Archive powered by MHonArc 2.6.18.

Top of page