SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phungductung 0:8ede47d38d10 1 /**
phungductung 0:8ede47d38d10 2 ******************************************************************************
phungductung 0:8ede47d38d10 3 * @file stm32f7xx_hal_crc_ex.c
phungductung 0:8ede47d38d10 4 * @author MCD Application Team
phungductung 0:8ede47d38d10 5 * @version V1.0.4
phungductung 0:8ede47d38d10 6 * @date 09-December-2015
phungductung 0:8ede47d38d10 7 * @brief Extended CRC HAL module driver.
phungductung 0:8ede47d38d10 8 *
phungductung 0:8ede47d38d10 9 * This file provides firmware functions to manage the following
phungductung 0:8ede47d38d10 10 * functionalities of the CRC peripheral:
phungductung 0:8ede47d38d10 11 * + Initialization/de-initialization functions
phungductung 0:8ede47d38d10 12 *
phungductung 0:8ede47d38d10 13 @verbatim
phungductung 0:8ede47d38d10 14 ==============================================================================
phungductung 0:8ede47d38d10 15 ##### CRC specific features #####
phungductung 0:8ede47d38d10 16 ==============================================================================
phungductung 0:8ede47d38d10 17 [..]
phungductung 0:8ede47d38d10 18 (#) Polynomial configuration.
phungductung 0:8ede47d38d10 19 (#) Input data reverse mode.
phungductung 0:8ede47d38d10 20 (#) Output data reverse mode.
phungductung 0:8ede47d38d10 21
phungductung 0:8ede47d38d10 22 @endverbatim
phungductung 0:8ede47d38d10 23 ******************************************************************************
phungductung 0:8ede47d38d10 24 * @attention
phungductung 0:8ede47d38d10 25 *
phungductung 0:8ede47d38d10 26 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
phungductung 0:8ede47d38d10 27 *
phungductung 0:8ede47d38d10 28 * Redistribution and use in source and binary forms, with or without modification,
phungductung 0:8ede47d38d10 29 * are permitted provided that the following conditions are met:
phungductung 0:8ede47d38d10 30 * 1. Redistributions of source code must retain the above copyright notice,
phungductung 0:8ede47d38d10 31 * this list of conditions and the following disclaimer.
phungductung 0:8ede47d38d10 32 * 2. Redistributions in binary form must reproduce the above copyright notice,
phungductung 0:8ede47d38d10 33 * this list of conditions and the following disclaimer in the documentation
phungductung 0:8ede47d38d10 34 * and/or other materials provided with the distribution.
phungductung 0:8ede47d38d10 35 * 3. Neither the name of STMicroelectronics nor the names of its contributors
phungductung 0:8ede47d38d10 36 * may be used to endorse or promote products derived from this software
phungductung 0:8ede47d38d10 37 * without specific prior written permission.
phungductung 0:8ede47d38d10 38 *
phungductung 0:8ede47d38d10 39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
phungductung 0:8ede47d38d10 40 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
phungductung 0:8ede47d38d10 41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
phungductung 0:8ede47d38d10 42 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
phungductung 0:8ede47d38d10 43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
phungductung 0:8ede47d38d10 44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
phungductung 0:8ede47d38d10 45 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
phungductung 0:8ede47d38d10 46 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
phungductung 0:8ede47d38d10 47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
phungductung 0:8ede47d38d10 48 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
phungductung 0:8ede47d38d10 49 *
phungductung 0:8ede47d38d10 50 ******************************************************************************
phungductung 0:8ede47d38d10 51 */
phungductung 0:8ede47d38d10 52
phungductung 0:8ede47d38d10 53 /* Includes ------------------------------------------------------------------*/
phungductung 0:8ede47d38d10 54 #include "stm32f7xx_hal.h"
phungductung 0:8ede47d38d10 55
phungductung 0:8ede47d38d10 56 /** @addtogroup STM32F7xx_HAL_Driver
phungductung 0:8ede47d38d10 57 * @{
phungductung 0:8ede47d38d10 58 */
phungductung 0:8ede47d38d10 59
phungductung 0:8ede47d38d10 60 /** @addtogroup CRCEx
phungductung 0:8ede47d38d10 61 * @brief CRC Extended HAL module driver
phungductung 0:8ede47d38d10 62 * @{
phungductung 0:8ede47d38d10 63 */
phungductung 0:8ede47d38d10 64
phungductung 0:8ede47d38d10 65 #ifdef HAL_CRC_MODULE_ENABLED
phungductung 0:8ede47d38d10 66
phungductung 0:8ede47d38d10 67 /* Private typedef -----------------------------------------------------------*/
phungductung 0:8ede47d38d10 68 /* Private define ------------------------------------------------------------*/
phungductung 0:8ede47d38d10 69 /* Private macro -------------------------------------------------------------*/
phungductung 0:8ede47d38d10 70 /* Private variables ---------------------------------------------------------*/
phungductung 0:8ede47d38d10 71 /* Private function prototypes -----------------------------------------------*/
phungductung 0:8ede47d38d10 72 /* Private functions ---------------------------------------------------------*/
phungductung 0:8ede47d38d10 73
phungductung 0:8ede47d38d10 74 /** @addtogroup CRCEx_Exported_Functions
phungductung 0:8ede47d38d10 75 * @{
phungductung 0:8ede47d38d10 76 */
phungductung 0:8ede47d38d10 77
phungductung 0:8ede47d38d10 78 /** @addtogroup CRCEx_Exported_Functions_Group1
phungductung 0:8ede47d38d10 79 * @brief Extended CRC features functions
phungductung 0:8ede47d38d10 80 *
phungductung 0:8ede47d38d10 81 @verbatim
phungductung 0:8ede47d38d10 82 ===============================================================================
phungductung 0:8ede47d38d10 83 ##### CRC Extended features functions #####
phungductung 0:8ede47d38d10 84 ===============================================================================
phungductung 0:8ede47d38d10 85 [..]
phungductung 0:8ede47d38d10 86 This subsection provides function allowing to:
phungductung 0:8ede47d38d10 87 (+) Set CRC polynomial if different from default one.
phungductung 0:8ede47d38d10 88
phungductung 0:8ede47d38d10 89 @endverbatim
phungductung 0:8ede47d38d10 90 * @{
phungductung 0:8ede47d38d10 91 */
phungductung 0:8ede47d38d10 92
phungductung 0:8ede47d38d10 93
phungductung 0:8ede47d38d10 94 /**
phungductung 0:8ede47d38d10 95 * @brief Initializes the CRC polynomial if different from default one.
phungductung 0:8ede47d38d10 96 * @param hcrc: CRC handle
phungductung 0:8ede47d38d10 97 * @param Pol: CRC generating polynomial (7, 8, 16 or 32-bit long)
phungductung 0:8ede47d38d10 98 * This parameter is written in normal representation, e.g.
phungductung 0:8ede47d38d10 99 * for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
phungductung 0:8ede47d38d10 100 * for a polynomial of degree 16, X^16 + X^12 + X^5 + 1 is written 0x1021
phungductung 0:8ede47d38d10 101 * @param PolyLength: CRC polynomial length
phungductung 0:8ede47d38d10 102 * This parameter can be one of the following values:
phungductung 0:8ede47d38d10 103 * @arg CRC_POLYLENGTH_7B: 7-bit long CRC (generating polynomial of degree 7)
phungductung 0:8ede47d38d10 104 * @arg CRC_POLYLENGTH_8B: 8-bit long CRC (generating polynomial of degree 8)
phungductung 0:8ede47d38d10 105 * @arg CRC_POLYLENGTH_16B: 16-bit long CRC (generating polynomial of degree 16)
phungductung 0:8ede47d38d10 106 * @arg CRC_POLYLENGTH_32B: 32-bit long CRC (generating polynomial of degree 32)
phungductung 0:8ede47d38d10 107 * @retval HAL status
phungductung 0:8ede47d38d10 108 */
phungductung 0:8ede47d38d10 109 HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength)
phungductung 0:8ede47d38d10 110 {
phungductung 0:8ede47d38d10 111 uint32_t msb = 31; /* polynomial degree is 32 at most, so msb is initialized to max value */
phungductung 0:8ede47d38d10 112
phungductung 0:8ede47d38d10 113 /* Check the parameters */
phungductung 0:8ede47d38d10 114 assert_param(IS_CRC_POL_LENGTH(PolyLength));
phungductung 0:8ede47d38d10 115
phungductung 0:8ede47d38d10 116 /* check polynomial definition vs polynomial size:
phungductung 0:8ede47d38d10 117 * polynomial length must be aligned with polynomial
phungductung 0:8ede47d38d10 118 * definition. HAL_ERROR is reported if Pol degree is
phungductung 0:8ede47d38d10 119 * larger than that indicated by PolyLength.
phungductung 0:8ede47d38d10 120 * Look for MSB position: msb will contain the degree of
phungductung 0:8ede47d38d10 121 * the second to the largest polynomial member. E.g., for
phungductung 0:8ede47d38d10 122 * X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */
phungductung 0:8ede47d38d10 123 while (((Pol & ((uint32_t)(0x1) << msb)) == 0) && (msb-- > 0))
phungductung 0:8ede47d38d10 124 {
phungductung 0:8ede47d38d10 125 }
phungductung 0:8ede47d38d10 126
phungductung 0:8ede47d38d10 127 switch (PolyLength)
phungductung 0:8ede47d38d10 128 {
phungductung 0:8ede47d38d10 129 case CRC_POLYLENGTH_7B:
phungductung 0:8ede47d38d10 130 if (msb >= HAL_CRC_LENGTH_7B)
phungductung 0:8ede47d38d10 131 {
phungductung 0:8ede47d38d10 132 return HAL_ERROR;
phungductung 0:8ede47d38d10 133 }
phungductung 0:8ede47d38d10 134 break;
phungductung 0:8ede47d38d10 135 case CRC_POLYLENGTH_8B:
phungductung 0:8ede47d38d10 136 if (msb >= HAL_CRC_LENGTH_8B)
phungductung 0:8ede47d38d10 137 {
phungductung 0:8ede47d38d10 138 return HAL_ERROR;
phungductung 0:8ede47d38d10 139 }
phungductung 0:8ede47d38d10 140 break;
phungductung 0:8ede47d38d10 141 case CRC_POLYLENGTH_16B:
phungductung 0:8ede47d38d10 142 if (msb >= HAL_CRC_LENGTH_16B)
phungductung 0:8ede47d38d10 143 {
phungductung 0:8ede47d38d10 144 return HAL_ERROR;
phungductung 0:8ede47d38d10 145 }
phungductung 0:8ede47d38d10 146 break;
phungductung 0:8ede47d38d10 147 case CRC_POLYLENGTH_32B:
phungductung 0:8ede47d38d10 148 /* no polynomial definition vs. polynomial length issue possible */
phungductung 0:8ede47d38d10 149 break;
phungductung 0:8ede47d38d10 150 default:
phungductung 0:8ede47d38d10 151 break;
phungductung 0:8ede47d38d10 152 }
phungductung 0:8ede47d38d10 153
phungductung 0:8ede47d38d10 154 /* set generating polynomial */
phungductung 0:8ede47d38d10 155 WRITE_REG(hcrc->Instance->POL, Pol);
phungductung 0:8ede47d38d10 156
phungductung 0:8ede47d38d10 157 /* set generating polynomial size */
phungductung 0:8ede47d38d10 158 MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, PolyLength);
phungductung 0:8ede47d38d10 159
phungductung 0:8ede47d38d10 160 /* Return function status */
phungductung 0:8ede47d38d10 161 return HAL_OK;
phungductung 0:8ede47d38d10 162 }
phungductung 0:8ede47d38d10 163
phungductung 0:8ede47d38d10 164 /**
phungductung 0:8ede47d38d10 165 * @brief Set the Reverse Input data mode.
phungductung 0:8ede47d38d10 166 * @param hcrc: CRC handle
phungductung 0:8ede47d38d10 167 * @param InputReverseMode: Input Data inversion mode
phungductung 0:8ede47d38d10 168 * This parameter can be one of the following values:
phungductung 0:8ede47d38d10 169 * @arg CRC_INPUTDATA_INVERSION_NONE: no change in bit order (default value)
phungductung 0:8ede47d38d10 170 * @arg CRC_INPUTDATA_INVERSION_BYTE: Byte-wise bit reversal
phungductung 0:8ede47d38d10 171 * @arg CRC_INPUTDATA_INVERSION_HALFWORD: HalfWord-wise bit reversal
phungductung 0:8ede47d38d10 172 * @arg CRC_INPUTDATA_INVERSION_WORD: Word-wise bit reversal
phungductung 0:8ede47d38d10 173 * @retval HAL status
phungductung 0:8ede47d38d10 174 */
phungductung 0:8ede47d38d10 175 HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode)
phungductung 0:8ede47d38d10 176 {
phungductung 0:8ede47d38d10 177 /* Check the parameters */
phungductung 0:8ede47d38d10 178 assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(InputReverseMode));
phungductung 0:8ede47d38d10 179
phungductung 0:8ede47d38d10 180 /* Change CRC peripheral state */
phungductung 0:8ede47d38d10 181 hcrc->State = HAL_CRC_STATE_BUSY;
phungductung 0:8ede47d38d10 182
phungductung 0:8ede47d38d10 183 /* set input data inversion mode */
phungductung 0:8ede47d38d10 184 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, InputReverseMode);
phungductung 0:8ede47d38d10 185 /* Change CRC peripheral state */
phungductung 0:8ede47d38d10 186 hcrc->State = HAL_CRC_STATE_READY;
phungductung 0:8ede47d38d10 187
phungductung 0:8ede47d38d10 188 /* Return function status */
phungductung 0:8ede47d38d10 189 return HAL_OK;
phungductung 0:8ede47d38d10 190 }
phungductung 0:8ede47d38d10 191
phungductung 0:8ede47d38d10 192 /**
phungductung 0:8ede47d38d10 193 * @brief Set the Reverse Output data mode.
phungductung 0:8ede47d38d10 194 * @param hcrc: CRC handle
phungductung 0:8ede47d38d10 195 * @param OutputReverseMode: Output Data inversion mode
phungductung 0:8ede47d38d10 196 * This parameter can be one of the following values:
phungductung 0:8ede47d38d10 197 * @arg CRC_OUTPUTDATA_INVERSION_DISABLE: no CRC inversion (default value)
phungductung 0:8ede47d38d10 198 * @arg CRC_OUTPUTDATA_INVERSION_ENABLE: bit-level inversion (e.g for a 8-bit CRC: 0xB5 becomes 0xAD)
phungductung 0:8ede47d38d10 199 * @retval HAL status
phungductung 0:8ede47d38d10 200 */
phungductung 0:8ede47d38d10 201 HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode)
phungductung 0:8ede47d38d10 202 {
phungductung 0:8ede47d38d10 203 /* Check the parameters */
phungductung 0:8ede47d38d10 204 assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(OutputReverseMode));
phungductung 0:8ede47d38d10 205
phungductung 0:8ede47d38d10 206 /* Change CRC peripheral state */
phungductung 0:8ede47d38d10 207 hcrc->State = HAL_CRC_STATE_BUSY;
phungductung 0:8ede47d38d10 208
phungductung 0:8ede47d38d10 209 /* set output data inversion mode */
phungductung 0:8ede47d38d10 210 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, OutputReverseMode);
phungductung 0:8ede47d38d10 211
phungductung 0:8ede47d38d10 212 /* Change CRC peripheral state */
phungductung 0:8ede47d38d10 213 hcrc->State = HAL_CRC_STATE_READY;
phungductung 0:8ede47d38d10 214
phungductung 0:8ede47d38d10 215 /* Return function status */
phungductung 0:8ede47d38d10 216 return HAL_OK;
phungductung 0:8ede47d38d10 217 }
phungductung 0:8ede47d38d10 218
phungductung 0:8ede47d38d10 219
phungductung 0:8ede47d38d10 220
phungductung 0:8ede47d38d10 221
phungductung 0:8ede47d38d10 222 /**
phungductung 0:8ede47d38d10 223 * @}
phungductung 0:8ede47d38d10 224 */
phungductung 0:8ede47d38d10 225
phungductung 0:8ede47d38d10 226
phungductung 0:8ede47d38d10 227 /**
phungductung 0:8ede47d38d10 228 * @}
phungductung 0:8ede47d38d10 229 */
phungductung 0:8ede47d38d10 230
phungductung 0:8ede47d38d10 231
phungductung 0:8ede47d38d10 232 #endif /* HAL_CRC_MODULE_ENABLED */
phungductung 0:8ede47d38d10 233 /**
phungductung 0:8ede47d38d10 234 * @}
phungductung 0:8ede47d38d10 235 */
phungductung 0:8ede47d38d10 236
phungductung 0:8ede47d38d10 237 /**
phungductung 0:8ede47d38d10 238 * @}
phungductung 0:8ede47d38d10 239 */
phungductung 0:8ede47d38d10 240
phungductung 0:8ede47d38d10 241 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
phungductung 0:8ede47d38d10 242