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