Nordic stack and drivers for the mbed BLE API Modified for HRM 1017 and correct DISCONNECT event processing
Fork of nRF51822 by
nordic/app_common/crc16.cpp@0:eff01767de02, 2014-03-26 (annotated)
- Committer:
- bogdanm
- Date:
- Wed Mar 26 14:38:17 2014 +0000
- Revision:
- 0:eff01767de02
Initial import of the nRF51822 code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:eff01767de02 | 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. |
bogdanm | 0:eff01767de02 | 2 | * |
bogdanm | 0:eff01767de02 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
bogdanm | 0:eff01767de02 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
bogdanm | 0:eff01767de02 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
bogdanm | 0:eff01767de02 | 6 | * |
bogdanm | 0:eff01767de02 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
bogdanm | 0:eff01767de02 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
bogdanm | 0:eff01767de02 | 9 | * the file. |
bogdanm | 0:eff01767de02 | 10 | * |
bogdanm | 0:eff01767de02 | 11 | */ |
bogdanm | 0:eff01767de02 | 12 | |
bogdanm | 0:eff01767de02 | 13 | #include "crc16.h" |
bogdanm | 0:eff01767de02 | 14 | #include <stdio.h> |
bogdanm | 0:eff01767de02 | 15 | |
bogdanm | 0:eff01767de02 | 16 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc) |
bogdanm | 0:eff01767de02 | 17 | { |
bogdanm | 0:eff01767de02 | 18 | uint32_t i; |
bogdanm | 0:eff01767de02 | 19 | uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc; |
bogdanm | 0:eff01767de02 | 20 | |
bogdanm | 0:eff01767de02 | 21 | for (i = 0; i < size; i++) |
bogdanm | 0:eff01767de02 | 22 | { |
bogdanm | 0:eff01767de02 | 23 | crc = (unsigned char)(crc >> 8) | (crc << 8); |
bogdanm | 0:eff01767de02 | 24 | crc ^= p_data[i]; |
bogdanm | 0:eff01767de02 | 25 | crc ^= (unsigned char)(crc & 0xff) >> 4; |
bogdanm | 0:eff01767de02 | 26 | crc ^= (crc << 8) << 4; |
bogdanm | 0:eff01767de02 | 27 | crc ^= ((crc & 0xff) << 4) << 1; |
bogdanm | 0:eff01767de02 | 28 | } |
bogdanm | 0:eff01767de02 | 29 | |
bogdanm | 0:eff01767de02 | 30 | return crc; |
bogdanm | 0:eff01767de02 | 31 | } |