Theo Havercroft / nRF51822

Dependencies:   nrf51-sdk

Fork of nRF51822 by Lancaster University

Committer:
vcoubard
Date:
Mon Jan 11 10:19:02 2016 +0000
Revision:
541:884f95bf5351
Parent:
387:b13ab9a7ddb9
Synchronized with git rev 60a7c0c0
Author: Rohit Grover
bring in the latest changes for BLE::init() where we allow <object, member> tuples for init callback.

Who changed what in which revision?

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