Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
fsl_crc.h
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _FSL_CRC_H_
32 #define _FSL_CRC_H_
33 
34 #include "fsl_common.h"
35 
41 /*******************************************************************************
42  * Definitions
43  ******************************************************************************/
44 
46 #define FSL_CRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
49 #if defined(FSL_FEATURE_CRC_HAS_CRC_REG) && FSL_FEATURE_CRC_HAS_CRC_REG
50 #define DATA CRC
51 #define DATALL CRCLL
52 #endif
53 
55 #ifndef CRC_DRIVER_CUSTOM_DEFAULTS
56 #define CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT 1
57 #endif
58 
60 typedef enum _crc_bits
61 {
62  kCrcBits16 = 0U,
63  kCrcBits32 = 1U
64 } crc_bits_t;
65 
67 typedef enum _crc_result
68 {
69  kCrcFinalChecksum = 0U,
75 } crc_result_t;
76 
83 typedef struct _crc_config
84 {
85  uint32_t polynomial;
87  uint32_t seed;
88  bool reflectIn;
89  bool reflectOut;
94 } crc_config_t;
95 
96 /*******************************************************************************
97  * API
98  ******************************************************************************/
99 #if defined(__cplusplus)
100 extern "C" {
101 #endif
102 
112 void CRC_Init(CRC_Type *base, const crc_config_t *config);
113 
121 static inline void CRC_Deinit(CRC_Type *base)
122 {
123  /* gate clock */
124  CLOCK_DisableClock(kCLOCK_Crc0);
125 }
126 
143 void CRC_GetDefaultConfig(crc_config_t *config);
144 
155 void CRC_WriteData(CRC_Type *base, const uint8_t *data, size_t dataSize);
156 
166 static inline uint32_t CRC_Get32bitResult(CRC_Type *base)
167 {
168  return base->DATA;
169 }
170 
180 uint16_t CRC_Get16bitResult(CRC_Type *base);
181 
182 #if defined(__cplusplus)
183 }
184 #endif
185 
190 #endif /* _FSL_CRC_H_ */
uint32_t polynomial
Definition: fsl_crc.h:85
bool reflectIn
Definition: fsl_crc.h:88
crc_bits_t
CRC bit width.
Definition: fsl_crc.h:60
crc_result_t
CRC result type.
Definition: fsl_crc.h:67
Definition: fsl_crc.h:71
crc_bits_t crcBits
Definition: fsl_crc.h:91
CRC protocol configuration.
Definition: fsl_crc.h:83
void CRC_GetDefaultConfig(crc_config_t *config)
Loads default values to CRC protocol configuration structure.
Definition: fsl_crc.c:205
static void CRC_Deinit(CRC_Type *base)
Disable the CRC peripheral module.
Definition: fsl_crc.h:121
void CRC_Init(CRC_Type *base, const crc_config_t *config)
Enable and configure the CRC peripheral module.
Definition: fsl_crc.c:190
crc_result_t crcResult
Definition: fsl_crc.h:92
void CRC_WriteData(CRC_Type *base, const uint8_t *data, size_t dataSize)
Write data to the CRC module.
Definition: fsl_crc.c:217
bool reflectOut
Definition: fsl_crc.h:89
uint16_t CRC_Get16bitResult(CRC_Type *base)
Read 16-bit checksum from the CRC module.
Definition: fsl_crc.c:249
static uint32_t CRC_Get32bitResult(CRC_Type *base)
Read 32-bit checksum from the CRC module.
Definition: fsl_crc.h:166
Definition: fsl_crc.h:63
bool complementChecksum
Definition: fsl_crc.h:90
uint32_t seed
Definition: fsl_crc.h:87