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)16 uint32_t HAL_CrcCompute(hal_crc_config_t *crcConfig, uint8_t *dataIn, uint32_t length)
17 {
18     CRC_Type *const s_CrcList[] = CRC_BASE_PTRS;
19     crc_config_t config;
20     uint32_t result;
21 
22     config.seed          = crcConfig->crcSeed;
23     config.reverseIn     = (bool)crcConfig->crcRefIn;
24     config.complementIn  = false;
25     config.complementOut = (bool)crcConfig->complementChecksum;
26     config.reverseOut    = (bool)crcConfig->crcRefOut;
27 
28     assert((crcConfig->crcSize == 2U) || (crcConfig->crcSize == 4U));
29 
30     if (crcConfig->crcSize == 2U)
31     {
32         config.polynomial = kCRC_Polynomial_CRC_CCITT;
33     }
34     else
35     {
36         config.polynomial = kCRC_Polynomial_CRC_32;
37     }
38 
39     CRC_Init(s_CrcList[0], &config);
40     CRC_WriteData(s_CrcList[0], dataIn, length);
41 
42     if (crcConfig->crcSize == 2U)
43     {
44         result = (uint32_t)CRC_Get16bitResult(s_CrcList[0]);
45     }
46     else
47     {
48         result = CRC_Get32bitResult(s_CrcList[0]);
49     }
50 
51     return result;
52 }
53