Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TUKS-COURSE-TIMER by
stm32l4xx_hal_crc_ex.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_crc_ex.c 00004 * @author MCD Application Team 00005 * @version V1.5.1 00006 * @date 31-May-2016 00007 * @brief Extended CRC HAL module driver. 00008 * This file provides firmware functions to manage the extended 00009 * functionalities of the CRC peripheral. 00010 * 00011 @verbatim 00012 ================================================================================ 00013 ##### How to use this driver ##### 00014 ================================================================================ 00015 [..] 00016 (+) Set user-defined generating polynomial thru HAL_CRCEx_Polynomial_Set() 00017 (+) Configure Input or Output data inversion 00018 00019 @endverbatim 00020 ****************************************************************************** 00021 * @attention 00022 * 00023 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00024 * 00025 * Redistribution and use in source and binary forms, with or without modification, 00026 * are permitted provided that the following conditions are met: 00027 * 1. Redistributions of source code must retain the above copyright notice, 00028 * this list of conditions and the following disclaimer. 00029 * 2. Redistributions in binary form must reproduce the above copyright notice, 00030 * this list of conditions and the following disclaimer in the documentation 00031 * and/or other materials provided with the distribution. 00032 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00033 * may be used to endorse or promote products derived from this software 00034 * without specific prior written permission. 00035 * 00036 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00037 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00038 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00040 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00041 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00042 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00043 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00044 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00045 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00046 * 00047 ****************************************************************************** 00048 */ 00049 00050 /* Includes ------------------------------------------------------------------*/ 00051 #include "stm32l4xx_hal.h" 00052 00053 /** @addtogroup STM32L4xx_HAL_Driver 00054 * @{ 00055 */ 00056 00057 /** @defgroup CRCEx CRCEx 00058 * @brief CRC Extended HAL module driver 00059 * @{ 00060 */ 00061 00062 #ifdef HAL_CRC_MODULE_ENABLED 00063 00064 /* Private typedef -----------------------------------------------------------*/ 00065 /* Private define ------------------------------------------------------------*/ 00066 /* Private macro -------------------------------------------------------------*/ 00067 /* Private variables ---------------------------------------------------------*/ 00068 /* Private function prototypes -----------------------------------------------*/ 00069 /* Exported functions --------------------------------------------------------*/ 00070 00071 /** @defgroup CRCEx_Exported_Functions CRC Extended Exported Functions 00072 * @{ 00073 */ 00074 00075 /** @defgroup CRCEx_Exported_Functions_Group1 Extended Initialization/de-initialization functions 00076 * @brief Extended Initialization and Configuration functions. 00077 * 00078 @verbatim 00079 =============================================================================== 00080 ##### Extended configuration functions ##### 00081 =============================================================================== 00082 [..] This section provides functions allowing to: 00083 (+) Configure the generating polynomial 00084 (+) Configure the input data inversion 00085 (+) Configure the output data inversion 00086 00087 @endverbatim 00088 * @{ 00089 */ 00090 00091 00092 /** 00093 * @brief Initialize the CRC polynomial if different from default one. 00094 * @param hcrc: CRC handle 00095 * @param Pol: CRC generating polynomial (7, 8, 16 or 32-bit long). 00096 * This parameter is written in normal representation, e.g. 00097 * @arg for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65 00098 * @arg for a polynomial of degree 16, X^16 + X^12 + X^5 + 1 is written 0x1021 00099 * @param PolyLength: CRC polynomial length. 00100 * This parameter can be one of the following values: 00101 * @arg @ref CRC_POLYLENGTH_7B 7-bit long CRC (generating polynomial of degree 7) 00102 * @arg @ref CRC_POLYLENGTH_8B 8-bit long CRC (generating polynomial of degree 8) 00103 * @arg @ref CRC_POLYLENGTH_16B 16-bit long CRC (generating polynomial of degree 16) 00104 * @arg @ref CRC_POLYLENGTH_32B 32-bit long CRC (generating polynomial of degree 32) 00105 * @retval HAL status 00106 */ 00107 HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength) 00108 { 00109 uint32_t msb = 31; /* polynomial degree is 32 at most, so msb is initialized to max value */ 00110 00111 /* Check the parameters */ 00112 assert_param(IS_CRC_POL_LENGTH(PolyLength)); 00113 00114 /* check polynomial definition vs polynomial size: 00115 * polynomial length must be aligned with polynomial 00116 * definition. HAL_ERROR is reported if Pol degree is 00117 * larger than that indicated by PolyLength. 00118 * Look for MSB position: msb will contain the degree of 00119 * the second to the largest polynomial member. E.g., for 00120 * X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */ 00121 while (((Pol & (1U << msb)) == 0) && (msb-- > 0)) {} 00122 00123 switch (PolyLength) 00124 { 00125 case CRC_POLYLENGTH_7B: 00126 if (msb >= HAL_CRC_LENGTH_7B) 00127 { 00128 return HAL_ERROR; 00129 } 00130 break; 00131 case CRC_POLYLENGTH_8B: 00132 if (msb >= HAL_CRC_LENGTH_8B) 00133 { 00134 return HAL_ERROR; 00135 } 00136 break; 00137 case CRC_POLYLENGTH_16B: 00138 if (msb >= HAL_CRC_LENGTH_16B) 00139 { 00140 return HAL_ERROR; 00141 } 00142 break; 00143 case CRC_POLYLENGTH_32B: 00144 /* no polynomial definition vs. polynomial length issue possible */ 00145 break; 00146 default: 00147 break; 00148 } 00149 00150 /* set generating polynomial */ 00151 WRITE_REG(hcrc->Instance->POL, Pol); 00152 00153 /* set generating polynomial size */ 00154 MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, PolyLength); 00155 00156 /* Return function status */ 00157 return HAL_OK; 00158 } 00159 00160 /** 00161 * @brief Set the Reverse Input data mode. 00162 * @param hcrc: CRC handle 00163 * @param InputReverseMode: Input Data inversion mode. 00164 * This parameter can be one of the following values: 00165 * @arg @ref CRC_INPUTDATA_INVERSION_NONE no change in bit order (default value) 00166 * @arg @ref CRC_INPUTDATA_INVERSION_BYTE Byte-wise bit reversal 00167 * @arg @ref CRC_INPUTDATA_INVERSION_HALFWORD HalfWord-wise bit reversal 00168 * @arg @ref CRC_INPUTDATA_INVERSION_WORD Word-wise bit reversal 00169 * @retval HAL status 00170 */ 00171 HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode) 00172 { 00173 /* Check the parameters */ 00174 assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(InputReverseMode)); 00175 00176 /* Change CRC peripheral state */ 00177 hcrc->State = HAL_CRC_STATE_BUSY; 00178 00179 /* set input data inversion mode */ 00180 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, InputReverseMode); 00181 /* Change CRC peripheral state */ 00182 hcrc->State = HAL_CRC_STATE_READY; 00183 00184 /* Return function status */ 00185 return HAL_OK; 00186 } 00187 00188 /** 00189 * @brief Set the Reverse Output data mode. 00190 * @param hcrc: CRC handle 00191 * @param OutputReverseMode: Output Data inversion mode. 00192 * This parameter can be one of the following values: 00193 * @arg @ref CRC_OUTPUTDATA_INVERSION_DISABLE no CRC inversion (default value) 00194 * @arg @ref CRC_OUTPUTDATA_INVERSION_ENABLE bit-level inversion (e.g. for a 8-bit CRC: 0xB5 becomes 0xAD) 00195 * @retval HAL status 00196 */ 00197 HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode) 00198 { 00199 /* Check the parameters */ 00200 assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(OutputReverseMode)); 00201 00202 /* Change CRC peripheral state */ 00203 hcrc->State = HAL_CRC_STATE_BUSY; 00204 00205 /* set output data inversion mode */ 00206 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, OutputReverseMode); 00207 00208 /* Change CRC peripheral state */ 00209 hcrc->State = HAL_CRC_STATE_READY; 00210 00211 /* Return function status */ 00212 return HAL_OK; 00213 } 00214 00215 00216 00217 00218 /** 00219 * @} 00220 */ 00221 00222 00223 /** 00224 * @} 00225 */ 00226 00227 00228 #endif /* HAL_CRC_MODULE_ENABLED */ 00229 /** 00230 * @} 00231 */ 00232 00233 /** 00234 * @} 00235 */ 00236 00237 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:38:49 by
