Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

crc16.h

00001 /* Copyright (c) 2002, Marek Michalkiewicz
00002    All rights reserved.
00003 
00004    Redistribution and use in source and binary forms, with or without
00005    modification, are permitted provided that the following conditions are met:
00006 
00007    * Redistributions of source code must retain the above copyright
00008      notice, this list of conditions and the following disclaimer.
00009    * Redistributions in binary form must reproduce the above copyright
00010      notice, this list of conditions and the following disclaimer in
00011      the documentation and/or other materials provided with the
00012      distribution.
00013 
00014   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00015   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00017   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00018   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00019   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00020   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00021   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00022   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00023   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00024   POSSIBILITY OF SUCH DAMAGE. */
00025 
00026 /*
00027    avr/crc16.h - optimized CRC-16
00028 
00029    Polynomial: x^16 + x^15 + x^2 + 1 (0xa001)
00030    Initial value: 0xffff
00031 
00032    See the Dallas Semiconductor app note 27 for 8051 assembler example
00033    and general CRC optimization suggestions.
00034  */
00035 
00036 #ifndef _AVR_CRC16_H_
00037 #define _AVR_CRC16_H_
00038 
00039 static inline unsigned int
00040 _crc16_update(unsigned int __crc, unsigned char __data)
00041 {
00042         unsigned char __tmp;
00043         unsigned int __ret;
00044 
00045         __asm__ (
00046                 "eor %A0,%2" "\n\t"
00047                 "mov %1,%A0" "\n\t"
00048                 "swap %1" "\n\t"
00049                 "eor %1,%A0" "\n\t"
00050                 "mov __tmp_reg__,%1" "\n\t"
00051                 "lsr %1" "\n\t"
00052                 "lsr %1" "\n\t"
00053                 "eor %1,__tmp_reg__" "\n\t"
00054                 "mov __tmp_reg__,%1" "\n\t"
00055                 "lsr %1" "\n\t"
00056                 "eor %1,__tmp_reg__" "\n\t"
00057                 "andi %1,0x07" "\n\t"
00058                 "mov __tmp_reg__,%A0" "\n\t"
00059                 "mov %A0,%B0" "\n\t"
00060                 "lsr %1" "\n\t"
00061                 "ror __tmp_reg__" "\n\t"
00062                 "ror %1" "\n\t"
00063                 "mov %B0,__tmp_reg__" "\n\t"
00064                 "eor %A0,%1" "\n\t"
00065                 "lsr __tmp_reg__" "\n\t"
00066                 "ror %1" "\n\t"
00067                 "eor %B0,__tmp_reg__" "\n\t"
00068                 "eor %A0,%1"
00069                 : "=r" (__ret), "=d" (__tmp)
00070                 : "r" (__data), "0" (__crc)
00071                 : "r0"
00072         );
00073         return __ret;
00074 }
00075 
00076 #endif /* _AVR_CRC16_H_ */

Generated on Thu Jan 30 22:30:44 2003 for EduNet by doxygen1.2.18