V148

Fork of RadioHead-148 by David Rimer

Committer:
ilkaykozak
Date:
Wed Oct 25 05:14:09 2017 +0000
Revision:
1:b7641da2b203
Parent:
0:ab4e012489ef
V148

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidr99 0:ab4e012489ef 1 /* Copyright (c) 2002, 2003, 2004 Marek Michalkiewicz
davidr99 0:ab4e012489ef 2 Copyright (c) 2005, 2007 Joerg Wunsch
davidr99 0:ab4e012489ef 3 All rights reserved.
davidr99 0:ab4e012489ef 4
davidr99 0:ab4e012489ef 5 Redistribution and use in source and binary forms, with or without
davidr99 0:ab4e012489ef 6 modification, are permitted provided that the following conditions are met:
davidr99 0:ab4e012489ef 7
davidr99 0:ab4e012489ef 8 * Redistributions of source code must retain the above copyright
davidr99 0:ab4e012489ef 9 notice, this list of conditions and the following disclaimer.
davidr99 0:ab4e012489ef 10
davidr99 0:ab4e012489ef 11 * Redistributions in binary form must reproduce the above copyright
davidr99 0:ab4e012489ef 12 notice, this list of conditions and the following disclaimer in
davidr99 0:ab4e012489ef 13 the documentation and/or other materials provided with the
davidr99 0:ab4e012489ef 14 distribution.
davidr99 0:ab4e012489ef 15
davidr99 0:ab4e012489ef 16 * Neither the name of the copyright holders nor the names of
davidr99 0:ab4e012489ef 17 contributors may be used to endorse or promote products derived
davidr99 0:ab4e012489ef 18 from this software without specific prior written permission.
davidr99 0:ab4e012489ef 19
davidr99 0:ab4e012489ef 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
davidr99 0:ab4e012489ef 21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
davidr99 0:ab4e012489ef 22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
davidr99 0:ab4e012489ef 23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
davidr99 0:ab4e012489ef 24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
davidr99 0:ab4e012489ef 25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
davidr99 0:ab4e012489ef 26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
davidr99 0:ab4e012489ef 27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
davidr99 0:ab4e012489ef 28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
davidr99 0:ab4e012489ef 29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
davidr99 0:ab4e012489ef 30 POSSIBILITY OF SUCH DAMAGE. */
davidr99 0:ab4e012489ef 31
davidr99 0:ab4e012489ef 32 // Port to Energia / MPS430 by Yannick DEVOS XV4Y - (c) 2013
davidr99 0:ab4e012489ef 33 // http://xv4y.radioclub.asia/
davidr99 0:ab4e012489ef 34 //
davidr99 0:ab4e012489ef 35
davidr99 0:ab4e012489ef 36 // Adapted to RadioHead use by Mike McCauley 2014
davidr99 0:ab4e012489ef 37 // This is to prevent name collisions with other similar library functions
davidr99 0:ab4e012489ef 38 // and to provide a consistent API amonng all processors
davidr99 0:ab4e012489ef 39 //
davidr99 0:ab4e012489ef 40
davidr99 0:ab4e012489ef 41 /* $Id: RHCRC.cpp,v 1.1 2014/06/24 02:40:12 mikem Exp $ */
davidr99 0:ab4e012489ef 42
davidr99 0:ab4e012489ef 43 #include <RHCRC.h>
davidr99 0:ab4e012489ef 44
davidr99 0:ab4e012489ef 45 #define lo8(x) ((x)&0xff)
davidr99 0:ab4e012489ef 46 #define hi8(x) ((x)>>8)
davidr99 0:ab4e012489ef 47
davidr99 0:ab4e012489ef 48 uint16_t RHcrc16_update(uint16_t crc, uint8_t a)
davidr99 0:ab4e012489ef 49 {
davidr99 0:ab4e012489ef 50 int i;
davidr99 0:ab4e012489ef 51
davidr99 0:ab4e012489ef 52 crc ^= a;
davidr99 0:ab4e012489ef 53 for (i = 0; i < 8; ++i)
davidr99 0:ab4e012489ef 54 {
davidr99 0:ab4e012489ef 55 if (crc & 1)
davidr99 0:ab4e012489ef 56 crc = (crc >> 1) ^ 0xA001;
davidr99 0:ab4e012489ef 57 else
davidr99 0:ab4e012489ef 58 crc = (crc >> 1);
davidr99 0:ab4e012489ef 59 }
davidr99 0:ab4e012489ef 60 return crc;
davidr99 0:ab4e012489ef 61 }
davidr99 0:ab4e012489ef 62
davidr99 0:ab4e012489ef 63 uint16_t RHcrc_xmodem_update (uint16_t crc, uint8_t data)
davidr99 0:ab4e012489ef 64 {
davidr99 0:ab4e012489ef 65 int i;
davidr99 0:ab4e012489ef 66
davidr99 0:ab4e012489ef 67 crc = crc ^ ((uint16_t)data << 8);
davidr99 0:ab4e012489ef 68 for (i=0; i<8; i++)
davidr99 0:ab4e012489ef 69 {
davidr99 0:ab4e012489ef 70 if (crc & 0x8000)
davidr99 0:ab4e012489ef 71 crc = (crc << 1) ^ 0x1021;
davidr99 0:ab4e012489ef 72 else
davidr99 0:ab4e012489ef 73 crc <<= 1;
davidr99 0:ab4e012489ef 74 }
davidr99 0:ab4e012489ef 75
davidr99 0:ab4e012489ef 76 return crc;
davidr99 0:ab4e012489ef 77 }
davidr99 0:ab4e012489ef 78
davidr99 0:ab4e012489ef 79 uint16_t RHcrc_ccitt_update (uint16_t crc, uint8_t data)
davidr99 0:ab4e012489ef 80 {
davidr99 0:ab4e012489ef 81 data ^= lo8 (crc);
davidr99 0:ab4e012489ef 82 data ^= data << 4;
davidr99 0:ab4e012489ef 83
davidr99 0:ab4e012489ef 84 return ((((uint16_t)data << 8) | hi8 (crc)) ^ (uint8_t)(data >> 4)
davidr99 0:ab4e012489ef 85 ^ ((uint16_t)data << 3));
davidr99 0:ab4e012489ef 86 }
davidr99 0:ab4e012489ef 87
davidr99 0:ab4e012489ef 88 uint8_t RHcrc_ibutton_update(uint8_t crc, uint8_t data)
davidr99 0:ab4e012489ef 89 {
davidr99 0:ab4e012489ef 90 uint8_t i;
davidr99 0:ab4e012489ef 91
davidr99 0:ab4e012489ef 92 crc = crc ^ data;
davidr99 0:ab4e012489ef 93 for (i = 0; i < 8; i++)
davidr99 0:ab4e012489ef 94 {
davidr99 0:ab4e012489ef 95 if (crc & 0x01)
davidr99 0:ab4e012489ef 96 crc = (crc >> 1) ^ 0x8C;
davidr99 0:ab4e012489ef 97 else
davidr99 0:ab4e012489ef 98 crc >>= 1;
davidr99 0:ab4e012489ef 99 }
davidr99 0:ab4e012489ef 100
davidr99 0:ab4e012489ef 101 return crc;
davidr99 0:ab4e012489ef 102 }
davidr99 0:ab4e012489ef 103
davidr99 0:ab4e012489ef 104