Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RHCRC.cpp
00001 /* Copyright (c) 2002, 2003, 2004 Marek Michalkiewicz 00002 Copyright (c) 2005, 2007 Joerg Wunsch 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright 00009 notice, this list of conditions and the following disclaimer. 00010 00011 * Redistributions in binary form must reproduce the above copyright 00012 notice, this list of conditions and the following disclaimer in 00013 the documentation and/or other materials provided with the 00014 distribution. 00015 00016 * Neither the name of the copyright holders nor the names of 00017 contributors may be used to endorse or promote products derived 00018 from this software without specific prior written permission. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00024 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 POSSIBILITY OF SUCH DAMAGE. */ 00031 00032 // Port to Energia / MPS430 by Yannick DEVOS XV4Y - (c) 2013 00033 // http://xv4y.radioclub.asia/ 00034 // 00035 00036 // Adapted to RadioHead use by Mike McCauley 2014 00037 // This is to prevent name collisions with other similar library functions 00038 // and to provide a consistent API amonng all processors 00039 // 00040 00041 /* $Id: RHCRC.cpp,v 1.1 2014/06/24 02:40:12 mikem Exp $ */ 00042 00043 #include <RHCRC.h> 00044 00045 #define lo8(x) ((x)&0xff) 00046 #define hi8(x) ((x)>>8) 00047 00048 uint16_t RHcrc16_update(uint16_t crc, uint8_t a) 00049 { 00050 int i; 00051 00052 crc ^= a; 00053 for (i = 0; i < 8; ++i) 00054 { 00055 if (crc & 1) 00056 crc = (crc >> 1) ^ 0xA001; 00057 else 00058 crc = (crc >> 1); 00059 } 00060 return crc; 00061 } 00062 00063 uint16_t RHcrc_xmodem_update (uint16_t crc, uint8_t data) 00064 { 00065 int i; 00066 00067 crc = crc ^ ((uint16_t)data << 8); 00068 for (i=0; i<8; i++) 00069 { 00070 if (crc & 0x8000) 00071 crc = (crc << 1) ^ 0x1021; 00072 else 00073 crc <<= 1; 00074 } 00075 00076 return crc; 00077 } 00078 00079 uint16_t RHcrc_ccitt_update (uint16_t crc, uint8_t data) 00080 { 00081 data ^= lo8 (crc); 00082 data ^= data << 4; 00083 00084 return ((((uint16_t)data << 8) | hi8 (crc)) ^ (uint8_t)(data >> 4) 00085 ^ ((uint16_t)data << 3)); 00086 } 00087 00088 uint8_t RHcrc_ibutton_update(uint8_t crc, uint8_t data) 00089 { 00090 uint8_t i; 00091 00092 crc = crc ^ data; 00093 for (i = 0; i < 8; i++) 00094 { 00095 if (crc & 0x01) 00096 crc = (crc >> 1) ^ 0x8C; 00097 else 00098 crc >>= 1; 00099 } 00100 00101 return crc; 00102 } 00103 00104
Generated on Tue Jul 12 2022 18:05:56 by
1.7.2