test

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Nov 08 13:50:44 2017 +0000
Revision:
178:d650f5d4c87a
Parent:
150:02e0a0aed4ec
This updates the lib to the mbed lib v 155

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 150:02e0a0aed4ec 1 /**
<> 150:02e0a0aed4ec 2 * @file crc.h
<> 150:02e0a0aed4ec 3 * @brief CRC peripheral module function prototypes and data types.
<> 150:02e0a0aed4ec 4 */
<> 150:02e0a0aed4ec 5
<> 150:02e0a0aed4ec 6 /* ****************************************************************************
<> 150:02e0a0aed4ec 7 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
<> 150:02e0a0aed4ec 8 *
<> 150:02e0a0aed4ec 9 * Permission is hereby granted, free of charge, to any person obtaining a
<> 150:02e0a0aed4ec 10 * copy of this software and associated documentation files (the "Software"),
<> 150:02e0a0aed4ec 11 * to deal in the Software without restriction, including without limitation
<> 150:02e0a0aed4ec 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
<> 150:02e0a0aed4ec 13 * and/or sell copies of the Software, and to permit persons to whom the
<> 150:02e0a0aed4ec 14 * Software is furnished to do so, subject to the following conditions:
<> 150:02e0a0aed4ec 15 *
<> 150:02e0a0aed4ec 16 * The above copyright notice and this permission notice shall be included
<> 150:02e0a0aed4ec 17 * in all copies or substantial portions of the Software.
<> 150:02e0a0aed4ec 18 *
<> 150:02e0a0aed4ec 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
<> 150:02e0a0aed4ec 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
<> 150:02e0a0aed4ec 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
<> 150:02e0a0aed4ec 22 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
<> 150:02e0a0aed4ec 23 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
<> 150:02e0a0aed4ec 24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
<> 150:02e0a0aed4ec 25 * OTHER DEALINGS IN THE SOFTWARE.
<> 150:02e0a0aed4ec 26 *
<> 150:02e0a0aed4ec 27 * Except as contained in this notice, the name of Maxim Integrated
<> 150:02e0a0aed4ec 28 * Products, Inc. shall not be used except as stated in the Maxim Integrated
<> 150:02e0a0aed4ec 29 * Products, Inc. Branding Policy.
<> 150:02e0a0aed4ec 30 *
<> 150:02e0a0aed4ec 31 * The mere transfer of this software does not imply any licenses
<> 150:02e0a0aed4ec 32 * of trade secrets, proprietary technology, copyrights, patents,
<> 150:02e0a0aed4ec 33 * trademarks, maskwork rights, or any other form of intellectual
<> 150:02e0a0aed4ec 34 * property whatsoever. Maxim Integrated Products, Inc. retains all
<> 150:02e0a0aed4ec 35 * ownership rights.
<> 150:02e0a0aed4ec 36 *
<> 150:02e0a0aed4ec 37 * $Date: 2016-08-02 13:45:09 -0500 (Tue, 02 Aug 2016) $
<> 150:02e0a0aed4ec 38 * $Revision: 23897 $
<> 150:02e0a0aed4ec 39 *
<> 150:02e0a0aed4ec 40 **************************************************************************** */
<> 150:02e0a0aed4ec 41
<> 150:02e0a0aed4ec 42 /* Define to prevent redundant inclusion */
<> 150:02e0a0aed4ec 43 #ifndef _CRC_H_
<> 150:02e0a0aed4ec 44 #define _CRC_H_
<> 150:02e0a0aed4ec 45
<> 150:02e0a0aed4ec 46 #ifdef __cplusplus
<> 150:02e0a0aed4ec 47 extern "C" {
<> 150:02e0a0aed4ec 48 #endif
<> 150:02e0a0aed4ec 49
<> 150:02e0a0aed4ec 50 /**
<> 150:02e0a0aed4ec 51 * @defgroup crc Cyclic Redundancy Check (CRC)
<> 150:02e0a0aed4ec 52 * @ingroup periphlibs
<> 150:02e0a0aed4ec 53 * @brief High-level API for CRC Peripheral Module
<> 150:02e0a0aed4ec 54 * @{
<> 150:02e0a0aed4ec 55 */
<> 150:02e0a0aed4ec 56
<> 150:02e0a0aed4ec 57 /**
<> 150:02e0a0aed4ec 58 * @page crc_overview Overview and Usage
<> 150:02e0a0aed4ec 59 * @parblock
<> 150:02e0a0aed4ec 60 * - Initialize the CRC for usage by calling either the CRC16_Init() function or the CRC32_Init() funciton
<> 150:02e0a0aed4ec 61 * + For CRC16, CCITT mode is enabled if the parameter is set
<> 150:02e0a0aed4ec 62 * + Select the Endian of the data for calculation
<> 150:02e0a0aed4ec 63 * - passing a 1 sets the module to little endian
<> 150:02e0a0aed4ec 64 * - passing a 0 sets the module to big endian
<> 150:02e0a0aed4ec 65 * - Set the intial CRC seed by calling CRC16_Reseed() or CRC32_Reseed()
<> 150:02e0a0aed4ec 66 * + This is the initial value of the CRC remainder to be used when the data is passed to the module
<> 150:02e0a0aed4ec 67 * - Pass data to the CRC engine using the methods:
<> 150:02e0a0aed4ec 68 * + CRC16_AddData()
<> 150:02e0a0aed4ec 69 * + CRC16_AddDataArray()
<> 150:02e0a0aed4ec 70 * + CRC32_AddData()
<> 150:02e0a0aed4ec 71 * + CRC32_AddDataArray()
<> 150:02e0a0aed4ec 72 * @note any data passed to the add methods of the peripheral is padded with zeros if it is less than
<> 150:02e0a0aed4ec 73 * 32-bits.
<> 150:02e0a0aed4ec 74 * @endparblock
<> 150:02e0a0aed4ec 75 */
<> 150:02e0a0aed4ec 76
<> 150:02e0a0aed4ec 77
<> 150:02e0a0aed4ec 78 /* **** Includes **** */
<> 150:02e0a0aed4ec 79 #include "mxc_config.h"
<> 150:02e0a0aed4ec 80 #include <string.h>
<> 150:02e0a0aed4ec 81 #include "crc_regs.h"
<> 150:02e0a0aed4ec 82
<> 150:02e0a0aed4ec 83 /* **** Definitions **** */
<> 150:02e0a0aed4ec 84
<> 150:02e0a0aed4ec 85 /* **** Globals **** */
<> 150:02e0a0aed4ec 86
<> 150:02e0a0aed4ec 87 /* **** Function Prototypes **** */
<> 150:02e0a0aed4ec 88
<> 150:02e0a0aed4ec 89 /**
<> 150:02e0a0aed4ec 90 * @brief Initialize CRC clock and select CRC16 mode and byte order.
<> 150:02e0a0aed4ec 91 *
<> 150:02e0a0aed4ec 92 * @param CCITT_TRUE CRC16-CCITT-TRUE = 1, CRC16-CCITT-FALSE = 0
<> 150:02e0a0aed4ec 93 * @param lilEndian byte order, little endian = 1, big endian = 0
<> 150:02e0a0aed4ec 94 */
<> 150:02e0a0aed4ec 95 void CRC16_Init(uint8_t CCITT_TRUE, uint8_t lilEndian);
<> 150:02e0a0aed4ec 96
<> 150:02e0a0aed4ec 97 /**
<> 150:02e0a0aed4ec 98 * @brief Initialize CRC clock and select byte order for CRC32.
<> 150:02e0a0aed4ec 99 *
<> 150:02e0a0aed4ec 100 * @param lilEndian byte order, little endian = 1, big endian = 0
<> 150:02e0a0aed4ec 101 */
<> 150:02e0a0aed4ec 102 void CRC32_Init(uint8_t lilEndian);
<> 150:02e0a0aed4ec 103
<> 150:02e0a0aed4ec 104 /**
<> 150:02e0a0aed4ec 105 * @brief Initialize CRC16 calculation.
<> 150:02e0a0aed4ec 106 *
<> 150:02e0a0aed4ec 107 * @param initData intial remainder to start the CRC16 calculation with
<> 150:02e0a0aed4ec 108 */
<> 150:02e0a0aed4ec 109 void CRC16_Reseed(uint16_t initData);
<> 150:02e0a0aed4ec 110
<> 150:02e0a0aed4ec 111 /**
<> 150:02e0a0aed4ec 112 * @brief Initialize CRC32 calculation.
<> 150:02e0a0aed4ec 113 *
<> 150:02e0a0aed4ec 114 * @param initData intial remainder to start the CRC32 calculation with
<> 150:02e0a0aed4ec 115 */
<> 150:02e0a0aed4ec 116 void CRC32_Reseed(uint32_t initData);
<> 150:02e0a0aed4ec 117
<> 150:02e0a0aed4ec 118 /**
<> 150:02e0a0aed4ec 119 * @brief Add data to the CRC16 calculation.
<> 150:02e0a0aed4ec 120 *
<> 150:02e0a0aed4ec 121 * @param data data to add to the CRC16 calculation
<> 150:02e0a0aed4ec 122 * @note data is padded with zeros if less than 32bits.
<> 150:02e0a0aed4ec 123 */
<> 150:02e0a0aed4ec 124 __STATIC_INLINE void CRC16_AddData(uint32_t data)
<> 150:02e0a0aed4ec 125 {
<> 150:02e0a0aed4ec 126 MXC_CRC_DATA->value16[0] = data;
<> 150:02e0a0aed4ec 127 }
<> 150:02e0a0aed4ec 128
<> 150:02e0a0aed4ec 129 /**
<> 150:02e0a0aed4ec 130 * @brief Add data to the CRC32 calculation
<> 150:02e0a0aed4ec 131 *
<> 150:02e0a0aed4ec 132 * @param data data to add to the CRC32 calculation
<> 150:02e0a0aed4ec 133 * @note data is padded with zeros if less than 32bits
<> 150:02e0a0aed4ec 134 */
<> 150:02e0a0aed4ec 135 __STATIC_INLINE void CRC32_AddData(uint32_t data)
<> 150:02e0a0aed4ec 136 {
<> 150:02e0a0aed4ec 137 MXC_CRC_DATA->value32[0] = data;
<> 150:02e0a0aed4ec 138 }
<> 150:02e0a0aed4ec 139
<> 150:02e0a0aed4ec 140 /**
<> 150:02e0a0aed4ec 141 * @brief Add an array of data to the CRC16 calculation
<> 150:02e0a0aed4ec 142 *
<> 150:02e0a0aed4ec 143 * @param data pointer to array of data
<> 150:02e0a0aed4ec 144 * @note data is padded with zeros if less than 32bits
<> 150:02e0a0aed4ec 145 *
<> 150:02e0a0aed4ec 146 * @param arrayLength number of elements in array
<> 150:02e0a0aed4ec 147 */
<> 150:02e0a0aed4ec 148 __STATIC_INLINE void CRC16_AddDataArray(uint32_t *data, uint32_t arrayLength)
<> 150:02e0a0aed4ec 149 {
<> 150:02e0a0aed4ec 150 memcpy((void *)(&(MXC_CRC_DATA->value16)), (void *)data, arrayLength * sizeof(data[0]));
<> 150:02e0a0aed4ec 151 }
<> 150:02e0a0aed4ec 152
<> 150:02e0a0aed4ec 153 /**
<> 150:02e0a0aed4ec 154 * @brief Add an array of data to the CRC32 calculation
<> 150:02e0a0aed4ec 155 *
<> 150:02e0a0aed4ec 156 * @param data pointer to array of data
<> 150:02e0a0aed4ec 157 * @note data is padded with zeros if less than 32bits
<> 150:02e0a0aed4ec 158 * @param arrayLength number of elements in array
<> 150:02e0a0aed4ec 159 */
<> 150:02e0a0aed4ec 160 __STATIC_INLINE void CRC32_AddDataArray(uint32_t *data, uint32_t arrayLength)
<> 150:02e0a0aed4ec 161 {
<> 150:02e0a0aed4ec 162 memcpy((void *)(&(MXC_CRC_DATA->value32)), (void *)data, arrayLength * sizeof(data[0]));
<> 150:02e0a0aed4ec 163 }
<> 150:02e0a0aed4ec 164
<> 150:02e0a0aed4ec 165 /**
<> 150:02e0a0aed4ec 166 * @brief Get the calculated CRC16 value
<> 150:02e0a0aed4ec 167 *
<> 150:02e0a0aed4ec 168 * @return CRC16 value
<> 150:02e0a0aed4ec 169 */
<> 150:02e0a0aed4ec 170 __STATIC_INLINE uint32_t CRC16_GetCRC()
<> 150:02e0a0aed4ec 171 {
<> 150:02e0a0aed4ec 172 return MXC_CRC_DATA->value16[0];
<> 150:02e0a0aed4ec 173 }
<> 150:02e0a0aed4ec 174
<> 150:02e0a0aed4ec 175 /**
<> 150:02e0a0aed4ec 176 * @brief Get the calculated CRC32 value
<> 150:02e0a0aed4ec 177 *
<> 150:02e0a0aed4ec 178 * @return CRC32 value
<> 150:02e0a0aed4ec 179 */
<> 150:02e0a0aed4ec 180 __STATIC_INLINE uint32_t CRC32_GetCRC()
<> 150:02e0a0aed4ec 181 {
<> 150:02e0a0aed4ec 182 return MXC_CRC_DATA->value32[0];
<> 150:02e0a0aed4ec 183 }
<> 150:02e0a0aed4ec 184
<> 150:02e0a0aed4ec 185 /**@} end of crc group */
<> 150:02e0a0aed4ec 186
<> 150:02e0a0aed4ec 187 #ifdef __cplusplus
<> 150:02e0a0aed4ec 188 }
<> 150:02e0a0aed4ec 189 #endif
<> 150:02e0a0aed4ec 190
<> 150:02e0a0aed4ec 191 #endif /* _CRC_H_ */