crc.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * crc.h
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2003 Steve Underwood
00009  *
00010  * All rights reserved.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 2.1,
00014  * as published by the Free Software Foundation.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  */
00025 
00026 /*! \file */
00027 
00028 /*! \page crc_page CRC
00029 
00030 \section crc_page_sec_1 What does it do?
00031 
00032 \section crc_page_sec_2 How does it work?
00033 */
00034 
00035 #if !defined(_SPANDSP_CRC_H_)
00036 #define _SPANDSP_CRC_H_
00037 
00038 #if defined(__cplusplus)
00039 extern "C"
00040 {
00041 #endif
00042 
00043 /*! \brief Calculate the ITU/CCITT CRC-32 value in buffer.
00044     \param buf The buffer containing the data.
00045     \param len The length of the frame.
00046     \param crc The initial CRC value. This is usually 0xFFFFFFFF, or 0 for a new block (it depends on
00047            the application). It is previous returned CRC value for the continuation of a block.
00048     \return The CRC value.
00049 */
00050 SPAN_DECLARE(uint32_t) crc_itu32_calc(const uint8_t *buf, int len, uint32_t crc);
00051 
00052 /*! \brief Append an ITU/CCITT CRC-32 value to a frame.
00053     \param buf The buffer containing the frame. This must be at least 2 bytes longer than
00054                the frame it contains, to allow room for the CRC value.
00055     \param len The length of the frame.
00056     \return The new length of the frame.
00057 */
00058 SPAN_DECLARE(int) crc_itu32_append(uint8_t *buf, int len);
00059 
00060 /*! \brief Check the ITU/CCITT CRC-32 value in a frame.
00061     \param buf The buffer containing the frame.
00062     \param len The length of the frame.
00063     \return TRUE if the CRC is OK, else FALSE.
00064 */
00065 SPAN_DECLARE(int) crc_itu32_check(const uint8_t *buf, int len);
00066 
00067 /*! \brief Calculate the ITU/CCITT CRC-16 value in buffer by whole bytes.
00068     \param buf The buffer containing the data.
00069     \param len The length of the frame.
00070     \param crc The initial CRC value. This is usually 0xFFFF, or 0 for a new block (it depends on
00071            the application). It is previous returned CRC value for the continuation of a block.
00072     \return The CRC value.
00073 */
00074 SPAN_DECLARE(uint16_t) crc_itu16_calc(const uint8_t *buf, int len, uint16_t crc);
00075 
00076 /*! \brief Calculate the ITU/CCITT CRC-16 value of some bits from a byte.
00077     \param buf The buffer containing the byte of data.
00078     \param len The number of bits, starting from the LSB.
00079     \param crc The initial CRC value. This is usually 0xFFFF, or 0 for a new block (it depends on
00080            the application). It is previous returned CRC value for the continuation of a block.
00081     \return The CRC value.
00082 */
00083 SPAN_DECLARE(uint16_t) crc_itu16_bits(uint8_t buf, int len, uint16_t crc);
00084 
00085 /*! \brief Append an ITU/CCITT CRC-16 value to a frame.
00086     \param buf The buffer containing the frame. This must be at least 2 bytes longer than
00087                the frame it contains, to allow room for the CRC value.
00088     \param len The length of the frame.
00089     \return The new length of the frame.
00090 */
00091 SPAN_DECLARE(int) crc_itu16_append(uint8_t *buf, int len);
00092 
00093 /*! \brief Check the ITU/CCITT CRC-16 value in a frame.
00094     \param buf The buffer containing the frame.
00095     \param len The length of the frame.
00096     \return TRUE if the CRC is OK, else FALSE.
00097 */
00098 SPAN_DECLARE(int) crc_itu16_check(const uint8_t *buf, int len);
00099 
00100 #if defined(__cplusplus)
00101 }
00102 #endif
00103 
00104 #endif
00105 /*- End of file ------------------------------------------------------------*/

Generated on 18 Oct 2012 for spandsp by  doxygen 1.6.1