crc16.h

Go to the documentation of this file.
00001 /** \addtogroup lib
00002  * @{ */
00003 
00004 /**
00005  * \defgroup crc16 Cyclic Redundancy Check 16 (CRC16) calculation
00006  *
00007  * The Cyclic Redundancy Check 16 is a hash function that produces a
00008  * checksum that is used to detect errors in transmissions. The CRC16
00009  * calculation module is an iterative CRC calculator that can be used
00010  * to cumulatively update a CRC checksum for every incoming byte.
00011  *
00012  * @{
00013  */
00014 
00015 /**
00016  * \file
00017  *         Header file for the CRC16 calculcation
00018  * \author
00019  *         Adam Dunkels <adam@sics.se>
00020  *
00021  */
00022 
00023 /*
00024  * Copyright (c) 2005, Swedish Institute of Computer Science
00025  * All rights reserved.
00026  *
00027  * Redistribution and use in source and binary forms, with or without
00028  * modification, are permitted provided that the following conditions
00029  * are met:
00030  * 1. Redistributions of source code must retain the above copyright
00031  *    notice, this list of conditions and the following disclaimer.
00032  * 2. Redistributions in binary form must reproduce the above copyright
00033  *    notice, this list of conditions and the following disclaimer in the
00034  *    documentation and/or other materials provided with the distribution.
00035  * 3. Neither the name of the Institute nor the names of its contributors
00036  *    may be used to endorse or promote products derived from this software
00037  *    without specific prior written permission.
00038  *
00039  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00040  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00041  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00042  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00043  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00044  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00045  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00046  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00047  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00048  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00049  * SUCH DAMAGE.
00050  *
00051  * This file is part of the Contiki operating system.
00052  *
00053  * @(#)$Id: crc16.h,v 1.4 2008/10/15 14:17:28 nvt-se Exp $
00054  */
00055 #ifndef __CRC16_H__
00056 #define __CRC16_H__
00057 
00058 /**
00059  * \brief      Update an accumulated CRC16 checksum with one byte.
00060  * \param b    The byte to be added to the checksum
00061  * \param crc  The accumulated CRC that is to be updated.
00062  * \return     The updated CRC checksum.
00063  *
00064  *             This function updates an accumulated CRC16 checksum
00065  *             with one byte. It can be used as a running checksum, or
00066  *             to checksum an entire data block.
00067  *
00068  *             \note The algorithm used in this implementation is
00069  *             tailored for a running checksum and does not perform as
00070  *             well as a table-driven algorithm when checksumming an
00071  *             entire data block.
00072  *
00073  */
00074 unsigned short crc16_add(unsigned char b, unsigned short crc);
00075 
00076 /**
00077  * \brief      Calculate the CRC16 over a data area
00078  * \param data Pointer to the data
00079  * \param datalen The length of the data
00080  * \param crc  The accumulated CRC that is to be updated (or zero).
00081  * \return     The CRC16 checksum.
00082  *
00083  *             This function calculates the CRC16 checksum of a data area.
00084  *
00085  *             \note The algorithm used in this implementation is
00086  *             tailored for a running checksum and does not perform as
00087  *             well as a table-driven algorithm when checksumming an
00088  *             entire data block.
00089  */
00090 unsigned short crc16_data(const unsigned char *data, int datalen,
00091                           unsigned short acc);
00092 
00093 #endif /* __CRC16_H__ */
00094 
00095 /** @} */
00096 /** @} */

Generated on Mon Apr 11 14:23:28 2011 for Contiki 2.5 by  doxygen 1.6.1