1 /** 2 * Calculation of CRC 16 CCITT polynomial. 3 * 4 * @file crc16-ccitt.h 5 * @ingroup CO_crc16_ccitt 6 * @author Lammert Bies 7 * @author Janez Paternoster 8 * @copyright 2012 - 2020 Janez Paternoster 9 * 10 * This file is part of CANopenNode, an opensource CANopen Stack. 11 * Project home page is <https://github.com/CANopenNode/CANopenNode>. 12 * For more information on CANopen see <http://www.can-cia.org/>. 13 * 14 * Licensed under the Apache License, Version 2.0 (the "License"); 15 * you may not use this file except in compliance with the License. 16 * You may obtain a copy of the License at 17 * 18 * http://www.apache.org/licenses/LICENSE-2.0 19 * 20 * Unless required by applicable law or agreed to in writing, software 21 * distributed under the License is distributed on an "AS IS" BASIS, 22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 * See the License for the specific language governing permissions and 24 * limitations under the License. 25 */ 26 27 28 #ifndef CRC16_CCITT_H 29 #define CRC16_CCITT_H 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /** 36 * @defgroup CO_crc16_ccitt CRC 16 CCITT 37 * @ingroup CO_CANopen 38 * @{ 39 * 40 * Calculation of CRC 16 CCITT polynomial. 41 * 42 * Equation: 43 * 44 * `x^16 + x^12 + x^5 + 1` 45 */ 46 47 48 /** 49 * Calculate CRC sum on block of data. 50 * 51 * @param block Pointer to block of data. 52 * @param blockLength Length of data in bytes; 53 * @param crc Initial value (zero for xmodem). If block is split into 54 * multiple segments, previous CRC is used as initial. 55 * 56 * @return Calculated CRC. 57 */ 58 #ifdef CO_USE_OWN_CRC16 59 /* Map CANopenNode crc16_ccitt() to Zephyr crc16_itu_t() function */ 60 extern uint16_t crc16_itu_t(uint16_t seed, const uint8_t *src, size_t len); 61 #define crc16_ccitt(block, blockLength, crc) crc16_itu_t(crc, block, blockLength) 62 #else 63 unsigned short crc16_ccitt( 64 const unsigned char block[], 65 unsigned int blockLength, 66 unsigned short crc); 67 #endif 68 69 #ifdef __cplusplus 70 } 71 #endif /*__cplusplus*/ 72 73 /** @} */ 74 #endif 75