Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeEnglishEspañolContact

The text of a manual · part 14 of 16

4985 Network Controller Programmer's Guide: Appendix C: CRC Checking with Asynchronous Interface

Pages 105 to 108 of 130, from 4985 Network Controller Programmer's Guide

The original document is the PDF (762 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

Filed in the catalog under the Norand Route Commander 4000 Series APU

Page 105

Appendix C CRC Checking with Asynchronous Interface "

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

Cyclical Redundancy Checking (CRC) is a method that verifies the integrity of data. It works by processing a block of data, bit by bit, with a known arithmetic algorithm designed to detect data errors. The NORANDâ Controller has an option to enable this detection for data transferred between the host and the controller to ensure that data has not been corrupted. This 16-bit CRC checking and encoding is performed on data records only. If CRC checking is enabled in the initialization record, all data (type “0”) records have the following format: "

4985 data records

<channel ID><record type “0”><256 bytes of data><2-byte CRC> "

Host data records

/0<256 bytes data><CRC byte><CRC byte> -S8129 enables CRC checking in the system mode parameter in the initialization record sent to the 4985 from the host. The system mode parameter is the -S<system_mode> parameter in the initialization record (see page 4-20). The sample “C” subroutine, CRCCALC, calculates a 16-bit CRC (CRCCCITT) on the data buffer. If addcrc is true, the calculated CRC is returned in unsigned character variable crcbytes. Otherwise, the calculated value is compared against the value passed in crcbytes and a non-zero error code is returned if the comparison fails. This routine performs the byte-wise calculation on the fly. A faster implementation would include generating a CRC lookup table and using it to look up the CRC rather than calculating it. int crccalc (char* header, int hsize, unsigned char* crcbytes, int addcrc) 4985 Network Controller Programmer’s Guide

C-1

Page 106

APPENDIX C

"

CRC Checking with Asynchronous Interface unsigned int crccalc(unsigned char *buffer, unsigned int size, unsigned int addcrc); /******************************************************* * CALCULATE CRC FOR BUFFER * * inputs: * * buffer - contains information to calculate crc * * size size of buffer to process * * addcrc - if nonzero, add 2 crc bytes to end of * * block. * * if zero, calculate and compare crc to * * last 2 bytes. * * returns: * * 0 = good crc * * 1 = bad crc * *******************************************************/ unsigned int crccalc(unsigned char *buffer, unsigned int size, unsigned int addcrc) { register int i; register int crc; char* ptr; int count; count=size; crc=0; ptr=buffer; while (--count >= 0) { crc=(int) *ptr++ << 8; for (i=0; i<8; i++) { crc=((crc & 0x8000_ ? 0x1021 : 0) ^ (crc << 1); } } if (addcrc) { buffer[size]=(0xff00 & crc) >> 8; buffer[size+1]=(0x00ff & crc); } else if (buffer[size] !=(unsigned)((0xff00 * crc)>>8) || C-2

4985 Network Controller Programmer’s Guide

Page 107

APPENDIX C

"

CRC Checking with Asynchronous Interface buffer[size+1] !=(unsigned)(0x00ff & crc)) return(1); return(0); } { if (ptr) /*headr or buf may be NULL*/ { while ( -- count >= 0) { crc ^=(int)*ptr++ << 8; for (i=0);i < 8; i++) { crc=((crc&0x8000)) ?0x1021:0)^(crc<<1); } } } ptr=buf; count=bsize; } if (addcrc) { crcbytes[0]=(0xff00&crc)>>8; crcbytes[1]=(0x00ff&crc); } else if (crcbytes[0]!=(unsigned)((0xff00&crc)>>8) || crcbytes[1]!=(unsigned)(0x00ff&crc)) { return -1; } return 0; }

4985 Network Controller Programmer’s Guide

C-3

Page 108

APPENDIX C

C-4

"

CRC Checking with Asynchronous Interface

4985 Network Controller Programmer’s Guide