fsl_crc.h
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FSL_CRC_H_
#define _FSL_CRC_H_
#include "fsl_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define FSL_CRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
#if defined(FSL_FEATURE_CRC_HAS_CRC_REG) && FSL_FEATURE_CRC_HAS_CRC_REG
#define DATA CRC
#define DATALL CRCLL
#endif
#ifndef CRC_DRIVER_CUSTOM_DEFAULTS
#define CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT 1
#endif
typedef enum _crc_bits
{
kCrcBits16 = 0U,
kCrcBits32 = 1U
} crc_bits_t;
typedef enum _crc_result
{
kCrcFinalChecksum = 0U,
kCrcIntermediateChecksum = 1U
} crc_result_t;
typedef struct _crc_config
{
uint32_t polynomial;
uint32_t seed;
bool reflectIn;
bool reflectOut;
bool complementChecksum;
crc_bits_t crcBits;
crc_result_t crcResult;
} crc_config_t;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
void CRC_Init(CRC_Type *base, const crc_config_t *config);
static inline void CRC_Deinit(CRC_Type *base)
{
/* gate clock */
CLOCK_DisableClock(kCLOCK_Crc0);
}
void CRC_GetDefaultConfig(crc_config_t *config);
void CRC_WriteData(CRC_Type *base, const uint8_t *data, size_t dataSize);
static inline uint32_t CRC_Get32bitResult(CRC_Type *base)
{
return base->DATA;
}
uint16_t CRC_Get16bitResult(CRC_Type *base);
#if defined(__cplusplus)
}
#endif
#endif /* _FSL_CRC_H_ */
crc_config_t::polynomial
uint32_t polynomial
Definition: fsl_crc.h:85
crc_config_t::reflectIn
bool reflectIn
Definition: fsl_crc.h:88
crc_bits_t
crc_bits_t
CRC bit width.
Definition: fsl_crc.h:60
crc_result_t
crc_result_t
CRC result type.
Definition: fsl_crc.h:67
kCrcIntermediateChecksum
Definition: fsl_crc.h:71
crc_config_t::crcBits
crc_bits_t crcBits
Definition: fsl_crc.h:91
crc_config_t
CRC protocol configuration.
Definition: fsl_crc.h:83
CRC_GetDefaultConfig
void CRC_GetDefaultConfig(crc_config_t *config)
Loads default values to CRC protocol configuration structure.
Definition: fsl_crc.c:205
CRC_Deinit
static void CRC_Deinit(CRC_Type *base)
Disable the CRC peripheral module.
Definition: fsl_crc.h:121
CRC_Init
void CRC_Init(CRC_Type *base, const crc_config_t *config)
Enable and configure the CRC peripheral module.
Definition: fsl_crc.c:190
crc_config_t::crcResult
crc_result_t crcResult
Definition: fsl_crc.h:92
CRC_WriteData
void CRC_WriteData(CRC_Type *base, const uint8_t *data, size_t dataSize)
Write data to the CRC module.
Definition: fsl_crc.c:217
crc_config_t::reflectOut
bool reflectOut
Definition: fsl_crc.h:89
CRC_Get16bitResult
uint16_t CRC_Get16bitResult(CRC_Type *base)
Read 16-bit checksum from the CRC module.
Definition: fsl_crc.c:249
CRC_Get32bitResult
static uint32_t CRC_Get32bitResult(CRC_Type *base)
Read 32-bit checksum from the CRC module.
Definition: fsl_crc.h:166
kCrcBits32
Definition: fsl_crc.h:63
crc_config_t::complementChecksum
bool complementChecksum
Definition: fsl_crc.h:90
crc_config_t::seed
uint32_t seed
Definition: fsl_crc.h:87