RFAL library for the STMicroelectronics X-NUCLEO-NFC05A1

Dependents:   mbed-os-nfc05a1

Committer:
DiegoOstuni
Date:
Thu Nov 14 14:34:50 2019 +0000
Revision:
0:75fc82583a41
Add files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiegoOstuni 0:75fc82583a41 1
DiegoOstuni 0:75fc82583a41 2 /******************************************************************************
DiegoOstuni 0:75fc82583a41 3 * @attention
DiegoOstuni 0:75fc82583a41 4 *
DiegoOstuni 0:75fc82583a41 5 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
DiegoOstuni 0:75fc82583a41 6 *
DiegoOstuni 0:75fc82583a41 7 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 0:75fc82583a41 8 * You may not use this file except in compliance with the License.
DiegoOstuni 0:75fc82583a41 9 * You may obtain a copy of the License at:
DiegoOstuni 0:75fc82583a41 10 *
DiegoOstuni 0:75fc82583a41 11 * http://www.st.com/myliberty
DiegoOstuni 0:75fc82583a41 12 *
DiegoOstuni 0:75fc82583a41 13 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 0:75fc82583a41 14 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 0:75fc82583a41 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 0:75fc82583a41 16 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 0:75fc82583a41 17 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 0:75fc82583a41 18 * See the License for the specific language governing permissions and
DiegoOstuni 0:75fc82583a41 19 * limitations under the License.
DiegoOstuni 0:75fc82583a41 20 *
DiegoOstuni 0:75fc82583a41 21 ******************************************************************************/
DiegoOstuni 0:75fc82583a41 22
DiegoOstuni 0:75fc82583a41 23 /*
DiegoOstuni 0:75fc82583a41 24 * PROJECT: ST25R391x firmware
DiegoOstuni 0:75fc82583a41 25 * $Revision: $
DiegoOstuni 0:75fc82583a41 26 * LANGUAGE: ISO C99
DiegoOstuni 0:75fc82583a41 27 */
DiegoOstuni 0:75fc82583a41 28
DiegoOstuni 0:75fc82583a41 29 /*! \file rfal_crc.c
DiegoOstuni 0:75fc82583a41 30 *
DiegoOstuni 0:75fc82583a41 31 * \author Oliver Regenfelder
DiegoOstuni 0:75fc82583a41 32 *
DiegoOstuni 0:75fc82583a41 33 * \brief CRC calculation implementation
DiegoOstuni 0:75fc82583a41 34 *
DiegoOstuni 0:75fc82583a41 35 */
DiegoOstuni 0:75fc82583a41 36
DiegoOstuni 0:75fc82583a41 37 /*
DiegoOstuni 0:75fc82583a41 38 ******************************************************************************
DiegoOstuni 0:75fc82583a41 39 * INCLUDES
DiegoOstuni 0:75fc82583a41 40 ******************************************************************************
DiegoOstuni 0:75fc82583a41 41 */
DiegoOstuni 0:75fc82583a41 42 #include "rfal_crc.h"
DiegoOstuni 0:75fc82583a41 43
DiegoOstuni 0:75fc82583a41 44 /*
DiegoOstuni 0:75fc82583a41 45 ******************************************************************************
DiegoOstuni 0:75fc82583a41 46 * LOCAL FUNCTION PROTOTYPES
DiegoOstuni 0:75fc82583a41 47 ******************************************************************************
DiegoOstuni 0:75fc82583a41 48 */
DiegoOstuni 0:75fc82583a41 49 static uint16_t rfalCrcUpdateCcitt(uint16_t crc, uint8_t dat);
DiegoOstuni 0:75fc82583a41 50
DiegoOstuni 0:75fc82583a41 51 /*
DiegoOstuni 0:75fc82583a41 52 ******************************************************************************
DiegoOstuni 0:75fc82583a41 53 * GLOBAL FUNCTIONS
DiegoOstuni 0:75fc82583a41 54 ******************************************************************************
DiegoOstuni 0:75fc82583a41 55 */
DiegoOstuni 0:75fc82583a41 56 uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length)
DiegoOstuni 0:75fc82583a41 57 {
DiegoOstuni 0:75fc82583a41 58 uint16_t crc = preloadValue;
DiegoOstuni 0:75fc82583a41 59 uint16_t index;
DiegoOstuni 0:75fc82583a41 60
DiegoOstuni 0:75fc82583a41 61 for (index = 0; index < length; index++)
DiegoOstuni 0:75fc82583a41 62 {
DiegoOstuni 0:75fc82583a41 63 crc = rfalCrcUpdateCcitt(crc, buf[index]);
DiegoOstuni 0:75fc82583a41 64 }
DiegoOstuni 0:75fc82583a41 65
DiegoOstuni 0:75fc82583a41 66 return crc;
DiegoOstuni 0:75fc82583a41 67 }
DiegoOstuni 0:75fc82583a41 68
DiegoOstuni 0:75fc82583a41 69 /*
DiegoOstuni 0:75fc82583a41 70 ******************************************************************************
DiegoOstuni 0:75fc82583a41 71 * LOCAL FUNCTIONS
DiegoOstuni 0:75fc82583a41 72 ******************************************************************************
DiegoOstuni 0:75fc82583a41 73 */
DiegoOstuni 0:75fc82583a41 74 static uint16_t rfalCrcUpdateCcitt(uint16_t crc, uint8_t dat)
DiegoOstuni 0:75fc82583a41 75 {
DiegoOstuni 0:75fc82583a41 76 dat ^= ((uint8_t)crc) & 0xFF;
DiegoOstuni 0:75fc82583a41 77 dat ^= dat << 4;
DiegoOstuni 0:75fc82583a41 78
DiegoOstuni 0:75fc82583a41 79 crc = (crc >> 8)^(((uint16_t) dat) << 8)^(((uint16_t) dat) << 3)^(((uint16_t) dat) >> 4);
DiegoOstuni 0:75fc82583a41 80
DiegoOstuni 0:75fc82583a41 81 return crc;
DiegoOstuni 0:75fc82583a41 82 }
DiegoOstuni 0:75fc82583a41 83