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@0:f2542974c862, 2016-04-07 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Thu Apr 07 17:34:39 2016 +0100
- Revision:
- 0:f2542974c862
- Child:
- 1:ebc0e0ef0a11
Synchronized with git rev fea7c30
Author: Liyou Zhou
Initial commit, centralising all required files from nordic sdk in on central repo.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
0:f2542974c862 | 1 | /* |
Vincent Coubard |
0:f2542974c862 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Vincent Coubard |
0:f2542974c862 | 3 | * All rights reserved. |
Vincent Coubard |
0:f2542974c862 | 4 | * |
Vincent Coubard |
0:f2542974c862 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Vincent Coubard |
0:f2542974c862 | 6 | * are permitted provided that the following conditions are met: |
Vincent Coubard |
0:f2542974c862 | 7 | * |
Vincent Coubard |
0:f2542974c862 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Vincent Coubard |
0:f2542974c862 | 9 | * list of conditions and the following disclaimer. |
Vincent Coubard |
0:f2542974c862 | 10 | * |
Vincent Coubard |
0:f2542974c862 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Vincent Coubard |
0:f2542974c862 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Vincent Coubard |
0:f2542974c862 | 13 | * other materials provided with the distribution. |
Vincent Coubard |
0:f2542974c862 | 14 | * |
Vincent Coubard |
0:f2542974c862 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Vincent Coubard |
0:f2542974c862 | 16 | * contributors to this software may be used to endorse or promote products |
Vincent Coubard |
0:f2542974c862 | 17 | * derived from this software without specific prior written permission. |
Vincent Coubard |
0:f2542974c862 | 18 | * |
Vincent Coubard |
0:f2542974c862 | 19 | * |
Vincent Coubard |
0:f2542974c862 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Vincent Coubard |
0:f2542974c862 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Vincent Coubard |
0:f2542974c862 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Vincent Coubard |
0:f2542974c862 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Vincent Coubard |
0:f2542974c862 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Vincent Coubard |
0:f2542974c862 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Vincent Coubard |
0:f2542974c862 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Vincent Coubard |
0:f2542974c862 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Vincent Coubard |
0:f2542974c862 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Vincent Coubard |
0:f2542974c862 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Vincent Coubard |
0:f2542974c862 | 30 | * |
Vincent Coubard |
0:f2542974c862 | 31 | */ |
Vincent Coubard |
0:f2542974c862 | 32 | |
Vincent Coubard |
0:f2542974c862 | 33 | #include "crc16.h" |
Vincent Coubard |
0:f2542974c862 | 34 | #include <stdio.h> |
Vincent Coubard |
0:f2542974c862 | 35 | |
Vincent Coubard |
0:f2542974c862 | 36 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc) |
Vincent Coubard |
0:f2542974c862 | 37 | { |
Vincent Coubard |
0:f2542974c862 | 38 | uint32_t i; |
Vincent Coubard |
0:f2542974c862 | 39 | uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc; |
Vincent Coubard |
0:f2542974c862 | 40 | |
Vincent Coubard |
0:f2542974c862 | 41 | for (i = 0; i < size; i++) |
Vincent Coubard |
0:f2542974c862 | 42 | { |
Vincent Coubard |
0:f2542974c862 | 43 | crc = (unsigned char)(crc >> 8) | (crc << 8); |
Vincent Coubard |
0:f2542974c862 | 44 | crc ^= p_data[i]; |
Vincent Coubard |
0:f2542974c862 | 45 | crc ^= (unsigned char)(crc & 0xff) >> 4; |
Vincent Coubard |
0:f2542974c862 | 46 | crc ^= (crc << 8) << 4; |
Vincent Coubard |
0:f2542974c862 | 47 | crc ^= ((crc & 0xff) << 4) << 1; |
Vincent Coubard |
0:f2542974c862 | 48 | } |
Vincent Coubard |
0:f2542974c862 | 49 | |
Vincent Coubard |
0:f2542974c862 | 50 | return crc; |
Vincent Coubard |
0:f2542974c862 | 51 | } |