The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_RO359B/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/drivers/fsl_crc.h@143:86740a56073b
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
AnnaBridge 143:86740a56073b 3 * Copyright 2016-2017 NXP
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 143:86740a56073b 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 143:86740a56073b 13 * other materials provided with the distribution.
AnnaBridge 143:86740a56073b 14 *
AnnaBridge 143:86740a56073b 15 * o Neither the name of the copyright holder nor the names of its
AnnaBridge 143:86740a56073b 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 143:86740a56073b 17 * software without specific prior written permission.
AnnaBridge 143:86740a56073b 18 *
AnnaBridge 143:86740a56073b 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 29 */
AnnaBridge 143:86740a56073b 30
AnnaBridge 143:86740a56073b 31 #ifndef _FSL_CRC_H_
AnnaBridge 143:86740a56073b 32 #define _FSL_CRC_H_
AnnaBridge 143:86740a56073b 33
AnnaBridge 143:86740a56073b 34 #include "fsl_common.h"
AnnaBridge 143:86740a56073b 35
AnnaBridge 143:86740a56073b 36 /*!
AnnaBridge 143:86740a56073b 37 * @addtogroup crc
AnnaBridge 143:86740a56073b 38 * @{
AnnaBridge 143:86740a56073b 39 */
AnnaBridge 143:86740a56073b 40
AnnaBridge 143:86740a56073b 41 /*******************************************************************************
AnnaBridge 143:86740a56073b 42 * Definitions
AnnaBridge 143:86740a56073b 43 ******************************************************************************/
AnnaBridge 143:86740a56073b 44
AnnaBridge 143:86740a56073b 45 /*! @name Driver version */
AnnaBridge 143:86740a56073b 46 /*@{*/
AnnaBridge 143:86740a56073b 47 /*! @brief CRC driver version. Version 2.0.1.
AnnaBridge 143:86740a56073b 48 *
AnnaBridge 143:86740a56073b 49 * Current version: 2.0.1
AnnaBridge 143:86740a56073b 50 *
AnnaBridge 143:86740a56073b 51 * Change log:
AnnaBridge 143:86740a56073b 52 * - Version 2.0.1
AnnaBridge 143:86740a56073b 53 * - move DATA and DATALL macro definition from header file to source file
AnnaBridge 143:86740a56073b 54 */
AnnaBridge 143:86740a56073b 55 #define FSL_CRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
AnnaBridge 143:86740a56073b 56 /*@}*/
AnnaBridge 143:86740a56073b 57
AnnaBridge 143:86740a56073b 58 #ifndef CRC_DRIVER_CUSTOM_DEFAULTS
AnnaBridge 143:86740a56073b 59 /*! @brief Default configuration structure filled by CRC_GetDefaultConfig(). Use CRC16-CCIT-FALSE as defeault. */
AnnaBridge 143:86740a56073b 60 #define CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT 1
AnnaBridge 143:86740a56073b 61 #endif
AnnaBridge 143:86740a56073b 62
AnnaBridge 143:86740a56073b 63 /*! @brief CRC bit width */
AnnaBridge 143:86740a56073b 64 typedef enum _crc_bits
AnnaBridge 143:86740a56073b 65 {
AnnaBridge 143:86740a56073b 66 kCrcBits16 = 0U, /*!< Generate 16-bit CRC code */
AnnaBridge 143:86740a56073b 67 kCrcBits32 = 1U /*!< Generate 32-bit CRC code */
AnnaBridge 143:86740a56073b 68 } crc_bits_t;
AnnaBridge 143:86740a56073b 69
AnnaBridge 143:86740a56073b 70 /*! @brief CRC result type */
AnnaBridge 143:86740a56073b 71 typedef enum _crc_result
AnnaBridge 143:86740a56073b 72 {
AnnaBridge 143:86740a56073b 73 kCrcFinalChecksum = 0U, /*!< CRC data register read value is the final checksum.
AnnaBridge 143:86740a56073b 74 Reflect out and final xor protocol features are applied. */
AnnaBridge 143:86740a56073b 75 kCrcIntermediateChecksum = 1U /*!< CRC data register read value is intermediate checksum (raw value).
AnnaBridge 143:86740a56073b 76 Reflect out and final xor protocol feature are not applied.
AnnaBridge 143:86740a56073b 77 Intermediate checksum can be used as a seed for CRC_Init()
AnnaBridge 143:86740a56073b 78 to continue adding data to this checksum. */
AnnaBridge 143:86740a56073b 79 } crc_result_t;
AnnaBridge 143:86740a56073b 80
AnnaBridge 143:86740a56073b 81 /*!
AnnaBridge 143:86740a56073b 82 * @brief CRC protocol configuration.
AnnaBridge 143:86740a56073b 83 *
AnnaBridge 143:86740a56073b 84 * This structure holds the configuration for the CRC protocol.
AnnaBridge 143:86740a56073b 85 *
AnnaBridge 143:86740a56073b 86 */
AnnaBridge 143:86740a56073b 87 typedef struct _crc_config
AnnaBridge 143:86740a56073b 88 {
AnnaBridge 143:86740a56073b 89 uint32_t polynomial; /*!< CRC Polynomial, MSBit first.
AnnaBridge 143:86740a56073b 90 Example polynomial: 0x1021 = 1_0000_0010_0001 = x^12+x^5+1 */
AnnaBridge 143:86740a56073b 91 uint32_t seed; /*!< Starting checksum value */
AnnaBridge 143:86740a56073b 92 bool reflectIn; /*!< Reflect bits on input. */
AnnaBridge 143:86740a56073b 93 bool reflectOut; /*!< Reflect bits on output. */
AnnaBridge 143:86740a56073b 94 bool complementChecksum; /*!< True if the result shall be complement of the actual checksum. */
AnnaBridge 143:86740a56073b 95 crc_bits_t crcBits; /*!< Selects 16- or 32- bit CRC protocol. */
AnnaBridge 143:86740a56073b 96 crc_result_t crcResult; /*!< Selects final or intermediate checksum return from CRC_Get16bitResult() or
AnnaBridge 143:86740a56073b 97 CRC_Get32bitResult() */
AnnaBridge 143:86740a56073b 98 } crc_config_t;
AnnaBridge 143:86740a56073b 99
AnnaBridge 143:86740a56073b 100 /*******************************************************************************
AnnaBridge 143:86740a56073b 101 * API
AnnaBridge 143:86740a56073b 102 ******************************************************************************/
AnnaBridge 143:86740a56073b 103 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 104 extern "C" {
AnnaBridge 143:86740a56073b 105 #endif
AnnaBridge 143:86740a56073b 106
AnnaBridge 143:86740a56073b 107 /*!
AnnaBridge 143:86740a56073b 108 * @brief Enables and configures the CRC peripheral module.
AnnaBridge 143:86740a56073b 109 *
AnnaBridge 143:86740a56073b 110 * This function enables the clock gate in the SIM module for the CRC peripheral.
AnnaBridge 143:86740a56073b 111 * It also configures the CRC module and starts a checksum computation by writing the seed.
AnnaBridge 143:86740a56073b 112 *
AnnaBridge 143:86740a56073b 113 * @param base CRC peripheral address.
AnnaBridge 143:86740a56073b 114 * @param config CRC module configuration structure.
AnnaBridge 143:86740a56073b 115 */
AnnaBridge 143:86740a56073b 116 void CRC_Init(CRC_Type *base, const crc_config_t *config);
AnnaBridge 143:86740a56073b 117
AnnaBridge 143:86740a56073b 118 /*!
AnnaBridge 143:86740a56073b 119 * @brief Disables the CRC peripheral module.
AnnaBridge 143:86740a56073b 120 *
AnnaBridge 143:86740a56073b 121 * This function disables the clock gate in the SIM module for the CRC peripheral.
AnnaBridge 143:86740a56073b 122 *
AnnaBridge 143:86740a56073b 123 * @param base CRC peripheral address.
AnnaBridge 143:86740a56073b 124 */
AnnaBridge 143:86740a56073b 125 static inline void CRC_Deinit(CRC_Type *base)
AnnaBridge 143:86740a56073b 126 {
AnnaBridge 143:86740a56073b 127 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
AnnaBridge 143:86740a56073b 128 /* gate clock */
AnnaBridge 143:86740a56073b 129 CLOCK_DisableClock(kCLOCK_Crc0);
AnnaBridge 143:86740a56073b 130 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
AnnaBridge 143:86740a56073b 131 }
AnnaBridge 143:86740a56073b 132
AnnaBridge 143:86740a56073b 133 /*!
AnnaBridge 143:86740a56073b 134 * @brief Loads default values to the CRC protocol configuration structure.
AnnaBridge 143:86740a56073b 135 *
AnnaBridge 143:86740a56073b 136 * Loads default values to the CRC protocol configuration structure. The default values are as follows.
AnnaBridge 143:86740a56073b 137 * @code
AnnaBridge 143:86740a56073b 138 * config->polynomial = 0x1021;
AnnaBridge 143:86740a56073b 139 * config->seed = 0xFFFF;
AnnaBridge 143:86740a56073b 140 * config->reflectIn = false;
AnnaBridge 143:86740a56073b 141 * config->reflectOut = false;
AnnaBridge 143:86740a56073b 142 * config->complementChecksum = false;
AnnaBridge 143:86740a56073b 143 * config->crcBits = kCrcBits16;
AnnaBridge 143:86740a56073b 144 * config->crcResult = kCrcFinalChecksum;
AnnaBridge 143:86740a56073b 145 * @endcode
AnnaBridge 143:86740a56073b 146 *
AnnaBridge 143:86740a56073b 147 * @param config CRC protocol configuration structure.
AnnaBridge 143:86740a56073b 148 */
AnnaBridge 143:86740a56073b 149 void CRC_GetDefaultConfig(crc_config_t *config);
AnnaBridge 143:86740a56073b 150
AnnaBridge 143:86740a56073b 151 /*!
AnnaBridge 143:86740a56073b 152 * @brief Writes data to the CRC module.
AnnaBridge 143:86740a56073b 153 *
AnnaBridge 143:86740a56073b 154 * Writes input data buffer bytes to the CRC data register.
AnnaBridge 143:86740a56073b 155 * The configured type of transpose is applied.
AnnaBridge 143:86740a56073b 156 *
AnnaBridge 143:86740a56073b 157 * @param base CRC peripheral address.
AnnaBridge 143:86740a56073b 158 * @param data Input data stream, MSByte in data[0].
AnnaBridge 143:86740a56073b 159 * @param dataSize Size in bytes of the input data buffer.
AnnaBridge 143:86740a56073b 160 */
AnnaBridge 143:86740a56073b 161 void CRC_WriteData(CRC_Type *base, const uint8_t *data, size_t dataSize);
AnnaBridge 143:86740a56073b 162
AnnaBridge 143:86740a56073b 163 /*!
AnnaBridge 143:86740a56073b 164 * @brief Reads the 32-bit checksum from the CRC module.
AnnaBridge 143:86740a56073b 165 *
AnnaBridge 143:86740a56073b 166 * Reads the CRC data register (either an intermediate or the final checksum).
AnnaBridge 143:86740a56073b 167 * The configured type of transpose and complement is applied.
AnnaBridge 143:86740a56073b 168 *
AnnaBridge 143:86740a56073b 169 * @param base CRC peripheral address.
AnnaBridge 143:86740a56073b 170 * @return An intermediate or the final 32-bit checksum, after configured transpose and complement operations.
AnnaBridge 143:86740a56073b 171 */
AnnaBridge 143:86740a56073b 172 uint32_t CRC_Get32bitResult(CRC_Type *base);
AnnaBridge 143:86740a56073b 173
AnnaBridge 143:86740a56073b 174 /*!
AnnaBridge 143:86740a56073b 175 * @brief Reads a 16-bit checksum from the CRC module.
AnnaBridge 143:86740a56073b 176 *
AnnaBridge 143:86740a56073b 177 * Reads the CRC data register (either an intermediate or the final checksum).
AnnaBridge 143:86740a56073b 178 * The configured type of transpose and complement is applied.
AnnaBridge 143:86740a56073b 179 *
AnnaBridge 143:86740a56073b 180 * @param base CRC peripheral address.
AnnaBridge 143:86740a56073b 181 * @return An intermediate or the final 16-bit checksum, after configured transpose and complement operations.
AnnaBridge 143:86740a56073b 182 */
AnnaBridge 143:86740a56073b 183 uint16_t CRC_Get16bitResult(CRC_Type *base);
AnnaBridge 143:86740a56073b 184
AnnaBridge 143:86740a56073b 185 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 186 }
AnnaBridge 143:86740a56073b 187 #endif
AnnaBridge 143:86740a56073b 188
AnnaBridge 143:86740a56073b 189 /*!
AnnaBridge 143:86740a56073b 190 *@}
AnnaBridge 143:86740a56073b 191 */
AnnaBridge 143:86740a56073b 192
AnnaBridge 143:86740a56073b 193 #endif /* _FSL_CRC_H_ */