SG RFID nRF51822 fork

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers crc16.cpp Source File

crc16.cpp

00001 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is property of Nordic Semiconductor ASA.
00004  * Terms and conditions of usage are described in detail in NORDIC
00005  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *
00011  */
00012 
00013 #include "crc16.h "
00014 #include <stdio.h>
00015 
00016 uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc)
00017 {
00018     uint32_t i;
00019     uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc;
00020 
00021     for (i = 0; i < size; i++)
00022     {
00023         crc  = (unsigned char)(crc >> 8) | (crc << 8);
00024         crc ^= p_data[i];
00025         crc ^= (unsigned char)(crc & 0xff) >> 4;
00026         crc ^= (crc << 8) << 4;
00027         crc ^= ((crc & 0xff) << 4) << 1;
00028     }
00029 
00030     return crc;
00031 }