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