1 /* 2 * Copyright 2018 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #include "fsl_common.h" 10 #include "fsl_adapter_crc.h" 11 #include "fsl_crc.h" 12 13 /******************************************************************************* 14 * Code 15 ******************************************************************************/ HAL_CrcCompute(hal_crc_config_t * crcConfig,uint8_t * dataIn,uint32_t length)16uint32_t HAL_CrcCompute(hal_crc_config_t *crcConfig, uint8_t *dataIn, uint32_t length) 17 { 18 crc_config_t config; 19 uint32_t result; 20 21 config.polynomial = crcConfig->crcPoly; 22 config.seed = crcConfig->crcSeed; 23 config.reflectIn = (bool)crcConfig->crcRefIn; 24 config.reflectOut = (bool)crcConfig->crcRefOut; 25 config.complementChecksum = (bool)crcConfig->complementChecksum; 26 27 assert((crcConfig->crcSize == 2U) || (crcConfig->crcSize == 4U)); 28 29 if (crcConfig->crcSize == 2U) 30 { 31 config.crcBits = kCrcBits16; 32 } 33 else 34 { 35 config.crcBits = kCrcBits32; 36 } 37 38 config.crcResult = kCrcFinalChecksum; 39 40 CRC_Init(CRC0, &config); 41 CRC_WriteData(CRC0, dataIn, length); 42 43 if (crcConfig->crcSize == 2U) 44 { 45 result = (uint32_t)CRC_Get16bitResult(CRC0); 46 } 47 else 48 { 49 result = CRC_Get32bitResult(CRC0); 50 } 51 52 return result; 53 } 54