Junichi Katsu
/
BLE_MPU6050_test6_challenge_sb
テスト用です。
nRF51822_wallbot/nordic/app_common/crc16.cpp@0:8468a4403fea, 2016-10-11 (annotated)
- Committer:
- jksoft
- Date:
- Tue Oct 11 11:09:42 2016 +0000
- Revision:
- 0:8468a4403fea
SB??ver;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:8468a4403fea | 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. |
jksoft | 0:8468a4403fea | 2 | * |
jksoft | 0:8468a4403fea | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
jksoft | 0:8468a4403fea | 4 | * Terms and conditions of usage are described in detail in NORDIC |
jksoft | 0:8468a4403fea | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
jksoft | 0:8468a4403fea | 6 | * |
jksoft | 0:8468a4403fea | 7 | * Licensees are granted free, non-transferable use of the information. NO |
jksoft | 0:8468a4403fea | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jksoft | 0:8468a4403fea | 9 | * the file. |
jksoft | 0:8468a4403fea | 10 | * |
jksoft | 0:8468a4403fea | 11 | */ |
jksoft | 0:8468a4403fea | 12 | |
jksoft | 0:8468a4403fea | 13 | #include "crc16.h" |
jksoft | 0:8468a4403fea | 14 | #include <stdio.h> |
jksoft | 0:8468a4403fea | 15 | |
jksoft | 0:8468a4403fea | 16 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc) |
jksoft | 0:8468a4403fea | 17 | { |
jksoft | 0:8468a4403fea | 18 | uint32_t i; |
jksoft | 0:8468a4403fea | 19 | uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc; |
jksoft | 0:8468a4403fea | 20 | |
jksoft | 0:8468a4403fea | 21 | for (i = 0; i < size; i++) |
jksoft | 0:8468a4403fea | 22 | { |
jksoft | 0:8468a4403fea | 23 | crc = (unsigned char)(crc >> 8) | (crc << 8); |
jksoft | 0:8468a4403fea | 24 | crc ^= p_data[i]; |
jksoft | 0:8468a4403fea | 25 | crc ^= (unsigned char)(crc & 0xff) >> 4; |
jksoft | 0:8468a4403fea | 26 | crc ^= (crc << 8) << 4; |
jksoft | 0:8468a4403fea | 27 | crc ^= ((crc & 0xff) << 4) << 1; |
jksoft | 0:8468a4403fea | 28 | } |
jksoft | 0:8468a4403fea | 29 | |
jksoft | 0:8468a4403fea | 30 | return crc; |
jksoft | 0:8468a4403fea | 31 | } |