| Remote Access Control |

# crc.c

Go to the documentation of this file.

    00001 // This file has been prepared for Doxygen automatic documentation generation.
    00048 #include "crc.h"
    00049 #include "common.h"
    00050 #include "config.h"
    00051
    00052
    00053
    00054 byte CRCReg[2];
    00055
    00056
    00057
    00058 void initCRC(void)
    00059 {
    00060         CRCReg[0] = 0xff;
    00061         CRCReg[1] = 0xff;
    00062 }
    00063
    00064
    00065
    00066 void calcCRC( byte nextByte )
    00067 {
    00068         byte reg0 = CRCReg[0];
    00069         byte reg1 = CRCReg[1];
    00070         byte tempByte = nextByte;
    00071         byte count = 8;
    00072         do {
    00073                 if( reg0 >> 7 ) {
    00074                         reg0 = (reg0 << 1) | (reg1 >> 7);
    00075                         reg1 = (reg1 << 1) | (tempByte >> 7);
    00076                         tempByte <<= 1;
    00077
    00078                         reg0 ^= POLY >> 8;
    00079                         reg1 ^= POLY & 0xff;
    00080                 } else {
    00081                         reg0 = (reg0 << 1) | (reg1 >> 7);
    00082                         reg1 = (reg1 << 1) | (tempByte >> 7);
    00083                         tempByte <<= 1;
    00084                 }
    00085         } while( --count );
    00086
    00087         CRCReg[0] = reg0;
    00088         CRCReg[1] = reg1;
    00089 }
    00090

@DOC_TITLE@