first commit

Dependencies:   mbed

Dependents:   ibeacon

Fork of BLE_WallbotBLE_Challenge by JKSoft

Committer:
jksoft
Date:
Wed Nov 12 02:40:34 2014 +0000
Revision:
0:76dfa9657d9d
????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:76dfa9657d9d 1 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
jksoft 0:76dfa9657d9d 2 *
jksoft 0:76dfa9657d9d 3 * The information contained herein is property of Nordic Semiconductor ASA.
jksoft 0:76dfa9657d9d 4 * Terms and conditions of usage are described in detail in NORDIC
jksoft 0:76dfa9657d9d 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
jksoft 0:76dfa9657d9d 6 *
jksoft 0:76dfa9657d9d 7 * Licensees are granted free, non-transferable use of the information. NO
jksoft 0:76dfa9657d9d 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
jksoft 0:76dfa9657d9d 9 * the file.
jksoft 0:76dfa9657d9d 10 *
jksoft 0:76dfa9657d9d 11 */
jksoft 0:76dfa9657d9d 12
jksoft 0:76dfa9657d9d 13 #include "crc16.h"
jksoft 0:76dfa9657d9d 14 #include <stdio.h>
jksoft 0:76dfa9657d9d 15
jksoft 0:76dfa9657d9d 16 uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc)
jksoft 0:76dfa9657d9d 17 {
jksoft 0:76dfa9657d9d 18 uint32_t i;
jksoft 0:76dfa9657d9d 19 uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc;
jksoft 0:76dfa9657d9d 20
jksoft 0:76dfa9657d9d 21 for (i = 0; i < size; i++)
jksoft 0:76dfa9657d9d 22 {
jksoft 0:76dfa9657d9d 23 crc = (unsigned char)(crc >> 8) | (crc << 8);
jksoft 0:76dfa9657d9d 24 crc ^= p_data[i];
jksoft 0:76dfa9657d9d 25 crc ^= (unsigned char)(crc & 0xff) >> 4;
jksoft 0:76dfa9657d9d 26 crc ^= (crc << 8) << 4;
jksoft 0:76dfa9657d9d 27 crc ^= ((crc & 0xff) << 4) << 1;
jksoft 0:76dfa9657d9d 28 }
jksoft 0:76dfa9657d9d 29
jksoft 0:76dfa9657d9d 30 return crc;
jksoft 0:76dfa9657d9d 31 }