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:
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?

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