crc8 Library - Original copyright: Colin O'Flynn - Copyright (c) 2002
Embed:
(wiki syntax)
Show/hide line numbers
crc8.cpp
00001 /* please read copyright-notice at EOF */ 00002 00003 #include "crc8.h" 00004 00005 #define CRC8INIT 0x00 00006 #define CRC8POLY 0x18 //0X18 = X^8+X^5+X^4+X^0 00007 00008 char crc8 ( char *data_in, int number_of_bytes_to_read ) 00009 { 00010 char crc; 00011 int loop_count; 00012 char bit_counter; 00013 char data; 00014 char feedback_bit; 00015 00016 crc = CRC8INIT; 00017 00018 for (loop_count = 0; loop_count != number_of_bytes_to_read; loop_count++) 00019 { 00020 data = data_in[loop_count]; 00021 00022 bit_counter = 8; 00023 do { 00024 feedback_bit = (crc ^ data) & 0x01; 00025 00026 if ( feedback_bit == 0x01 ) { 00027 crc = crc ^ CRC8POLY; 00028 } 00029 crc = (crc >> 1) & 0x7F; 00030 if ( feedback_bit == 0x01 ) { 00031 crc = crc | 0x80; 00032 } 00033 00034 data = data >> 1; 00035 bit_counter--; 00036 00037 } while (bit_counter > 0); 00038 } 00039 00040 return crc; 00041 } 00042 00043 /* 00044 This code is from Colin O'Flynn - Copyright (c) 2002 00045 only minor changes by M.Thomas 9/2004 00046 oonverted to mbed library by Erik van Wijk 10/2010 00047 00048 Permission is hereby granted, free of charge, to any person obtaining a copy of 00049 this software and associated documentation files (the "Software"), to deal in 00050 the Software without restriction, including without limitation the rights to 00051 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 00052 the Software, and to permit persons to whom the Software is furnished to do so, 00053 subject to the following conditions: 00054 00055 The above copyright notice and this permission notice shall be included in all 00056 copies or substantial portions of the Software. 00057 00058 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00059 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 00060 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 00061 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 00062 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00063 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00064 */
Generated on Fri Jul 15 2022 17:48:42 by 1.7.2