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[3];
00055 
00056 
00057 
00058 void initCRC(void)
00059 {
00060         CRCReg[0] = 0xff;
00061         CRCReg[1] = 0xff;
00062         CRCReg[2] = 0x00; // Always 0x00. See comment in crc.h file.
00063 }
00064 
00065 
00066 
00067 void calcCRC( byte nextByte )
00068 {
00069         byte reg0 = CRCReg[0];
00070         byte reg1 = CRCReg[1];
00071         byte tempByte = nextByte;
00072         byte count = 8;
00073         do {
00074                 if( reg0 >> 7 ) {
00075                         reg0 = (reg0 << 1) | (reg1 >> 7);
00076                         reg1 = (reg1 << 1) | (tempByte >> 7);
00077                         tempByte <<= 1;
00078 
00079                         reg0 ^= CRC_POLY >> 8;
00080                         reg1 ^= CRC_POLY & 0xff;
00081                 } else {
00082                         reg0 = (reg0 << 1) | (reg1 >> 7);
00083                         reg1 = (reg1 << 1) | (tempByte >> 7);
00084                         tempByte <<= 1;
00085                 }
00086         } while( --count );
00087 
00088         CRCReg[0] = reg0;
00089         CRCReg[1] = reg1;
00090 }
00091 
@DOC_TITLE@
Generated on Fri Aug 8 11:03:16 2008 for AVR411 Secure Rolling Code Algorithm (Transmitter) by doxygen 1.4.7