1 /** 2 ****************************************************************************** 3 * @file tae32f53xx_ll_iir.h 4 * @author MCD Application Team 5 * @brief Header file of IIR LL module. 6 * 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© Copyright (c) 2020 Tai-Action. 11 * All rights reserved.</center></h2> 12 * 13 * This software is licensed by Tai-Action under BSD 3-Clause license, 14 * the "License"; You may not use this file except in compliance with the 15 * License. You may obtain a copy of the License at: 16 * opensource.org/licenses/BSD-3-Clause 17 * 18 ****************************************************************************** 19 */ 20 21 /* Define to prevent recursive inclusion -------------------------------------*/ 22 #ifndef _TAE32F53XX_LL_IIR_H_ 23 #define _TAE32F53XX_LL_IIR_H_ 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif /* __cplusplus */ 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include "tae32f53xx_ll_def.h" 31 32 33 /** @addtogroup TAE32F53xx_LL_Driver 34 * @{ 35 */ 36 37 /** @addtogroup IIR_LL 38 * @{ 39 */ 40 41 42 /* Exported types ------------------------------------------------------------*/ 43 /** @defgroup IIR_LL_Exported_Types IIR LL Exported Types 44 * @brief IIR LL Exported Types 45 * @{ 46 */ 47 48 /** 49 * @brief IIR Order type definition 50 */ 51 typedef enum { 52 IIR_ORDER_1 = 0x00000000UL, /*!< Source Peripheral bus AHB Master1 */ 53 IIR_ORDER_2 = IIR_CR0_ORD_0, /*!< IIR order 2 */ 54 IIR_ORDER_3 = IIR_CR0_ORD_1, /*!< IIR order 3 */ 55 IIR_ORDER_4 = (IIR_CR0_ORD_0 | IIR_CR0_ORD_1), /*!< IIR order 4 */ 56 } IIR_OrderETypeDef; 57 58 /* 59 * @brief IIR internal data buffer reset or not 60 */ 61 typedef enum { 62 IIR_BUFFER_NO_RESET = 0x00000000UL, /*!< Do nothing to IIR Internal Data Buffer */ 63 IIR_BUFFER_RESET = IIR_CR0_IBRST, /*!< IIR Internal Data Buffer should reset */ 64 } IIR_BufferETypeDef; 65 66 67 /** 68 * @brief IIR Auto-Reload mode enable or disable 69 */ 70 typedef enum { 71 IIR_AUTORELOAD_DISABLE = 0x00000000UL, /*!< IIR Auto-Reload mode disable */ 72 IIR_AUTORELOAD_ENABLE = IIR_CR1_AREN, /*!< IIR Auto-Reload mode enable */ 73 } IIR_ATReloadETypeDef; 74 75 /** 76 * @brief IIR initialization structure definition 77 */ 78 typedef struct __IIR_InitTypeDef { 79 IIR_OrderETypeDef Order; /*!< Specifies the IIR order */ 80 IIR_BufferETypeDef BufferReset; /*!< Indicate to reset the internal data buffer or not */ 81 } IIR_InitTypeDef; 82 83 /** 84 * @brief IIR configuration structure definition 85 */ 86 typedef struct __IIR_ConfigTypeDef { 87 uint32_t InDataAddress; /*!< Specifies the input data address in memory area. 88 The address must be aligned to 16-bit boundary in specifies memory areas(For 89 more information, please see the documents of system architecture designs) */ 90 91 uint32_t InDataScale; /*!< Specifies magnify scale for the input data. 92 This parameter can be a value between 0 to 16 which stand for the input data 93 magnified 2^0 to 2^16 times */ 94 95 uint32_t FeedBackScale; /*!< Specifies the feekback narrow scale. 96 This parameter can be a value between 0 to 31 which stand for feedback 97 narrowed 2^0 to 2^31 times */ 98 99 uint32_t OutDataScale; /*!< Specifies narrow scale for the output data. 100 This parameter can be a value between 0 to 31 which stand for the output data 101 narrowed 2^0 to 2^31 times */ 102 103 int16_t AxCOEF[4]; /*!< Specifies the coefficient A. 104 This parameter can be a value between -32768 to +32767 */ 105 106 int16_t BxCOEF[5]; /*!< Specifies the coefficient B. 107 This parameter can be a value between -32768 to +32767 */ 108 } IIR_ConfigTypeDef; 109 110 /** 111 * @} 112 */ 113 114 115 /* Exported constants --------------------------------------------------------*/ 116 /** @defgroup IIR_LL_Exported_Constants IIR LL Exported Constants 117 * @brief IIR LL Exported Constants 118 * @{ 119 */ 120 121 /** @defgroup IIR_Flag_definition IIR Flag Definition 122 * @{ 123 */ 124 #define IIR_FLAG_FDIF IIR_ISR_FDIF /*!< IIR Filter Done Interrupt Flag */ 125 /** 126 * @} 127 */ 128 129 /** @defgroup IIR_Interrupt_definition IIR Interrupt Definition 130 * @{ 131 */ 132 #define IIR_IT_FDIE IIR_IER_IE /*!< IIR Filter Done Interrupt Enable */ 133 /** 134 * @} 135 */ 136 137 /** 138 * @} 139 */ 140 141 142 /* Exported macro ------------------------------------------------------------*/ 143 /** @defgroup IIR_LL_Exported_Macros IIR LL Exported Macros 144 * @brief IIR LL Exported Macros 145 * @{ 146 */ 147 148 /** 149 * @brief Enable the specified IIR interrupt. 150 * @param __INSTANCE__ IIR peripheral 151 * @param __INTERRUPT__ specifies the IIR interrupt source to enable. 152 * This parameter can be one of the following values: 153 * @arg IIR_IT_FDIE: Filiter Done Interrupt Enable 154 * @return None 155 */ 156 #define __LL_IIR_ENABLE_IT(__INSTANCE__, __INTERRUPT__) SET_BIT((__INSTANCE__)->IER, __INTERRUPT__) 157 158 159 /** 160 * @brief Disable the specified IIR interrupt. 161 * @param __INSTANCE__ IIR peripheral 162 * @param __INTERRUPT__ specifies the IIR interrupt source to disable. 163 * This parameter can be one of the following values: 164 * @arg IIR_IT_FDIE: Filiter Done Interrupt Enable 165 * @return None 166 */ 167 #define __LL_IIR_DISABLE_IT(__INSTANCE__, __INTERRUPT__) CLEAR_BIT((__INSTANCE__)->IER, __INTERRUPT__) 168 169 170 /** 171 * @brief Check whether the specified IIR interrupt source is enabled or not. 172 * @param __INSTANCE__ IIR peripheral 173 * @param __INTERRUPT__ specifies the IIR interrupt source to check. 174 * This parameter can be one of the following values: 175 * @arg IIR_IT_FDIE: Filiter Done Interrupt Enable 176 * @return The state of __INTERRUPT__ (SET or RESET). 177 */ 178 #define __LL_IIR_IT_CHECK_SOURCE(__INSTANCE__, __INTERRUPT__) \ 179 ((READ_BIT((__INSTANCE__)->IER, (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) 180 181 /** @brief Check whether the specified IIR status or interrupt flag is set or not. 182 * @param __INSTANCE__ IIR peripheral 183 * @param __FLAG__ specifies the IIR flag to check. 184 * This parameter can be one of the following values: 185 * @arg IIR_FLAG_FDIF: Filiter Done Interrupt Flag 186 * @return The new state of __FLAG__ (SET or RESET). 187 */ 188 #define __LL_IIR_GET_FLAG(__INSTANCE__, __FLAG__) \ 189 ((READ_BIT((__INSTANCE__)->ISR, (__FLAG__)) == (__FLAG__)) ? SET : RESET) 190 191 /** 192 * @brief Clear the specified IIR status or interrupt flag. 193 * @param __INSTANCE__ IIR peripheral 194 * @param __FLAG__ specifies the IIR flag to clear. 195 * This parameter can be one of the following values: 196 * @arg IIR_FLAG_FDIF: Filiter Done Interrupt Flag 197 * @return None 198 */ 199 #define __LL_IIR_CLEAR_FLAG(__INSTANCE__, __FLAG__) WRITE_REG((__INSTANCE__)->ISR, (__FLAG__)) 200 201 /** 202 * @brief Enable the IIR AutoReload feature. 203 * @param __INSTANCE__ IIR peripheral 204 * @return None 205 */ 206 #define __LL_IIR_AUTORELOAD_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CR1, IIR_CR1_AREN) 207 208 /** 209 * @brief Enable the IIR peripheral. 210 * @param __INSTANCE__ IIR peripheral 211 * @return None 212 */ 213 #define __LL_IIR_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CR0, IIR_CR0_IIREN) 214 215 /** 216 * @brief Disable the IIR peripheral. 217 * @param __INSTANCE__ IIR peripheral 218 * @return None 219 */ 220 #define __LL_IIR_DISABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CR0, IIR_CR0_IIREN) 221 222 /** 223 * @brief Start IIR filter 224 * @param __INSTANCE__ IIR peripheral 225 * @return None 226 */ 227 #define __LL_IIR_FILTER_START(__INSTANCE__) SET_BIT((__INSTANCE__)->CR1, IIR_CR1_START) 228 229 230 /** 231 * @brief Reset the IIR internal data buffer. 232 * @param __INSTANCE__ IIR peripheral 233 * @return None 234 */ 235 #define __LL_IIR_FILTER_BUFFER_RESET(__INSTANCE__) SET_BIT((__INSTANCE__)->CR0, IIR_CR0_IBRST) 236 237 /** 238 * @} 239 */ 240 241 242 /* Exported functions --------------------------------------------------------*/ 243 /** @addtogroup IIR_LL_Exported_functions 244 * @{ 245 */ 246 247 /** @addtogroup IIR_LL_Exported_Functions_Group1 248 * @{ 249 */ 250 LL_StatusETypeDef LL_IIR_Init(IIR_TypeDef *Instance, IIR_InitTypeDef *Init); 251 LL_StatusETypeDef LL_IIR_DeInit(IIR_TypeDef *Instance); 252 void LL_IIR_MspInit(IIR_TypeDef *Instance); 253 void LL_IIR_MspDeInit(IIR_TypeDef *Instance); 254 /** 255 * @} 256 */ 257 258 259 /** @addtogroup IIR_LL_Exported_Functions_Group2 260 * @{ 261 */ 262 LL_StatusETypeDef LL_IIR_FilterConfig(IIR_TypeDef *Instance, IIR_ConfigTypeDef *Config); 263 LL_StatusETypeDef LL_IIR_FilterConfig_Preload(IIR_TypeDef *Instance, IIR_ConfigTypeDef *Config); 264 /** 265 * @} 266 */ 267 268 269 /** @addtogroup IIR_LL_Exported_Functions_Group3 270 * @{ 271 */ 272 LL_StatusETypeDef LL_IIR_FilterStart(IIR_TypeDef *Instance, IIR_ATReloadETypeDef AutoReload); 273 LL_StatusETypeDef LL_IIR_FilterStart_IT(IIR_TypeDef *Instance, IIR_ATReloadETypeDef AutoReload); 274 LL_StatusETypeDef LL_IIR_FilterBufferReset(IIR_TypeDef *Instance); 275 int16_t LL_IIR_FilterDataGet(IIR_TypeDef *Instance); 276 /** 277 * @} 278 */ 279 280 281 /** @addtogroup IIR_LL_Exported_Functions_Interrupt 282 * @{ 283 */ 284 void LL_IIR_IRQHandler(IIR_TypeDef *IIRx); 285 void LL_IIR_FilterDoneCallBack(IIR_TypeDef *IIRx); 286 /** 287 * @} 288 */ 289 290 /** 291 * @} 292 */ 293 294 295 /* Private types -------------------------------------------------------------*/ 296 /* Private variables ---------------------------------------------------------*/ 297 /* Private constants ---------------------------------------------------------*/ 298 /* Private macros ------------------------------------------------------------*/ 299 /** @addtogroup IIR_LL_Private_Macros IIR LL Private Macros 300 * @brief IIR LL Private Macros 301 * @{ 302 */ 303 304 /** 305 * @brief Judge is IIR output data scale or not 306 * @param __SCALE__ scale to judge 307 * @retval 0 isn't IIR output data scale 308 * @retval 1 is IIR output data scale 309 */ 310 #define IS_IIR_OUTPUT_DATA_SCALE(__SCALE__) ((__SCALE__) <= 0x1FU) 311 312 /** 313 * @brief Judge is IIR input data scale or not 314 * @param __SCALE__ scale to judge 315 * @retval 0 isn't IIR input data scale 316 * @retval 1 is IIR input data scale 317 */ 318 #define IS_IIR_INPUT_DATA_SCALE(__SCALE__) ((__SCALE__) <= 0x10U) 319 320 /** 321 * @brief Judge is IIR feedback data scale or not 322 * @param __SCALE__ scale to judge 323 * @retval 0 isn't IIR feedback data scale 324 * @retval 1 is IIR feedback data scale 325 */ 326 #define IS_IIR_FEEDBACK_SCALE(__SCALE__) ((__SCALE__) <= 0x1FU) 327 328 /** 329 * @} 330 */ 331 332 333 /* Private functions ---------------------------------------------------------*/ 334 335 336 /** 337 * @} 338 */ 339 340 /** 341 * @} 342 */ 343 344 345 #ifdef __cplusplus 346 } 347 #endif /* __cplusplus */ 348 349 350 #endif /* _TAE32F53XX_LL_IIR_H_ */ 351 352 353 /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/ 354 355