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.
TARGET_LPC54114/TOOLCHAIN_IAR/fsl_crc.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 148:fd96258d940d | 1 | /* |
Kojto | 148:fd96258d940d | 2 | * Copyright (c) 2015-2016, Freescale Semiconductor, Inc. |
Kojto | 148:fd96258d940d | 3 | * All rights reserved. |
Kojto | 148:fd96258d940d | 4 | * |
Kojto | 148:fd96258d940d | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Kojto | 148:fd96258d940d | 6 | * are permitted provided that the following conditions are met: |
Kojto | 148:fd96258d940d | 7 | * |
Kojto | 148:fd96258d940d | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
Kojto | 148:fd96258d940d | 9 | * of conditions and the following disclaimer. |
Kojto | 148:fd96258d940d | 10 | * |
Kojto | 148:fd96258d940d | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
Kojto | 148:fd96258d940d | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Kojto | 148:fd96258d940d | 13 | * other materials provided with the distribution. |
Kojto | 148:fd96258d940d | 14 | * |
Kojto | 148:fd96258d940d | 15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
Kojto | 148:fd96258d940d | 16 | * contributors may be used to endorse or promote products derived from this |
Kojto | 148:fd96258d940d | 17 | * software without specific prior written permission. |
Kojto | 148:fd96258d940d | 18 | * |
Kojto | 148:fd96258d940d | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Kojto | 148:fd96258d940d | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Kojto | 148:fd96258d940d | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Kojto | 148:fd96258d940d | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Kojto | 148:fd96258d940d | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Kojto | 148:fd96258d940d | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Kojto | 148:fd96258d940d | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Kojto | 148:fd96258d940d | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Kojto | 148:fd96258d940d | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Kojto | 148:fd96258d940d | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 148:fd96258d940d | 29 | */ |
Kojto | 148:fd96258d940d | 30 | |
Kojto | 148:fd96258d940d | 31 | #ifndef _FSL_CRC_H_ |
Kojto | 148:fd96258d940d | 32 | #define _FSL_CRC_H_ |
Kojto | 148:fd96258d940d | 33 | |
Kojto | 148:fd96258d940d | 34 | #include "fsl_common.h" |
Kojto | 148:fd96258d940d | 35 | |
Kojto | 148:fd96258d940d | 36 | /*! |
Kojto | 148:fd96258d940d | 37 | * @addtogroup crc |
Kojto | 148:fd96258d940d | 38 | * @{ |
Kojto | 148:fd96258d940d | 39 | */ |
Kojto | 148:fd96258d940d | 40 | |
Kojto | 148:fd96258d940d | 41 | /*! @file */ |
Kojto | 148:fd96258d940d | 42 | |
Kojto | 148:fd96258d940d | 43 | /******************************************************************************* |
Kojto | 148:fd96258d940d | 44 | * Definitions |
Kojto | 148:fd96258d940d | 45 | ******************************************************************************/ |
Kojto | 148:fd96258d940d | 46 | |
Kojto | 148:fd96258d940d | 47 | /*! @name Driver version */ |
Kojto | 148:fd96258d940d | 48 | /*@{*/ |
Kojto | 148:fd96258d940d | 49 | /*! @brief CRC driver version. Version 2.0.0. |
Kojto | 148:fd96258d940d | 50 | * |
Kojto | 148:fd96258d940d | 51 | * Current version: 2.0.0 |
Kojto | 148:fd96258d940d | 52 | * |
Kojto | 148:fd96258d940d | 53 | * Change log: |
Kojto | 148:fd96258d940d | 54 | * - Version 2.0.0 |
Kojto | 148:fd96258d940d | 55 | * - initial version |
Kojto | 148:fd96258d940d | 56 | */ |
Kojto | 148:fd96258d940d | 57 | #define FSL_CRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) |
Kojto | 148:fd96258d940d | 58 | /*@}*/ |
Kojto | 148:fd96258d940d | 59 | |
Kojto | 148:fd96258d940d | 60 | #ifndef CRC_DRIVER_CUSTOM_DEFAULTS |
Kojto | 148:fd96258d940d | 61 | /*! @brief Default configuration structure filled by CRC_GetDefaultConfig(). Uses CRC-16/CCITT-FALSE as default. */ |
Kojto | 148:fd96258d940d | 62 | #define CRC_DRIVER_USE_CRC16_CCITT_FALSE_AS_DEFAULT 1 |
Kojto | 148:fd96258d940d | 63 | #endif |
Kojto | 148:fd96258d940d | 64 | |
Kojto | 148:fd96258d940d | 65 | /*! @brief CRC polynomials to use. */ |
Kojto | 148:fd96258d940d | 66 | typedef enum _crc_polynomial |
Kojto | 148:fd96258d940d | 67 | { |
Kojto | 148:fd96258d940d | 68 | kCRC_Polynomial_CRC_CCITT = 0U, /*!< x^16+x^12+x^5+1 */ |
Kojto | 148:fd96258d940d | 69 | kCRC_Polynomial_CRC_16 = 1U, /*!< x^16+x^15+x^2+1 */ |
Kojto | 148:fd96258d940d | 70 | kCRC_Polynomial_CRC_32 = 2U /*!< x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1 */ |
Kojto | 148:fd96258d940d | 71 | } crc_polynomial_t; |
Kojto | 148:fd96258d940d | 72 | |
Kojto | 148:fd96258d940d | 73 | /*! |
Kojto | 148:fd96258d940d | 74 | * @brief CRC protocol configuration. |
Kojto | 148:fd96258d940d | 75 | * |
Kojto | 148:fd96258d940d | 76 | * This structure holds the configuration for the CRC protocol. |
Kojto | 148:fd96258d940d | 77 | * |
Kojto | 148:fd96258d940d | 78 | */ |
Kojto | 148:fd96258d940d | 79 | typedef struct _crc_config |
Kojto | 148:fd96258d940d | 80 | { |
Kojto | 148:fd96258d940d | 81 | crc_polynomial_t polynomial; /*!< CRC polynomial. */ |
Kojto | 148:fd96258d940d | 82 | bool reverseIn; /*!< Reverse bits on input. */ |
Kojto | 148:fd96258d940d | 83 | bool complementIn; /*!< Perform 1's complement on input. */ |
Kojto | 148:fd96258d940d | 84 | bool reverseOut; /*!< Reverse bits on output. */ |
Kojto | 148:fd96258d940d | 85 | bool complementOut; /*!< Perform 1's complement on output. */ |
Kojto | 148:fd96258d940d | 86 | uint32_t seed; /*!< Starting checksum value. */ |
Kojto | 148:fd96258d940d | 87 | } crc_config_t; |
Kojto | 148:fd96258d940d | 88 | |
Kojto | 148:fd96258d940d | 89 | /******************************************************************************* |
Kojto | 148:fd96258d940d | 90 | * API |
Kojto | 148:fd96258d940d | 91 | ******************************************************************************/ |
Kojto | 148:fd96258d940d | 92 | #if defined(__cplusplus) |
Kojto | 148:fd96258d940d | 93 | extern "C" { |
Kojto | 148:fd96258d940d | 94 | #endif |
Kojto | 148:fd96258d940d | 95 | |
Kojto | 148:fd96258d940d | 96 | /*! |
Kojto | 148:fd96258d940d | 97 | * @brief Enables and configures the CRC peripheral module. |
Kojto | 148:fd96258d940d | 98 | * |
Kojto | 148:fd96258d940d | 99 | * This functions enables the CRC peripheral clock in the LPC SYSCON block. |
Kojto | 148:fd96258d940d | 100 | * It also configures the CRC engine and starts checksum computation by writing the seed. |
Kojto | 148:fd96258d940d | 101 | * |
Kojto | 148:fd96258d940d | 102 | * @param base CRC peripheral address. |
Kojto | 148:fd96258d940d | 103 | * @param config CRC module configuration structure. |
Kojto | 148:fd96258d940d | 104 | */ |
Kojto | 148:fd96258d940d | 105 | void CRC_Init(CRC_Type *base, const crc_config_t *config); |
Kojto | 148:fd96258d940d | 106 | |
Kojto | 148:fd96258d940d | 107 | /*! |
Kojto | 148:fd96258d940d | 108 | * @brief Disables the CRC peripheral module. |
Kojto | 148:fd96258d940d | 109 | * |
Kojto | 148:fd96258d940d | 110 | * This functions disables the CRC peripheral clock in the LPC SYSCON block. |
Kojto | 148:fd96258d940d | 111 | * |
Kojto | 148:fd96258d940d | 112 | * @param base CRC peripheral address. |
Kojto | 148:fd96258d940d | 113 | */ |
Kojto | 148:fd96258d940d | 114 | static inline void CRC_Deinit(CRC_Type *base) |
Kojto | 148:fd96258d940d | 115 | { |
Kojto | 148:fd96258d940d | 116 | /* disable clock to CRC */ |
Kojto | 148:fd96258d940d | 117 | CLOCK_DisableClock(kCLOCK_Crc); |
Kojto | 148:fd96258d940d | 118 | } |
Kojto | 148:fd96258d940d | 119 | |
Kojto | 148:fd96258d940d | 120 | /*! |
Kojto | 148:fd96258d940d | 121 | * @brief resets CRC peripheral module. |
Kojto | 148:fd96258d940d | 122 | * |
Kojto | 148:fd96258d940d | 123 | * @param base CRC peripheral address, currently not used. |
Kojto | 148:fd96258d940d | 124 | */ |
Kojto | 148:fd96258d940d | 125 | void CRC_Reset(CRC_Type *base); |
Kojto | 148:fd96258d940d | 126 | |
Kojto | 148:fd96258d940d | 127 | /*! |
Kojto | 148:fd96258d940d | 128 | * @brief Loads default values to CRC protocol configuration structure. |
Kojto | 148:fd96258d940d | 129 | * |
Kojto | 148:fd96258d940d | 130 | * Loads default values to CRC protocol configuration structure. The default values are: |
Kojto | 148:fd96258d940d | 131 | * @code |
Kojto | 148:fd96258d940d | 132 | * config->polynomial = kCRC_Polynomial_CRC_CCITT; |
Kojto | 148:fd96258d940d | 133 | * config->reverseIn = false; |
Kojto | 148:fd96258d940d | 134 | * config->complementIn = false; |
Kojto | 148:fd96258d940d | 135 | * config->reverseOut = false; |
Kojto | 148:fd96258d940d | 136 | * config->complementOut = false; |
Kojto | 148:fd96258d940d | 137 | * config->seed = 0xFFFFU; |
Kojto | 148:fd96258d940d | 138 | * @endcode |
Kojto | 148:fd96258d940d | 139 | * |
Kojto | 148:fd96258d940d | 140 | * @param config CRC protocol configuration structure |
Kojto | 148:fd96258d940d | 141 | */ |
Kojto | 148:fd96258d940d | 142 | void CRC_GetDefaultConfig(crc_config_t *config); |
Kojto | 148:fd96258d940d | 143 | |
Kojto | 148:fd96258d940d | 144 | /*! |
Kojto | 148:fd96258d940d | 145 | * @brief Loads actual values configured in CRC peripheral to CRC protocol configuration structure. |
Kojto | 148:fd96258d940d | 146 | * |
Kojto | 148:fd96258d940d | 147 | * The values, including seed, can be used to resume CRC calculation later. |
Kojto | 148:fd96258d940d | 148 | |
Kojto | 148:fd96258d940d | 149 | * @param base CRC peripheral address. |
Kojto | 148:fd96258d940d | 150 | * @param config CRC protocol configuration structure |
Kojto | 148:fd96258d940d | 151 | */ |
Kojto | 148:fd96258d940d | 152 | void CRC_GetConfig(CRC_Type *base, crc_config_t *config); |
Kojto | 148:fd96258d940d | 153 | |
Kojto | 148:fd96258d940d | 154 | /*! |
Kojto | 148:fd96258d940d | 155 | * @brief Writes data to the CRC module. |
Kojto | 148:fd96258d940d | 156 | * |
Kojto | 148:fd96258d940d | 157 | * Writes input data buffer bytes to CRC data register. |
Kojto | 148:fd96258d940d | 158 | * |
Kojto | 148:fd96258d940d | 159 | * @param base CRC peripheral address. |
Kojto | 148:fd96258d940d | 160 | * @param data Input data stream, MSByte in data[0]. |
Kojto | 148:fd96258d940d | 161 | * @param dataSize Size of the input data buffer in bytes. |
Kojto | 148:fd96258d940d | 162 | */ |
Kojto | 148:fd96258d940d | 163 | void CRC_WriteData(CRC_Type *base, const uint8_t *data, size_t dataSize); |
Kojto | 148:fd96258d940d | 164 | |
Kojto | 148:fd96258d940d | 165 | /*! |
Kojto | 148:fd96258d940d | 166 | * @brief Reads 32-bit checksum from the CRC module. |
Kojto | 148:fd96258d940d | 167 | * |
Kojto | 148:fd96258d940d | 168 | * Reads CRC data register. |
Kojto | 148:fd96258d940d | 169 | * |
Kojto | 148:fd96258d940d | 170 | * @param base CRC peripheral address. |
Kojto | 148:fd96258d940d | 171 | * @return final 32-bit checksum, after configured bit reverse and complement operations. |
Kojto | 148:fd96258d940d | 172 | */ |
Kojto | 148:fd96258d940d | 173 | static inline uint32_t CRC_Get32bitResult(CRC_Type *base) |
Kojto | 148:fd96258d940d | 174 | { |
Kojto | 148:fd96258d940d | 175 | return base->SUM; |
Kojto | 148:fd96258d940d | 176 | } |
Kojto | 148:fd96258d940d | 177 | |
Kojto | 148:fd96258d940d | 178 | /*! |
Kojto | 148:fd96258d940d | 179 | * @brief Reads 16-bit checksum from the CRC module. |
Kojto | 148:fd96258d940d | 180 | * |
Kojto | 148:fd96258d940d | 181 | * Reads CRC data register. |
Kojto | 148:fd96258d940d | 182 | * |
Kojto | 148:fd96258d940d | 183 | * @param base CRC peripheral address. |
Kojto | 148:fd96258d940d | 184 | * @return final 16-bit checksum, after configured bit reverse and complement operations. |
Kojto | 148:fd96258d940d | 185 | */ |
Kojto | 148:fd96258d940d | 186 | static inline uint16_t CRC_Get16bitResult(CRC_Type *base) |
Kojto | 148:fd96258d940d | 187 | { |
Kojto | 148:fd96258d940d | 188 | return (uint16_t)base->SUM; |
Kojto | 148:fd96258d940d | 189 | } |
Kojto | 148:fd96258d940d | 190 | |
Kojto | 148:fd96258d940d | 191 | #if defined(__cplusplus) |
Kojto | 148:fd96258d940d | 192 | } |
Kojto | 148:fd96258d940d | 193 | #endif |
Kojto | 148:fd96258d940d | 194 | |
Kojto | 148:fd96258d940d | 195 | /*! |
Kojto | 148:fd96258d940d | 196 | *@} |
Kojto | 148:fd96258d940d | 197 | */ |
Kojto | 148:fd96258d940d | 198 | |
Kojto | 148:fd96258d940d | 199 | #endif /* _FSL_CRC_H_ */ |