stm32g4xx_hal_fmac.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_hal_fmac.h
  4. * @author MCD Application Team
  5. * @brief Header for stm32g4xx_hal_fmac.c module
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32G4xx_HAL_FMAC_H
  20. #define STM32G4xx_HAL_FMAC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g4xx_hal_def.h"
  26. #if defined(FMAC)
  27. /** @addtogroup STM32G4xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup FMAC
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup FMAC_Exported_Types FMAC Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief FMAC HAL State Structure definition
  39. */
  40. typedef enum
  41. {
  42. HAL_FMAC_STATE_RESET = 0x00U, /*!< FMAC not yet initialized or disabled */
  43. HAL_FMAC_STATE_READY = 0x20U, /*!< FMAC initialized and ready for use */
  44. HAL_FMAC_STATE_BUSY = 0x24U, /*!< FMAC internal process is ongoing */
  45. HAL_FMAC_STATE_BUSY_RD = 0x25U, /*!< FMAC reading configuration is ongoing */
  46. HAL_FMAC_STATE_BUSY_WR = 0x26U, /*!< FMAC writing configuration is ongoing */
  47. HAL_FMAC_STATE_TIMEOUT = 0xA0U, /*!< FMAC in Timeout state */
  48. HAL_FMAC_STATE_ERROR = 0xE0U /*!< FMAC in Error state */
  49. } HAL_FMAC_StateTypeDef;
  50. /**
  51. * @brief FMAC Handle Structure definition
  52. */
  53. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  54. typedef struct __FMAC_HandleTypeDef
  55. #else
  56. typedef struct
  57. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  58. {
  59. FMAC_TypeDef *Instance; /*!< Register base address */
  60. uint32_t FilterParam; /*!< Filter configuration (operation and parameters).
  61. Set to 0 if no valid configuration was applied. */
  62. uint8_t InputAccess; /*!< Access to the input buffer (internal memory area):
  63. DMA, IT, Polling, None.
  64. This parameter can be a value of @ref FMAC_Buffer_Access. */
  65. uint8_t OutputAccess; /*!< Access to the output buffer (internal memory area):
  66. DMA, IT, Polling, None.
  67. This parameter can be a value of @ref FMAC_Buffer_Access. */
  68. int16_t *pInput; /*!< Pointer to FMAC input data buffer */
  69. uint16_t InputCurrentSize; /*!< Number of the input elements already written into FMAC */
  70. uint16_t *pInputSize; /*!< Number of input elements to write (memory allocated to pInput).
  71. In case of early interruption of the filter operation,
  72. its value will be updated. */
  73. int16_t *pOutput; /*!< Pointer to FMAC output data buffer */
  74. uint16_t OutputCurrentSize; /*!< Number of the output elements already read from FMAC */
  75. uint16_t *pOutputSize; /*!< Number of output elements to read (memory allocated to pOutput).
  76. In case of early interruption of the filter operation,
  77. its value will be updated. */
  78. DMA_HandleTypeDef *hdmaIn; /*!< FMAC peripheral input data DMA handle parameters */
  79. DMA_HandleTypeDef *hdmaOut; /*!< FMAC peripheral output data DMA handle parameters */
  80. DMA_HandleTypeDef *hdmaPreload; /*!< FMAC peripheral preloaded data (X1, X2 and Y) DMA handle
  81. parameters */
  82. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  83. void (* ErrorCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC error callback */
  84. void (* HalfGetDataCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC get half data callback */
  85. void (* GetDataCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC get data callback */
  86. void (* HalfOutputDataReadyCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC half output data ready callback */
  87. void (* OutputDataReadyCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC output data ready callback */
  88. void (* FilterConfigCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC filter configuration callback */
  89. void (* FilterPreloadCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC filter preload callback */
  90. void (* MspInitCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC Msp Init callback */
  91. void (* MspDeInitCallback)(struct __FMAC_HandleTypeDef *hfmac); /*!< FMAC Msp DeInit callback */
  92. #endif /* (USE_HAL_FMAC_REGISTER_CALLBACKS) */
  93. HAL_LockTypeDef Lock; /*!< FMAC locking object */
  94. __IO HAL_FMAC_StateTypeDef State; /*!< FMAC state related to global handle management
  95. This parameter can be a value of @ref HAL_FMAC_StateTypeDef */
  96. __IO HAL_FMAC_StateTypeDef RdState; /*!< FMAC state related to read operations (access to Y buffer)
  97. This parameter can be a value of @ref HAL_FMAC_StateTypeDef */
  98. __IO HAL_FMAC_StateTypeDef WrState; /*!< FMAC state related to write operations (access to X1 buffer)
  99. This parameter can be a value of @ref HAL_FMAC_StateTypeDef */
  100. __IO uint32_t ErrorCode; /*!< FMAC peripheral error code
  101. This parameter can be a value of @ref FMAC_Error_Code */
  102. } FMAC_HandleTypeDef;
  103. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  104. /**
  105. * @brief FMAC Callback ID enumeration definition
  106. */
  107. typedef enum
  108. {
  109. HAL_FMAC_ERROR_CB_ID = 0x00U, /*!< FMAC error callback ID */
  110. HAL_FMAC_HALF_GET_DATA_CB_ID = 0x01U, /*!< FMAC get half data callback ID */
  111. HAL_FMAC_GET_DATA_CB_ID = 0x02U, /*!< FMAC get data callback ID */
  112. HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID = 0x03U, /*!< FMAC half output data ready callback ID */
  113. HAL_FMAC_OUTPUT_DATA_READY_CB_ID = 0x04U, /*!< FMAC output data ready callback ID */
  114. HAL_FMAC_FILTER_CONFIG_CB_ID = 0x05U, /*!< FMAC filter configuration callback ID */
  115. HAL_FMAC_FILTER_PRELOAD_CB_ID = 0x06U, /*!< FMAC filter preload callback ID */
  116. HAL_FMAC_MSPINIT_CB_ID = 0x07U, /*!< FMAC MspInit callback ID */
  117. HAL_FMAC_MSPDEINIT_CB_ID = 0x08U, /*!< FMAC MspDeInit callback ID */
  118. } HAL_FMAC_CallbackIDTypeDef;
  119. /**
  120. * @brief HAL FMAC Callback pointer definition
  121. */
  122. typedef void (*pFMAC_CallbackTypeDef)(FMAC_HandleTypeDef *hfmac); /*!< pointer to an FMAC callback function */
  123. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  124. /**
  125. * @brief FMAC Filter Configuration Structure definition
  126. */
  127. typedef struct
  128. {
  129. uint8_t InputBaseAddress; /*!< Base address of the input buffer (X1) within the internal memory
  130. (0x00 to 0xFF). Ignored if InputBufferSize is set to 0
  131. (previous configuration kept).
  132. Note: the buffers can overlap or even coincide exactly. */
  133. uint8_t InputBufferSize; /*!< Number of 16-bit words allocated to the input buffer
  134. (including the optional "headroom").
  135. 0 if a previous configuration should be kept. */
  136. uint32_t InputThreshold; /*!< Input threshold: the buffer full flag will be set if the number
  137. of free spaces in the buffer is lower than this threshold.
  138. This parameter can be a value
  139. of @ref FMAC_Data_Buffer_Threshold. */
  140. uint8_t CoeffBaseAddress; /*!< Base address of the coefficient buffer (X2) within the internal
  141. memory (0x00 to 0xFF). Ignored if CoeffBufferSize is set to 0
  142. (previous configuration kept).
  143. Note: the buffers can overlap or even coincide exactly. */
  144. uint8_t CoeffBufferSize; /*!< Number of 16-bit words allocated to the coefficient buffer.
  145. 0 if a previous configuration should be kept. */
  146. uint8_t OutputBaseAddress; /*!< Base address of the output buffer (Y) within the internal
  147. memory (0x00 to 0xFF). Ignored if OuputBufferSize is set to 0
  148. (previous configuration kept).
  149. Note: the buffers can overlap or even coincide exactly. */
  150. uint8_t OutputBufferSize; /*!< Number of 16-bit words allocated to the output buffer
  151. (including the optional "headroom").
  152. 0 if a previous configuration should be kept. */
  153. uint32_t OutputThreshold; /*!< Output threshold: the buffer empty flag will be set if the number
  154. of unread values in the buffer is lower than this threshold.
  155. This parameter can be a value
  156. of @ref FMAC_Data_Buffer_Threshold. */
  157. int16_t *pCoeffA; /*!< [IIR only] Initialization of the coefficient vector A.
  158. If not needed, it should be set to NULL. */
  159. uint8_t CoeffASize; /*!< Size of the coefficient vector A. */
  160. int16_t *pCoeffB; /*!< Initialization of the coefficient vector B.
  161. If not needed (re-use of a previously loaded buffer),
  162. it should be set to NULL. */
  163. uint8_t CoeffBSize; /*!< Size of the coefficient vector B. */
  164. uint8_t InputAccess; /*!< Access to the input buffer (internal memory area):
  165. DMA, IT, Polling, None.
  166. This parameter can be a value of @ref FMAC_Buffer_Access. */
  167. uint8_t OutputAccess; /*!< Access to the output buffer (internal memory area):
  168. DMA, IT, Polling, None.
  169. This parameter can be a value of @ref FMAC_Buffer_Access. */
  170. uint32_t Clip; /*!< Enable or disable the clipping feature. If the q1.15 range
  171. is exceeded, wrapping is done when the clipping feature is disabled
  172. and saturation is done when the clipping feature is enabled.
  173. This parameter can be a value of @ref FMAC_Clip_State. */
  174. uint32_t Filter; /*!< Filter type.
  175. This parameter can be a value
  176. of @ref FMAC_Functions (filter related values). */
  177. uint8_t P; /*!< Parameter P (vector length, number of filter taps, etc.). */
  178. uint8_t Q; /*!< Parameter Q (vector length, etc.). Ignored if not needed. */
  179. uint8_t R; /*!< Parameter R (gain, etc.). Ignored if not needed. */
  180. } FMAC_FilterConfigTypeDef;
  181. /**
  182. * @}
  183. */
  184. /* Exported constants --------------------------------------------------------*/
  185. /** @defgroup FMAC_Exported_Constants FMAC Exported Constants
  186. * @{
  187. */
  188. /** @defgroup FMAC_Error_Code FMAC Error code
  189. * @{
  190. */
  191. #define HAL_FMAC_ERROR_NONE 0x00000000U /*!< No error */
  192. #define HAL_FMAC_ERROR_SAT 0x00000001U /*!< Saturation error */
  193. #define HAL_FMAC_ERROR_UNFL 0x00000002U /*!< Underflow error */
  194. #define HAL_FMAC_ERROR_OVFL 0x00000004U /*!< Overflow error */
  195. #define HAL_FMAC_ERROR_DMA 0x00000008U /*!< DMA error */
  196. #define HAL_FMAC_ERROR_RESET 0x00000010U /*!< Reset error */
  197. #define HAL_FMAC_ERROR_PARAM 0x00000020U /*!< Parameter error */
  198. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  199. #define HAL_FMAC_ERROR_INVALID_CALLBACK 0x00000040U /*!< Invalid Callback error */
  200. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  201. #define HAL_FMAC_ERROR_TIMEOUT 0x00000080U /*!< Timeout error */
  202. /**
  203. * @}
  204. */
  205. /** @defgroup FMAC_Functions FMAC Functions
  206. * @{
  207. */
  208. #define FMAC_FUNC_LOAD_X1 (FMAC_PARAM_FUNC_0) /*!< Load X1 buffer */
  209. #define FMAC_FUNC_LOAD_X2 (FMAC_PARAM_FUNC_1) /*!< Load X2 buffer */
  210. #define FMAC_FUNC_LOAD_Y (FMAC_PARAM_FUNC_1 | FMAC_PARAM_FUNC_0) /*!< Load Y buffer */
  211. #define FMAC_FUNC_CONVO_FIR (FMAC_PARAM_FUNC_3) /*!< Convolution (FIR filter) */
  212. #define FMAC_FUNC_IIR_DIRECT_FORM_1 (FMAC_PARAM_FUNC_3 | FMAC_PARAM_FUNC_0) /*!< IIR filter (direct form 1) */
  213. /**
  214. * @}
  215. */
  216. /** @defgroup FMAC_Data_Buffer_Threshold FMAC Data Buffer Threshold
  217. * @{
  218. * @note This parameter sets a watermark for buffer full (input) or buffer empty (output).
  219. */
  220. #define FMAC_THRESHOLD_1 0x00000000U /*!< Input: Buffer full flag set if the number of free spaces
  221. in the buffer is less than 1.
  222. Output: Buffer empty flag set if the number
  223. of unread values in the buffer is less than 1. */
  224. #define FMAC_THRESHOLD_2 0x01000000U /*!< Input: Buffer full flag set if the number of free spaces
  225. in the buffer is less than 2.
  226. Output: Buffer empty flag set if the number
  227. of unread values in the buffer is less than 2. */
  228. #define FMAC_THRESHOLD_4 0x02000000U /*!< Input: Buffer full flag set if the number of free spaces
  229. in the buffer is less than 4.
  230. Output: Buffer empty flag set if the number
  231. of unread values in the buffer is less than 4. */
  232. #define FMAC_THRESHOLD_8 0x03000000U /*!< Input: Buffer full flag set if the number of free spaces
  233. in the buffer is less than 8.
  234. Output: Buffer empty flag set if the number
  235. of unread values in the buffer is less than 8. */
  236. #define FMAC_THRESHOLD_NO_VALUE 0xFFFFFFFFU /*!< The configured threshold value shouldn't be changed */
  237. /**
  238. * @}
  239. */
  240. /** @defgroup FMAC_Buffer_Access FMAC Buffer Access
  241. * @{
  242. */
  243. #define FMAC_BUFFER_ACCESS_NONE 0x00U /*!< Buffer handled by an external IP (ADC for instance) */
  244. #define FMAC_BUFFER_ACCESS_DMA 0x01U /*!< Buffer accessed through DMA */
  245. #define FMAC_BUFFER_ACCESS_POLLING 0x02U /*!< Buffer accessed through polling */
  246. #define FMAC_BUFFER_ACCESS_IT 0x03U /*!< Buffer accessed through interruptions */
  247. /**
  248. * @}
  249. */
  250. /** @defgroup FMAC_Clip_State FMAC Clip State
  251. * @{
  252. */
  253. #define FMAC_CLIP_DISABLED 0x00000000U /*!< Clipping disabled */
  254. #define FMAC_CLIP_ENABLED FMAC_CR_CLIPEN /*!< Clipping enabled */
  255. /**
  256. * @}
  257. */
  258. /** @defgroup FMAC_Flags FMAC status flags
  259. * @{
  260. */
  261. #define FMAC_FLAG_YEMPTY FMAC_SR_YEMPTY /*!< Y Buffer Empty Flag */
  262. #define FMAC_FLAG_X1FULL FMAC_SR_X1FULL /*!< X1 Buffer Full Flag */
  263. #define FMAC_FLAG_OVFL FMAC_SR_OVFL /*!< Overflow Error Flag */
  264. #define FMAC_FLAG_UNFL FMAC_SR_UNFL /*!< Underflow Error Flag */
  265. #define FMAC_FLAG_SAT FMAC_SR_SAT /*!< Saturation Error Flag
  266. (this helps in debugging a filter) */
  267. /**
  268. * @}
  269. */
  270. /** @defgroup FMAC_Interrupts_Enable FMAC Interrupts Enable bit
  271. * @{
  272. */
  273. #define FMAC_IT_RIEN FMAC_CR_RIEN /*!< Read Interrupt Enable */
  274. #define FMAC_IT_WIEN FMAC_CR_WIEN /*!< Write Interrupt Enable */
  275. #define FMAC_IT_OVFLIEN FMAC_CR_OVFLIEN /*!< Overflow Error Interrupt Enable */
  276. #define FMAC_IT_UNFLIEN FMAC_CR_UNFLIEN /*!< Underflow Error Interrupt Enable */
  277. #define FMAC_IT_SATIEN FMAC_CR_SATIEN /*!< Saturation Error Interrupt Enable
  278. (this helps in debugging a filter) */
  279. /**
  280. * @}
  281. */
  282. /**
  283. * @}
  284. */
  285. /* Exported variables --------------------------------------------------------*/
  286. /** @defgroup FMAC_Exported_variables FMAC Exported variables
  287. * @{
  288. */
  289. /**
  290. * @}
  291. */
  292. /* Exported macros -----------------------------------------------------------*/
  293. /** @defgroup FMAC_Exported_Macros FMAC Exported Macros
  294. * @{
  295. */
  296. /**
  297. * @brief Reset FMAC handle state.
  298. * @param __HANDLE__ FMAC handle.
  299. * @retval None
  300. */
  301. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  302. #define __HAL_FMAC_RESET_HANDLE_STATE(__HANDLE__) do{ \
  303. (__HANDLE__)->State = HAL_FMAC_STATE_RESET; \
  304. (__HANDLE__)->MspInitCallback = NULL; \
  305. (__HANDLE__)->MspDeInitCallback = NULL; \
  306. } while(0U)
  307. #else
  308. #define __HAL_FMAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_FMAC_STATE_RESET)
  309. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  310. /**
  311. * @brief Enable the specified FMAC interrupt
  312. * @param __HANDLE__ FMAC handle.
  313. * @param __INTERRUPT__ FMAC Interrupt.
  314. * This parameter can be any combination of the following values:
  315. * @arg @ref FMAC_IT_RIEN Read interrupt enable
  316. * @arg @ref FMAC_IT_WIEN Write interrupt enable
  317. * @arg @ref FMAC_IT_OVFLIEN Overflow error interrupt enable
  318. * @arg @ref FMAC_IT_UNFLIEN Underflow error interrupt enable
  319. * @arg @ref FMAC_IT_SATIEN Saturation error interrupt enable (this helps in debugging a filter)
  320. * @retval None
  321. */
  322. #define __HAL_FMAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) \
  323. (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
  324. /**
  325. * @brief Disable the FMAC interrupt
  326. * @param __HANDLE__ FMAC handle.
  327. * @param __INTERRUPT__ FMAC Interrupt.
  328. * This parameter can be any combination of the following values:
  329. * @arg @ref FMAC_IT_RIEN Read interrupt enable
  330. * @arg @ref FMAC_IT_WIEN Write interrupt enable
  331. * @arg @ref FMAC_IT_OVFLIEN Overflow error interrupt enable
  332. * @arg @ref FMAC_IT_UNFLIEN Underflow error interrupt enable
  333. * @arg @ref FMAC_IT_SATIEN Saturation error interrupt enable (this helps in debugging a filter)
  334. * @retval None
  335. */
  336. #define __HAL_FMAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) \
  337. (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
  338. /**
  339. * @brief Check whether the specified FMAC interrupt occurred or not.
  340. * @param __HANDLE__ FMAC handle.
  341. * @param __INTERRUPT__ FMAC interrupt to check.
  342. * This parameter can be any combination of the following values:
  343. * @arg @ref FMAC_FLAG_YEMPTY Y Buffer Empty Flag
  344. * @arg @ref FMAC_FLAG_X1FULL X1 Buffer Full Flag
  345. * @arg @ref FMAC_FLAG_OVFL Overflow Error Flag
  346. * @arg @ref FMAC_FLAG_UNFL Underflow Error Flag
  347. * @arg @ref FMAC_FLAG_SAT Saturation Error Flag
  348. * @retval SET (interrupt occurred) or RESET (interrupt did not occurred)
  349. */
  350. #define __HAL_FMAC_GET_IT(__HANDLE__, __INTERRUPT__) \
  351. (((__HANDLE__)->Instance->SR) &= ~(__INTERRUPT__))
  352. /**
  353. * @brief Clear specified FMAC interrupt status. Dummy macro as the
  354. interrupt status flags are read-only.
  355. * @param __HANDLE__ FMAC handle.
  356. * @param __INTERRUPT__ FMAC interrupt to clear.
  357. * @retval None
  358. */
  359. #define __HAL_FMAC_CLEAR_IT(__HANDLE__, __INTERRUPT__) /* Dummy macro */
  360. /**
  361. * @brief Check whether the specified FMAC status flag is set or not.
  362. * @param __HANDLE__ FMAC handle.
  363. * @param __FLAG__ FMAC flag to check.
  364. * This parameter can be any combination of the following values:
  365. * @arg @ref FMAC_FLAG_YEMPTY Y Buffer Empty Flag
  366. * @arg @ref FMAC_FLAG_X1FULL X1 Buffer Full Flag
  367. * @arg @ref FMAC_FLAG_OVFL Overflow Error Flag
  368. * @arg @ref FMAC_FLAG_UNFL Underflow Error Flag
  369. * @arg @ref FMAC_FLAG_SAT Saturation error Flag
  370. * @retval SET (flag is set) or RESET (flag is reset)
  371. */
  372. #define __HAL_FMAC_GET_FLAG(__HANDLE__, __FLAG__) \
  373. ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  374. /**
  375. * @brief Clear specified FMAC status flag. Dummy macro as no
  376. flag can be cleared.
  377. * @param __HANDLE__ FMAC handle.
  378. * @param __FLAG__ FMAC flag to clear.
  379. * @retval None
  380. */
  381. #define __HAL_FMAC_CLEAR_FLAG(__HANDLE__, __FLAG__) /* Dummy macro */
  382. /**
  383. * @brief Check whether the specified FMAC interrupt is enabled or not.
  384. * @param __HANDLE__ FMAC handle.
  385. * @param __INTERRUPT__ FMAC interrupt to check.
  386. * This parameter can be one of the following values:
  387. * @arg @ref FMAC_IT_RIEN Read interrupt enable
  388. * @arg @ref FMAC_IT_WIEN Write interrupt enable
  389. * @arg @ref FMAC_IT_OVFLIEN Overflow error interrupt enable
  390. * @arg @ref FMAC_IT_UNFLIEN Underflow error interrupt enable
  391. * @arg @ref FMAC_IT_SATIEN Saturation error interrupt enable (this helps in debugging a filter)
  392. * @retval FlagStatus
  393. */
  394. #define __HAL_FMAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
  395. (((__HANDLE__)->Instance->CR) & (__INTERRUPT__))
  396. /**
  397. * @}
  398. */
  399. /* Private defines -----------------------------------------------------------*/
  400. /** @addtogroup FMAC_Private_Constants
  401. * @{
  402. */
  403. #define FMAC_PARAM_P_MAX_IIR 64U /*!< Maximum value of P parameter with IIR */
  404. #define FMAC_PARAM_P_MAX_FIR 127U /*!< Maximum value of P parameter with FIR */
  405. #define FMAC_PARAM_P_MIN 2U /*!< Minimum value of P parameter */
  406. #define FMAC_PARAM_Q_MAX 63U /*!< Maximum value of Q parameter */
  407. #define FMAC_PARAM_Q_MIN 1U /*!< Minimum value of Q parameter */
  408. #define FMAC_PARAM_R_MAX 7U /*!< Maximum value of R parameter */
  409. /**
  410. * @}
  411. */
  412. /* Private Macros-------------------------------------------------------------*/
  413. /** @addtogroup FMAC_Private_Macros FMAC Private Macros
  414. * @{
  415. */
  416. /**
  417. * @brief Verify the FMAC function.
  418. * @param __FUNCTION__ ID of the function.
  419. * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
  420. */
  421. #define IS_FMAC_FUNCTION(__FUNCTION__) (((__FUNCTION__) == FMAC_FUNC_LOAD_X1) || \
  422. ((__FUNCTION__) == FMAC_FUNC_LOAD_X2) || \
  423. ((__FUNCTION__) == FMAC_FUNC_LOAD_Y) || \
  424. ((__FUNCTION__) == FMAC_FUNC_CONVO_FIR) || \
  425. ((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1))
  426. /**
  427. * @brief Verify the FMAC load function used for input data, output data or coefficients.
  428. * @param __FUNCTION__ ID of the load function.
  429. * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
  430. */
  431. #define IS_FMAC_LOAD_FUNCTION(__FUNCTION__) (((__FUNCTION__) == FMAC_FUNC_LOAD_X1) || \
  432. ((__FUNCTION__) == FMAC_FUNC_LOAD_X2) || \
  433. ((__FUNCTION__) == FMAC_FUNC_LOAD_Y))
  434. /**
  435. * @brief Verify the FMAC load function used with N values as input or output data.
  436. * @param __FUNCTION__ ID of the load function.
  437. * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
  438. */
  439. #define IS_FMAC_N_LOAD_FUNCTION(__FUNCTION__) (((__FUNCTION__) == FMAC_FUNC_LOAD_X1) || \
  440. ((__FUNCTION__) == FMAC_FUNC_LOAD_Y))
  441. /**
  442. * @brief Verify the FMAC load function used with N + M values as coefficients.
  443. * @param __FUNCTION__ ID of the load function.
  444. * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
  445. */
  446. #define IS_FMAC_N_M_LOAD_FUNCTION(__FUNCTION__) ((__FUNCTION__) == FMAC_FUNC_LOAD_X2)
  447. /**
  448. * @brief Verify the FMAC filter function.
  449. * @param __FUNCTION__ ID of the filter function.
  450. * @retval SET (__FUNCTION__ is a valid value) or RESET (__FUNCTION__ is invalid)
  451. */
  452. #define IS_FMAC_FILTER_FUNCTION(__FUNCTION__) (((__FUNCTION__) == FMAC_FUNC_CONVO_FIR) || \
  453. ((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1))
  454. /**
  455. * @brief Verify the FMAC threshold.
  456. * @param __THRESHOLD__ Value of the threshold.
  457. * @retval SET (__THRESHOLD__ is a valid value) or RESET (__THRESHOLD__ is invalid)
  458. */
  459. #define IS_FMAC_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == FMAC_THRESHOLD_1) || \
  460. ((__THRESHOLD__) == FMAC_THRESHOLD_2) || \
  461. ((__THRESHOLD__) == FMAC_THRESHOLD_4) || \
  462. ((__THRESHOLD__) == FMAC_THRESHOLD_NO_VALUE) || \
  463. ((__THRESHOLD__) == FMAC_THRESHOLD_8))
  464. /**
  465. * @brief Verify the FMAC filter parameter P.
  466. * @param __P__ Value of the filter parameter P.
  467. * @param __FUNCTION__ ID of the filter function.
  468. * @retval SET (__P__ is a valid value) or RESET (__P__ is invalid)
  469. */
  470. #define IS_FMAC_PARAM_P(__FUNCTION__, __P__) ((((__FUNCTION__) == FMAC_FUNC_CONVO_FIR) && \
  471. (((__P__) >= FMAC_PARAM_P_MIN) && \
  472. ((__P__) <= FMAC_PARAM_P_MAX_FIR))) || \
  473. (((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1) && \
  474. (((__P__) >= FMAC_PARAM_P_MIN) && \
  475. ((__P__) <= FMAC_PARAM_P_MAX_IIR))))
  476. /**
  477. * @brief Verify the FMAC filter parameter Q.
  478. * @param __Q__ Value of the filter parameter Q.
  479. * @param __FUNCTION__ ID of the filter function.
  480. * @retval SET (__Q__ is a valid value) or RESET (__Q__ is invalid)
  481. */
  482. #define IS_FMAC_PARAM_Q(__FUNCTION__, __Q__) (((__FUNCTION__) == FMAC_FUNC_CONVO_FIR) || \
  483. (((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1) && \
  484. (((__Q__) >= FMAC_PARAM_Q_MIN) && ((__Q__) <= FMAC_PARAM_Q_MAX))))
  485. /**
  486. * @brief Verify the FMAC filter parameter R.
  487. * @param __R__ Value of the filter parameter.
  488. * @param __FUNCTION__ ID of the filter function.
  489. * @retval SET (__R__ is a valid value) or RESET (__R__ is invalid)
  490. */
  491. #define IS_FMAC_PARAM_R(__FUNCTION__, __R__) ( (((__FUNCTION__) == FMAC_FUNC_CONVO_FIR) || \
  492. ((__FUNCTION__) == FMAC_FUNC_IIR_DIRECT_FORM_1)) && \
  493. ((__R__) <= FMAC_PARAM_R_MAX))
  494. /**
  495. * @brief Verify the FMAC buffer access.
  496. * @param __BUFFER_ACCESS__ Type of access.
  497. * @retval SET (__BUFFER_ACCESS__ is a valid value) or RESET (__BUFFER_ACCESS__ is invalid)
  498. */
  499. #define IS_FMAC_BUFFER_ACCESS(__BUFFER_ACCESS__) (((__BUFFER_ACCESS__) == FMAC_BUFFER_ACCESS_NONE) || \
  500. ((__BUFFER_ACCESS__) == FMAC_BUFFER_ACCESS_DMA) || \
  501. ((__BUFFER_ACCESS__) == FMAC_BUFFER_ACCESS_POLLING) || \
  502. ((__BUFFER_ACCESS__) == FMAC_BUFFER_ACCESS_IT))
  503. /**
  504. * @brief Verify the FMAC clip feature.
  505. * @param __CLIP_STATE__ Clip state.
  506. * @retval SET (__CLIP_STATE__ is a valid value) or RESET (__CLIP_STATE__ is invalid)
  507. */
  508. #define IS_FMAC_CLIP_STATE(__CLIP_STATE__) (((__CLIP_STATE__) == FMAC_CLIP_DISABLED) || \
  509. ((__CLIP_STATE__) == FMAC_CLIP_ENABLED))
  510. /**
  511. * @brief Check whether the threshold is applicable.
  512. * @param __SIZE__ Size of the matching buffer.
  513. * @param __WM__ Watermark value.
  514. * @param __ACCESS__ Access to the buffer (polling, it, dma, none).
  515. * @retval THRESHOLD
  516. */
  517. #define IS_FMAC_THRESHOLD_APPLICABLE(__SIZE__, __WM__, __ACCESS__) \
  518. (( (__SIZE__) >= (((__WM__) == FMAC_THRESHOLD_1)? 1U: \
  519. ((__WM__) == FMAC_THRESHOLD_2)? 2U: \
  520. ((__WM__) == FMAC_THRESHOLD_4)? 4U:8U))&& \
  521. ((((__ACCESS__) == FMAC_BUFFER_ACCESS_DMA)&& \
  522. ((__WM__) == FMAC_THRESHOLD_1))|| \
  523. ((__ACCESS__ )!= FMAC_BUFFER_ACCESS_DMA)))
  524. /**
  525. * @}
  526. */
  527. /* Exported functions ------------------------------------------------------- */
  528. /** @addtogroup FMAC_Exported_Functions
  529. * @{
  530. */
  531. /** @addtogroup FMAC_Exported_Functions_Group1
  532. * @{
  533. */
  534. /* Initialization and de-initialization functions ****************************/
  535. HAL_StatusTypeDef HAL_FMAC_Init(FMAC_HandleTypeDef *hfmac);
  536. HAL_StatusTypeDef HAL_FMAC_DeInit(FMAC_HandleTypeDef *hfmac);
  537. void HAL_FMAC_MspInit(FMAC_HandleTypeDef *hfmac);
  538. void HAL_FMAC_MspDeInit(FMAC_HandleTypeDef *hfmac);
  539. #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
  540. /* Callbacks Register/UnRegister functions ***********************************/
  541. HAL_StatusTypeDef HAL_FMAC_RegisterCallback(FMAC_HandleTypeDef *hfmac, HAL_FMAC_CallbackIDTypeDef CallbackID,
  542. pFMAC_CallbackTypeDef pCallback);
  543. HAL_StatusTypeDef HAL_FMAC_UnRegisterCallback(FMAC_HandleTypeDef *hfmac, HAL_FMAC_CallbackIDTypeDef CallbackID);
  544. #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
  545. /**
  546. * @}
  547. */
  548. /** @addtogroup FMAC_Exported_Functions_Group2
  549. * @{
  550. */
  551. /* Peripheral Control functions ***********************************************/
  552. HAL_StatusTypeDef HAL_FMAC_FilterConfig(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *pConfig);
  553. HAL_StatusTypeDef HAL_FMAC_FilterConfig_DMA(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *pConfig);
  554. HAL_StatusTypeDef HAL_FMAC_FilterPreload(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint8_t InputSize,
  555. int16_t *pOutput, uint8_t OutputSize);
  556. HAL_StatusTypeDef HAL_FMAC_FilterPreload_DMA(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint8_t InputSize,
  557. int16_t *pOutput, uint8_t OutputSize);
  558. HAL_StatusTypeDef HAL_FMAC_FilterStart(FMAC_HandleTypeDef *hfmac, int16_t *pOutput, uint16_t *pOutputSize);
  559. HAL_StatusTypeDef HAL_FMAC_AppendFilterData(FMAC_HandleTypeDef *hfmac, int16_t *pInput, uint16_t *pInputSize);
  560. HAL_StatusTypeDef HAL_FMAC_ConfigFilterOutputBuffer(FMAC_HandleTypeDef *hfmac, int16_t *pOutput, uint16_t *pOutputSize);
  561. HAL_StatusTypeDef HAL_FMAC_PollFilterData(FMAC_HandleTypeDef *hfmac, uint32_t Timeout);
  562. HAL_StatusTypeDef HAL_FMAC_FilterStop(FMAC_HandleTypeDef *hfmac);
  563. /**
  564. * @}
  565. */
  566. /** @addtogroup FMAC_Exported_Functions_Group3
  567. * @{
  568. */
  569. /* Callback functions *********************************************************/
  570. void HAL_FMAC_ErrorCallback(FMAC_HandleTypeDef *hfmac);
  571. void HAL_FMAC_HalfGetDataCallback(FMAC_HandleTypeDef *hfmac);
  572. void HAL_FMAC_GetDataCallback(FMAC_HandleTypeDef *hfmac);
  573. void HAL_FMAC_HalfOutputDataReadyCallback(FMAC_HandleTypeDef *hfmac);
  574. void HAL_FMAC_OutputDataReadyCallback(FMAC_HandleTypeDef *hfmac);
  575. void HAL_FMAC_FilterConfigCallback(FMAC_HandleTypeDef *hfmac);
  576. void HAL_FMAC_FilterPreloadCallback(FMAC_HandleTypeDef *hfmac);
  577. /**
  578. * @}
  579. */
  580. /** @addtogroup FMAC_Exported_Functions_Group4
  581. * @{
  582. */
  583. /* IRQ handler management *****************************************************/
  584. void HAL_FMAC_IRQHandler(FMAC_HandleTypeDef *hfmac);
  585. /**
  586. * @}
  587. */
  588. /** @addtogroup FMAC_Exported_Functions_Group5
  589. * @{
  590. */
  591. /* Peripheral State functions *************************************************/
  592. HAL_FMAC_StateTypeDef HAL_FMAC_GetState(const FMAC_HandleTypeDef *hfmac);
  593. uint32_t HAL_FMAC_GetError(const FMAC_HandleTypeDef *hfmac);
  594. /**
  595. * @}
  596. */
  597. /**
  598. * @}
  599. */
  600. /**
  601. * @}
  602. */
  603. /**
  604. * @}
  605. */
  606. #endif /* FMAC */
  607. #ifdef __cplusplus
  608. }
  609. #endif
  610. #endif /* STM32G4xx_HAL_FMAC_H */