| Remote Access Control |

# crc.c File Reference

## Detailed Description

Source file for CRC public and support functions.

This file contains the function implementation for the CRC generation functions. Refer to the crc.h file for more details.

- File: crc.c
- Compiler: IAR EWAVR 4.11B
- Supported devices: ATtiny45/85
- AppNote: AVR411 - Secure Rolling Code Algorithm for Wireless Link

Author:
  Atmel Corporation: http://www.atmel.com
  Support email: avr@atmel.com

Name

Revision
  1193

Date
  2006-10-31 14:21:08 +0100 (ti, 31 okt 2006)

Copyright (c) 2006, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file crc.c.

`#include "crc.h"`
`#include "common.h"`
`#include "config.h"`

Include dependency graph for crc.c:

Go to the source code of this file.

## Functions
void | calcCRC (byte nextByte)
void | initCRC (void)
## Variables
byte | CRCReg [3]

## Function Documentation

void calcCRC | ( | byte | nextByte | ) |

Process one byte of the message. Also used for the last two 0-bytes.

Definition at line 67 of file crc.c.

References CRC_POLY, and CRCReg.

Referenced by transmitTeachMessage().

    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 }

void initCRC | ( | void |  | ) |

Initializes CRCReg before processing a message.

Definition at line 58 of file crc.c.

References CRCReg.

Referenced by transmitTeachMessage().

    00059 {
    00060         CRCReg[0] = 0xff;
    00061         CRCReg[1] = 0xff;
    00062         CRCReg[2] = 0x00; // Always 0x00. See comment in crc.h file.
    00063 }

## Variable Documentation

byte CRCReg[3]

Stores CRC value during calculation.

Definition at line 54 of file crc.c.

Referenced by calcCRC(), initCRC(), and transmitTeachMessage().

@DOC_TITLE@