Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nrf51-sdk by
source/nordic_sdk/components/libraries/crc16/crc16.c@28:041dac1366b2, 2016-04-07 (annotated)
- Committer:
- vcoubard
- Date:
- Thu Apr 07 17:37:56 2016 +0100
- Revision:
- 28:041dac1366b2
- Parent:
- 20:a90c48eb1d30
- Child:
- 29:286940b7ee5a
Synchronized with git rev 012b8118
Author: Liyou Zhou
Pull in files from sdk 10.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 28:041dac1366b2 | 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. |
vcoubard | 28:041dac1366b2 | 2 | * |
vcoubard | 28:041dac1366b2 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
vcoubard | 28:041dac1366b2 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
vcoubard | 28:041dac1366b2 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
vcoubard | 28:041dac1366b2 | 6 | * |
vcoubard | 28:041dac1366b2 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
vcoubard | 28:041dac1366b2 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
vcoubard | 28:041dac1366b2 | 9 | * the file. |
vcoubard | 28:041dac1366b2 | 10 | * |
Vincent Coubard |
0:f2542974c862 | 11 | */ |
Vincent Coubard |
0:f2542974c862 | 12 | |
Vincent Coubard |
0:f2542974c862 | 13 | #include "crc16.h" |
Vincent Coubard |
0:f2542974c862 | 14 | #include <stdio.h> |
Vincent Coubard |
0:f2542974c862 | 15 | |
Vincent Coubard |
0:f2542974c862 | 16 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc) |
Vincent Coubard |
0:f2542974c862 | 17 | { |
Vincent Coubard |
0:f2542974c862 | 18 | uint32_t i; |
Vincent Coubard |
0:f2542974c862 | 19 | uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc; |
Vincent Coubard |
0:f2542974c862 | 20 | |
Vincent Coubard |
0:f2542974c862 | 21 | for (i = 0; i < size; i++) |
Vincent Coubard |
0:f2542974c862 | 22 | { |
Vincent Coubard |
0:f2542974c862 | 23 | crc = (unsigned char)(crc >> 8) | (crc << 8); |
Vincent Coubard |
0:f2542974c862 | 24 | crc ^= p_data[i]; |
Vincent Coubard |
0:f2542974c862 | 25 | crc ^= (unsigned char)(crc & 0xff) >> 4; |
Vincent Coubard |
0:f2542974c862 | 26 | crc ^= (crc << 8) << 4; |
Vincent Coubard |
0:f2542974c862 | 27 | crc ^= ((crc & 0xff) << 4) << 1; |
Vincent Coubard |
0:f2542974c862 | 28 | } |
Vincent Coubard |
0:f2542974c862 | 29 | |
Vincent Coubard |
0:f2542974c862 | 30 | return crc; |
vcoubard | 1:ebc0e0ef0a11 | 31 | } |