test

Committer:
elijahsj
Date:
Mon Nov 09 00:02:47 2020 -0500
Revision:
1:8a094db1347f
test

Who changed what in which revision?

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