BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:47:08 2018 +0000
Revision:
1:9c5af431a1f1
sdf

Who changed what in which revision?

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