2 ******************************************************************************
3 * @file stm32h7xx_hal_fmac.c
4 * @author MCD Application Team
5 * @brief FMAC HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the FMAC peripheral:
8 * + Initialization and de-initialization functions
9 * + Peripheral Control functions
10 * + Callback functions
11 * + IRQ handler management
12 * + Peripheral State functions
15 ================================================================================
16 ##### How to use this driver #####
17 ================================================================================
19 The FMAC HAL driver can be used as follows:
21 (#) Initialize the FMAC low level resources by implementing the HAL_FMAC_MspInit():
22 (++) Enable the FMAC interface clock using __HAL_RCC_FMAC_CLK_ENABLE().
23 (++) In case of using interrupts (e.g. access configured as FMAC_BUFFER_ACCESS_IT):
24 (+++) Configure the FMAC interrupt priority using HAL_NVIC_SetPriority().
25 (+++) Enable the FMAC IRQ handler using HAL_NVIC_EnableIRQ().
26 (+++) In FMAC IRQ handler, call HAL_FMAC_IRQHandler().
27 (++) In case of using DMA to control data transfer (e.g. access configured
28 as FMAC_BUFFER_ACCESS_DMA):
29 (+++) Enable the DMA1 interface clock using __HAL_RCC_DMA1_CLK_ENABLE().
30 (+++) Enable the DMAMUX1 interface clock using __HAL_RCC_DMAMUX1_CLK_ENABLE().
31 (+++) If the initialisation of the internal buffers (coefficients, input,
32 output) is done via DMA, configure and enable one DMA channel for
33 managing data transfer from memory to memory (preload channel).
34 (+++) If the input buffer is accessed via DMA, configure and enable one
35 DMA channel for managing data transfer from memory to peripheral
37 (+++) If the output buffer is accessed via DMA, configure and enable
38 one DMA channel for managing data transfer from peripheral to
39 memory (output channel).
40 (+++) Associate the initialized DMA handle(s) to the FMAC DMA handle(s)
41 using __HAL_LINKDMA().
42 (+++) Configure the priority and enable the NVIC for the transfer complete
43 interrupt on the enabled DMA channel(s) using HAL_NVIC_SetPriority()
44 and HAL_NVIC_EnableIRQ().
46 (#) Initialize the FMAC HAL using HAL_FMAC_Init(). This function
47 resorts to HAL_FMAC_MspInit() for low-level initialization.
49 (#) Configure the FMAC processing (filter) using HAL_FMAC_FilterConfig()
50 or HAL_FMAC_FilterConfig_DMA().
52 (++) Defines the memory area within the FMAC internal memory
53 (input, coefficients, output) and the associated threshold (input, output).
54 (++) Configures the filter and its parameters:
55 (+++) Finite Impulse Response (FIR) filter (also known as convolution).
56 (+++) Infinite Impulse Response (IIR) filter (direct form 1).
57 (++) Choose the way to access to the input and output buffers: none, polling,
58 DMA, IT. "none" means the input and/or output data will be handled by
59 another IP (ADC, DAC, etc.).
60 (++) Enable the error interruptions in the input access and/or the output
61 access is done through IT/DMA. If an error occurs, the interruption
62 will be triggered in loop. In order to recover, the user will have
63 to reset the IP with the sequence HAL_FMAC_DeInit / HAL_FMAC_Init.
64 Optionally, he can also disable the interrupt using __HAL_FMAC_DISABLE_IT;
65 the error status will be kept, but no more interrupt will be triggered.
66 (++) Write the provided coefficients into the internal memory using polling
67 mode (HAL_FMAC_FilterConfig()) or DMA (HAL_FMAC_FilterConfig_DMA()).
68 In the DMA case, HAL_FMAC_FilterConfigCallback() is called when
71 (#) Optionally, the user can enable the error interruption related to
72 saturation by calling __HAL_FMAC_ENABLE_IT. This helps in debugging the
73 filter. If a saturation occurs, the interruption will be triggered in loop.
74 In order to recover, the user will have to:
75 (++) Disable the interruption by calling __HAL_FMAC_DISABLE_IT if
76 he wishes to continue all the same.
77 (++) Reset the IP with the sequence HAL_FMAC_DeInit / HAL_FMAC_Init.
79 (#) Optionally, preload input (FIR, IIR) and output (IIR) data using
80 HAL_FMAC_FilterPreload() or HAL_FMAC_FilterPreload_DMA().
81 In the DMA case, HAL_FMAC_FilterPreloadCallback() is called when
83 This step is optional as the filter can be started without preloaded
86 (#) Start the FMAC processing (filter) using HAL_FMAC_FilterStart().
87 This function also configures the output buffer that will be filled from
88 the circular internal output buffer. The function returns immediately
89 without updating the provided buffer. The IP processing will be active until
90 HAL_FMAC_FilterStop() is called.
92 (#) If the input internal buffer is accessed via DMA, HAL_FMAC_HalfGetDataCallback()
93 will be called to indicate that half of the input buffer has been handled.
95 (#) If the input internal buffer is accessed via DMA or interrupt, HAL_FMAC_GetDataCallback()
96 will be called to require new input data. It will be provided through
97 HAL_FMAC_AppendFilterData() if the DMA isn't in circular mode.
99 (#) If the output internal buffer is accessed via DMA, HAL_FMAC_HalfOutputDataReadyCallback()
100 will be called to indicate that half of the output buffer has been handled.
102 (#) If the output internal buffer is accessed via DMA or interrupt,
103 HAL_FMAC_OutputDataReadyCallback() will be called to require a new output
104 buffer. It will be provided through HAL_FMAC_ConfigFilterOutputBuffer()
105 if the DMA isn't in circular mode.
107 (#) In all modes except none, provide new input data to be processed via HAL_FMAC_AppendFilterData().
108 This function should only be called once the previous input data has been handled
109 (the preloaded input data isn't concerned).
111 (#) In all modes except none, provide a new output buffer to be filled via
112 HAL_FMAC_ConfigFilterOutputBuffer(). This function should only be called once the previous
113 user's output buffer has been filled.
115 (#) In polling mode, handle the input and output data using HAL_FMAC_PollFilterData().
117 (++) Write the user's input data (provided via HAL_FMAC_AppendFilterData())
118 into the FMAC input memory area.
119 (++) Read the FMAC output memory area and write it into the user's output buffer.
120 It will return either when:
121 (++) the user's output buffer is filled.
122 (++) the user's input buffer has been handled.
123 The unused data (unread input data or free output data) will not be saved.
124 The user will have to use the updated input and output sizes to keep track
127 (#) Stop the FMAC processing (filter) using HAL_FMAC_FilterStop().
129 (#) Call HAL_FMAC_DeInit() to de-initialize the FMAC peripheral. This function
130 resorts to HAL_FMAC_MspDeInit() for low-level de-initialization.
132 ##### Callback registration #####
133 ==================================
136 The compilation define USE_HAL_FMAC_REGISTER_CALLBACKS when set to 1
137 allows the user to configure dynamically the driver callbacks.
140 Use Function @ref HAL_FMAC_RegisterCallback() to register a user callback.
141 Function @ref HAL_FMAC_RegisterCallback() allows to register following callbacks:
142 (+) ErrorCallback : Error Callback.
143 (+) HalfGetDataCallback : Get Half Data Callback.
144 (+) GetDataCallback : Get Data Callback.
145 (+) HalfOutputDataReadyCallback : Half Output Data Ready Callback.
146 (+) OutputDataReadyCallback : Output Data Ready Callback.
147 (+) FilterConfigCallback : Filter Configuration Callback.
148 (+) FilterPreloadCallback : Filter Preload Callback.
149 (+) MspInitCallback : FMAC MspInit.
150 (+) MspDeInitCallback : FMAC MspDeInit.
151 This function takes as parameters the HAL peripheral handle, the Callback ID
152 and a pointer to the user callback function.
155 Use function @ref HAL_FMAC_UnRegisterCallback() to reset a callback to the default
156 weak (surcharged) function.
157 @ref HAL_FMAC_UnRegisterCallback() takes as parameters the HAL peripheral handle
159 This function allows to reset following callbacks:
160 (+) ErrorCallback : Error Callback.
161 (+) HalfGetDataCallback : Get Half Data Callback.
162 (+) GetDataCallback : Get Data Callback.
163 (+) HalfOutputDataReadyCallback : Half Output Data Ready Callback.
164 (+) OutputDataReadyCallback : Output Data Ready Callback.
165 (+) FilterConfigCallback : Filter Configuration Callback.
166 (+) FilterPreloadCallback : Filter Preload Callback.
167 (+) MspInitCallback : FMAC MspInit.
168 (+) MspDeInitCallback : FMAC MspDeInit.
171 By default, after the @ref HAL_FMAC_Init() and when the state is HAL_FMAC_STATE_RESET
172 all callbacks are set to the corresponding weak (surcharged) functions:
173 examples @ref HAL_FMAC_TxCpltCallback(), @ref HAL_FMAC_RxHalfCpltCallback().
174 Exception done for MspInit and MspDeInit functions that are respectively
175 reset to the legacy weak (surcharged) functions in the @ref HAL_FMAC_Init()
176 and @ref HAL_FMAC_DeInit() only when these callbacks are null (not registered beforehand).
177 If not, MspInit or MspDeInit are not null, the @ref HAL_FMAC_Init() and @ref HAL_FMAC_DeInit()
178 keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
181 Callbacks can be registered/unregistered in HAL_FMAC_STATE_READY state only.
182 Exception done MspInit/MspDeInit that can be registered/unregistered
183 in HAL_FMAC_STATE_READY or HAL_FMAC_STATE_RESET state, thus registered (user)
184 MspInit/DeInit callbacks can be used during the Init/DeInit.
185 In that case first register the MspInit/MspDeInit user callbacks
186 using @ref HAL_FMAC_RegisterCallback() before calling @ref HAL_FMAC_DeInit()
187 or @ref HAL_FMAC_Init() function.
190 When the compilation define USE_HAL_FMAC_REGISTER_CALLBACKS is set to 0 or
191 not defined, the callback registration feature is not available
192 and weak (surcharged) callbacks are used.
197 ******************************************************************************
200 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
201 * All rights reserved.</center></h2>
203 * This software component is licensed by ST under BSD 3-Clause license,
204 * the "License"; You may not use this file except in compliance with the
205 * License. You may obtain a copy of the License at:
206 * opensource.org/licenses/BSD-3-Clause
208 ******************************************************************************
211 /* Includes ------------------------------------------------------------------*/
212 #include "stm32h7xx_hal.h"
215 #ifdef HAL_FMAC_MODULE_ENABLED
217 /** @addtogroup STM32H7xx_HAL_Driver
221 /** @defgroup FMAC FMAC
222 * @brief FMAC HAL driver modules
226 /* External variables --------------------------------------------------------*/
227 /* Private typedef -----------------------------------------------------------*/
228 /* Private defines -----------------------------------------------------------*/
229 /** @defgroup FMAC_Private_Constants FMAC Private Constants
233 #define MAX_FILTER_DATA_SIZE_TO_HANDLE ((uint16_t) 0xFFU)
234 #define PRELOAD_ACCESS_DMA 0x00U
235 #define PRELOAD_ACCESS_POLLING 0x01U
236 #define POLLING_DISABLED 0U
237 #define POLLING_ENABLED 1U
238 #define POLLING_NOT_STOPPED 0U
239 #define POLLING_STOPPED 1U
245 /* Private macros ------------------------------------------------------------*/
246 /** @defgroup FMAC_Private_Macros FMAC Private Macros
251 * @brief Get the X1 memory area size.
252 * @param __HANDLE__ FMAC handle.
253 * @retval X1_BUF_SIZE
255 #define FMAC_GET_X1_SIZE(__HANDLE__) \
256 ((((__HANDLE__)->Instance->X1BUFCFG) & (FMAC_X1BUFCFG_X1_BUF_SIZE)) >> (FMAC_X1BUFCFG_X1_BUF_SIZE_Pos))
259 * @brief Get the X1 watermark.
260 * @param __HANDLE__ FMAC handle.
263 #define FMAC_GET_X1_FULL_WM(__HANDLE__) \
264 (((__HANDLE__)->Instance->X1BUFCFG) & (FMAC_X1BUFCFG_FULL_WM))
267 * @brief Get the X2 memory area size.
268 * @param __HANDLE__ FMAC handle.
269 * @retval X2_BUF_SIZE
271 #define FMAC_GET_X2_SIZE(__HANDLE__) \
272 ((((__HANDLE__)->Instance->X2BUFCFG) & (FMAC_X2BUFCFG_X2_BUF_SIZE)) >> (FMAC_X2BUFCFG_X2_BUF_SIZE_Pos))
275 * @brief Get the Y memory area size.
276 * @param __HANDLE__ FMAC handle.
279 #define FMAC_GET_Y_SIZE(__HANDLE__) \
280 ((((__HANDLE__)->Instance->YBUFCFG) & (FMAC_YBUFCFG_Y_BUF_SIZE)) >> (FMAC_YBUFCFG_Y_BUF_SIZE_Pos))
283 * @brief Get the Y watermark.
284 * @param __HANDLE__ FMAC handle.
287 #define FMAC_GET_Y_EMPTY_WM(__HANDLE__) \
288 (((__HANDLE__)->Instance->YBUFCFG) & (FMAC_YBUFCFG_EMPTY_WM))
291 * @brief Get the start bit state.
292 * @param __HANDLE__ FMAC handle.
295 #define FMAC_GET_START_BIT(__HANDLE__) \
296 ((((__HANDLE__)->Instance->PARAM) & (FMAC_PARAM_START)) >> (FMAC_PARAM_START_Pos))
299 * @brief Get the threshold matching the watermak.
300 * @param __WM__ Watermark value.
303 #define FMAC_GET_THRESHOLD_FROM_WM(__WM__) ((__WM__ == FMAC_THRESHOLD_1)? 1U: \
304 (__WM__ == FMAC_THRESHOLD_2)? 2U: \
305 (__WM__ == FMAC_THRESHOLD_4)? 4U:8U)
308 * @brief Check whether the threshold is applicable.
309 * @param __SIZE__ Size of the matching buffer.
310 * @param __WM__ Watermark value.
311 * @param __ACCESS__ Access to the buffer (polling, it, dma, none).
314 #define IS_FMAC_THRESHOLD_APPLICABLE(__SIZE__, __WM__, __ACCESS__) (( (__SIZE__) >= (((__WM__) == FMAC_THRESHOLD_1)? 1U: \
315 ((__WM__) == FMAC_THRESHOLD_2)? 2U: \
316 ((__WM__) == FMAC_THRESHOLD_4)? 4U:8U))&& \
317 ((((__ACCESS__) == FMAC_BUFFER_ACCESS_DMA)&&((__WM__) == FMAC_THRESHOLD_1))|| \
318 ((__ACCESS__ )!= FMAC_BUFFER_ACCESS_DMA)))
324 /* Private variables ---------------------------------------------------------*/
326 /* Private function prototypes -----------------------------------------------*/
328 static HAL_StatusTypeDef
FMAC_Reset(FMAC_HandleTypeDef
*hfmac
);
329 static void FMAC_ResetDataPointers(FMAC_HandleTypeDef
*hfmac
);
330 static void FMAC_ResetOutputStateAndDataPointers(FMAC_HandleTypeDef
*hfmac
);
331 static void FMAC_ResetInputStateAndDataPointers(FMAC_HandleTypeDef
*hfmac
);
332 static HAL_StatusTypeDef
FMAC_FilterConfig(FMAC_HandleTypeDef
*hfmac
, FMAC_FilterConfigTypeDef
*sConfig
,
333 uint8_t PreloadAccess
);
334 static HAL_StatusTypeDef
FMAC_FilterPreload(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint8_t InputSize
,
335 int16_t *pOutput
, uint8_t OutputSize
, uint8_t PreloadAccess
);
336 static void FMAC_WritePreloadDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, int16_t **ppData
, uint8_t Size
);
337 static HAL_StatusTypeDef
FMAC_WaitOnStartUntilTimeout(FMAC_HandleTypeDef
*hfmac
, uint32_t Tickstart
, uint32_t Timeout
);
338 static HAL_StatusTypeDef
FMAC_AppendFilterDataUpdateState(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
,
339 uint16_t *pInputSize
);
340 static HAL_StatusTypeDef
FMAC_ConfigFilterOutputBufferUpdateState(FMAC_HandleTypeDef
*hfmac
, int16_t *pOutput
,
341 uint16_t *pOutputSize
);
342 static void FMAC_WriteDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, uint16_t MaxSizeToWrite
);
343 static void FMAC_ReadDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, uint16_t MaxSizeToRead
);
344 static void FMAC_DMAHalfGetData(DMA_HandleTypeDef
*hdma
);
345 static void FMAC_DMAGetData(DMA_HandleTypeDef
*hdma
);
346 static void FMAC_DMAHalfOutputDataReady(DMA_HandleTypeDef
*hdma
);
347 static void FMAC_DMAOutputDataReady(DMA_HandleTypeDef
*hdma
);
348 static void FMAC_DMAFilterConfig(DMA_HandleTypeDef
*hdma
);
349 static void FMAC_DMAFilterPreload(DMA_HandleTypeDef
*hdma
);
350 static void FMAC_DMAError(DMA_HandleTypeDef
*hdma
);
352 /* Private functions ---------------------------------------------------------*/
354 /** @defgroup FMAC_Exported_Functions FMAC Exported Functions
358 /** @defgroup FMAC_Exported_Functions_Group1 Initialization and de-initialization functions
359 * @brief Initialization and Configuration functions
362 ===============================================================================
363 ##### Initialization and de-initialization functions #####
364 ===============================================================================
365 [..] This section provides functions allowing to:
366 (+) Initialize the FMAC peripheral and the associated handle
367 (+) DeInitialize the FMAC peripheral
368 (+) Initialize the FMAC MSP (MCU Specific Package)
369 (+) De-Initialize the FMAC MSP
378 * @brief Initialize the FMAC peripheral and the associated handle.
379 * @param hfmac pointer to a FMAC_HandleTypeDef structure.
382 HAL_StatusTypeDef
HAL_FMAC_Init(FMAC_HandleTypeDef
*hfmac
)
384 /* Check the FMAC handle allocation */
390 /* Check the instance */
391 assert_param(IS_FMAC_ALL_INSTANCE(hfmac
->Instance
));
393 if (hfmac
->State
== HAL_FMAC_STATE_RESET
)
395 /* Allocate lock resource and initialize it */
396 hfmac
->Lock
= HAL_UNLOCKED
;
398 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
399 /* Register the default callback functions */
400 hfmac
->ErrorCallback
= HAL_FMAC_ErrorCallback
;
401 hfmac
->HalfGetDataCallback
= HAL_FMAC_HalfGetDataCallback
;
402 hfmac
->GetDataCallback
= HAL_FMAC_GetDataCallback
;
403 hfmac
->HalfOutputDataReadyCallback
= HAL_FMAC_HalfOutputDataReadyCallback
;
404 hfmac
->OutputDataReadyCallback
= HAL_FMAC_OutputDataReadyCallback
;
405 hfmac
->FilterConfigCallback
= HAL_FMAC_FilterConfigCallback
;
406 hfmac
->FilterPreloadCallback
= HAL_FMAC_FilterPreloadCallback
;
408 if (hfmac
->MspInitCallback
== NULL
)
410 hfmac
->MspInitCallback
= HAL_FMAC_MspInit
;
413 /* Init the low level hardware */
414 hfmac
->MspInitCallback(hfmac
);
416 /* Init the low level hardware */
417 HAL_FMAC_MspInit(hfmac
);
418 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
421 /* Reset pInput and pOutput */
422 hfmac
->FilterParam
= 0UL;
423 FMAC_ResetDataPointers(hfmac
);
425 /* Reset FMAC unit (internal pointers) */
426 if (FMAC_Reset(hfmac
) == HAL_TIMEOUT
)
428 /* Update FMAC error code and FMAC peripheral state */
429 hfmac
->ErrorCode
= HAL_FMAC_ERROR_RESET
;
430 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
432 /* Process Unlocked */
438 /* Update FMAC error code and FMAC peripheral state */
439 hfmac
->ErrorCode
= HAL_FMAC_ERROR_NONE
;
440 hfmac
->State
= HAL_FMAC_STATE_READY
;
442 /* Process Unlocked */
449 * @brief De-initialize the FMAC peripheral.
450 * @param hfmac pointer to a FMAC structure.
453 HAL_StatusTypeDef
HAL_FMAC_DeInit(FMAC_HandleTypeDef
*hfmac
)
455 /* Check the FMAC handle allocation */
461 /* Check the parameters */
462 assert_param(IS_FMAC_ALL_INSTANCE(hfmac
->Instance
));
464 /* Change FMAC peripheral state */
465 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
467 /* Set FMAC error code to none */
468 hfmac
->ErrorCode
= HAL_FMAC_ERROR_NONE
;
470 /* Reset pInput and pOutput */
471 hfmac
->FilterParam
= 0UL;
472 FMAC_ResetDataPointers(hfmac
);
474 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
475 if (hfmac
->MspDeInitCallback
== NULL
)
477 hfmac
->MspDeInitCallback
= HAL_FMAC_MspDeInit
;
479 /* DeInit the low level hardware */
480 hfmac
->MspDeInitCallback(hfmac
);
482 /* DeInit the low level hardware: CLOCK, NVIC, DMA */
483 HAL_FMAC_MspDeInit(hfmac
);
484 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
486 /* Change FMAC peripheral state */
487 hfmac
->State
= HAL_FMAC_STATE_RESET
;
492 /* Return function status */
497 * @brief Initialize the FMAC MSP.
498 * @param hfmac FMAC handle.
501 __weak
void HAL_FMAC_MspInit(FMAC_HandleTypeDef
*hfmac
)
503 /* Prevent unused argument(s) compilation warning */
506 /* NOTE : This function should not be modified, when the callback is needed,
507 the HAL_FMAC_MspInit can be implemented in the user file
512 * @brief De-initialize the FMAC MSP.
513 * @param hfmac FMAC handle.
516 __weak
void HAL_FMAC_MspDeInit(FMAC_HandleTypeDef
*hfmac
)
518 /* Prevent unused argument(s) compilation warning */
521 /* NOTE : This function should not be modified, when the callback is needed,
522 the HAL_FMAC_MspDeInit can be implemented in the user file
526 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
528 * @brief Register a User FMAC Callback
529 * to be used instead of the weak predefined callback.
530 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
531 * the configuration information for FMAC module.
532 * @param CallbackID ID of the callback to be registered.
533 * This parameter can be one of the following values:
534 * @arg @ref HAL_FMAC_ERROR_CB_ID Error Callback ID
535 * @arg @ref HAL_FMAC_HALF_GET_DATA_CB_ID Get Half Data Callback ID
536 * @arg @ref HAL_FMAC_GET_DATA_CB_ID Get Data Callback ID
537 * @arg @ref HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID Half Output Data Ready Callback ID
538 * @arg @ref HAL_FMAC_OUTPUT_DATA_READY_CB_ID Output Data Ready Callback ID
539 * @arg @ref HAL_FMAC_FILTER_CONFIG_CB_ID Filter Configuration Callback ID
540 * @arg @ref HAL_FMAC_FILTER_PRELOAD_CB_ID Filter Preload Callback ID
541 * @arg @ref HAL_FMAC_MSPINIT_CB_ID FMAC MspInit ID
542 * @arg @ref HAL_FMAC_MSPDEINIT_CB_ID FMAC MspDeInit ID
543 * @param pCallback pointer to the Callback function.
546 HAL_StatusTypeDef
HAL_FMAC_RegisterCallback(FMAC_HandleTypeDef
*hfmac
, HAL_FMAC_CallbackIDTypeDef CallbackID
,
547 pFMAC_CallbackTypeDef pCallback
)
549 HAL_StatusTypeDef status
= HAL_OK
;
551 if (pCallback
== NULL
)
553 /* Update the error code */
554 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
561 if (HAL_FMAC_STATE_READY
== hfmac
->State
)
565 case HAL_FMAC_ERROR_CB_ID
:
566 hfmac
->ErrorCallback
= pCallback
;
569 case HAL_FMAC_HALF_GET_DATA_CB_ID
:
570 hfmac
->HalfGetDataCallback
= pCallback
;
573 case HAL_FMAC_GET_DATA_CB_ID
:
574 hfmac
->GetDataCallback
= pCallback
;
577 case HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID
:
578 hfmac
->HalfOutputDataReadyCallback
= pCallback
;
581 case HAL_FMAC_OUTPUT_DATA_READY_CB_ID
:
582 hfmac
->OutputDataReadyCallback
= pCallback
;
585 case HAL_FMAC_FILTER_CONFIG_CB_ID
:
586 hfmac
->FilterConfigCallback
= pCallback
;
589 case HAL_FMAC_FILTER_PRELOAD_CB_ID
:
590 hfmac
->FilterPreloadCallback
= pCallback
;
593 case HAL_FMAC_MSPINIT_CB_ID
:
594 hfmac
->MspInitCallback
= pCallback
;
597 case HAL_FMAC_MSPDEINIT_CB_ID
:
598 hfmac
->MspDeInitCallback
= pCallback
;
602 /* Update the error code */
603 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
605 /* Return error status */
610 else if (HAL_FMAC_STATE_RESET
== hfmac
->State
)
614 case HAL_FMAC_MSPINIT_CB_ID
:
615 hfmac
->MspInitCallback
= pCallback
;
618 case HAL_FMAC_MSPDEINIT_CB_ID
:
619 hfmac
->MspDeInitCallback
= pCallback
;
623 /* Update the error code */
624 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
626 /* Return error status */
633 /* Update the error code */
634 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
636 /* Return error status */
647 * @brief Unregister a FMAC CallBack.
648 * FMAC callback is redirected to the weak predefined callback.
649 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
650 * the configuration information for FMAC module
651 * @param CallbackID ID of the callback to be unregistered.
652 * This parameter can be one of the following values:
653 * @arg @ref HAL_FMAC_ERROR_CB_ID Error Callback ID
654 * @arg @ref HAL_FMAC_HALF_GET_DATA_CB_ID Get Half Data Callback ID
655 * @arg @ref HAL_FMAC_GET_DATA_CB_ID Get Data Callback ID
656 * @arg @ref HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID Half Output Data Ready Callback ID
657 * @arg @ref HAL_FMAC_OUTPUT_DATA_READY_CB_ID Output Data Ready Callback ID
658 * @arg @ref HAL_FMAC_FILTER_CONFIG_CB_ID Filter Configuration Callback ID
659 * @arg @ref HAL_FMAC_FILTER_PRELOAD_CB_ID Filter Preload Callback ID
660 * @arg @ref HAL_FMAC_MSPINIT_CB_ID FMAC MspInit ID
661 * @arg @ref HAL_FMAC_MSPDEINIT_CB_ID FMAC MspDeInit ID
664 HAL_StatusTypeDef
HAL_FMAC_UnRegisterCallback(FMAC_HandleTypeDef
*hfmac
, HAL_FMAC_CallbackIDTypeDef CallbackID
)
666 HAL_StatusTypeDef status
= HAL_OK
;
671 if (HAL_FMAC_STATE_READY
== hfmac
->State
)
675 case HAL_FMAC_ERROR_CB_ID
:
676 hfmac
->ErrorCallback
= HAL_FMAC_ErrorCallback
; /* Legacy weak ErrorCallback */
679 case HAL_FMAC_HALF_GET_DATA_CB_ID
:
680 hfmac
->HalfGetDataCallback
= HAL_FMAC_HalfGetDataCallback
; /* Legacy weak HalfGetDataCallback */
683 case HAL_FMAC_GET_DATA_CB_ID
:
684 hfmac
->GetDataCallback
= HAL_FMAC_GetDataCallback
; /* Legacy weak GetDataCallback */
687 case HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID
:
688 hfmac
->HalfOutputDataReadyCallback
= HAL_FMAC_HalfOutputDataReadyCallback
; /* Legacy weak HalfOutputDataReadyCallback */
691 case HAL_FMAC_OUTPUT_DATA_READY_CB_ID
:
692 hfmac
->OutputDataReadyCallback
= HAL_FMAC_OutputDataReadyCallback
; /* Legacy weak OutputDataReadyCallback */
695 case HAL_FMAC_FILTER_CONFIG_CB_ID
:
696 hfmac
->FilterConfigCallback
= HAL_FMAC_FilterConfigCallback
; /* Legacy weak FilterConfigCallback */
699 case HAL_FMAC_FILTER_PRELOAD_CB_ID
:
700 hfmac
->FilterPreloadCallback
= HAL_FMAC_FilterPreloadCallback
; /* Legacy weak FilterPreloadCallback */
703 case HAL_FMAC_MSPINIT_CB_ID
:
704 hfmac
->MspInitCallback
= HAL_FMAC_MspInit
; /* Legacy weak MspInitCallback */
707 case HAL_FMAC_MSPDEINIT_CB_ID
:
708 hfmac
->MspDeInitCallback
= HAL_FMAC_MspDeInit
; /* Legacy weak MspDeInitCallback */
712 /* Update the error code */
713 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
715 /* Return error status */
720 else if (HAL_FMAC_STATE_RESET
== hfmac
->State
)
724 case HAL_FMAC_MSPINIT_CB_ID
:
725 hfmac
->MspInitCallback
= HAL_FMAC_MspInit
;
728 case HAL_FMAC_MSPDEINIT_CB_ID
:
729 hfmac
->MspDeInitCallback
= HAL_FMAC_MspDeInit
;
733 /* Update the error code */
734 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
736 /* Return error status */
743 /* Update the error code */
744 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
746 /* Return error status */
755 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
761 /** @defgroup FMAC_Exported_Functions_Group2 Peripheral Control functions
762 * @brief Control functions.
765 ==============================================================================
766 ##### Peripheral Control functions #####
767 ==============================================================================
768 [..] This section provides functions allowing to:
769 (+) Configure the FMAC peripheral: memory area, filter type and parameters,
770 way to access to the input and output memory area (none, polling, IT, DMA).
771 (+) Start the FMAC processing (filter).
772 (+) Handle the input data that will be provided into FMAC.
773 (+) Handle the output data provided by FMAC.
774 (+) Stop the FMAC processing (filter).
781 * @brief Configure the FMAC filter according to the parameters
782 * specified in the FMAC_FilterConfigTypeDef structure.
783 * The provided data will be loaded using polling mode.
784 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
785 * the configuration information for FMAC module.
786 * @param sConfig pointer to a FMAC_FilterConfigTypeDef structure that
787 * contains the FMAC configuration information.
790 HAL_StatusTypeDef
HAL_FMAC_FilterConfig(FMAC_HandleTypeDef
*hfmac
, FMAC_FilterConfigTypeDef
*sConfig
)
792 return (FMAC_FilterConfig(hfmac
, sConfig
, PRELOAD_ACCESS_POLLING
));
796 * @brief Configure the FMAC filter according to the parameters
797 * specified in the FMAC_FilterConfigTypeDef structure.
798 * The provided data will be loaded using DMA.
799 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
800 * the configuration information for FMAC module.
801 * @param sConfig pointer to a FMAC_FilterConfigTypeDef structure that
802 * contains the FMAC configuration information.
805 HAL_StatusTypeDef
HAL_FMAC_FilterConfig_DMA(FMAC_HandleTypeDef
*hfmac
, FMAC_FilterConfigTypeDef
*sConfig
)
807 return (FMAC_FilterConfig(hfmac
, sConfig
, PRELOAD_ACCESS_DMA
));
811 * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
812 * They will be used by FMAC as soon as HAL_FMAC_FilterStart is called.
813 * The provided data will be loaded using polling mode.
814 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
815 * the configuration information for FMAC module.
816 * @param pInput Preloading of the first elements of the input buffer (X1).
817 * If not needed (no data available when starting), it should be set to NULL.
818 * @param InputSize Size of the input vector.
819 * As pInput is used for preloading data, it cannot be bigger than the input memory area.
820 * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
821 * If not needed, it should be set to NULL.
822 * @param OutputSize Size of the output vector.
823 * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
824 * @note The input and the output buffers can be filled by calling several times HAL_FMAC_FilterPreload
825 * (each call filling partly the buffers). In case of overflow (too much data provided through
826 * all these calls), an error will be returned.
829 HAL_StatusTypeDef
HAL_FMAC_FilterPreload(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint8_t InputSize
,
830 int16_t *pOutput
, uint8_t OutputSize
)
832 return (FMAC_FilterPreload(hfmac
, pInput
, InputSize
, pOutput
, OutputSize
, PRELOAD_ACCESS_POLLING
));
836 * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
837 * They will be used by FMAC as soon as HAL_FMAC_FilterStart is called.
838 * The provided data will be loaded using DMA.
839 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
840 * the configuration information for FMAC module.
841 * @param pInput Preloading of the first elements of the input buffer (X1).
842 * If not needed (no data available when starting), it should be set to NULL.
843 * @param InputSize Size of the input vector.
844 * As pInput is used for preloading data, it cannot be bigger than the input memory area.
845 * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
846 * If not needed, it should be set to NULL.
847 * @param OutputSize Size of the output vector.
848 * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
849 * @note The input and the output buffers can be filled by calling several times HAL_FMAC_FilterPreload
850 * (each call filling partly the buffers). In case of overflow (too much data provided through
851 * all these calls), an error will be returned.
854 HAL_StatusTypeDef
HAL_FMAC_FilterPreload_DMA(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint8_t InputSize
,
855 int16_t *pOutput
, uint8_t OutputSize
)
857 return (FMAC_FilterPreload(hfmac
, pInput
, InputSize
, pOutput
, OutputSize
, PRELOAD_ACCESS_DMA
));
862 * @brief Start the FMAC processing according to the existing FMAC configuration.
863 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
864 * the configuration information for FMAC module.
865 * @param pOutput pointer to buffer where output data of FMAC processing will be stored
867 * If it is set to NULL, the output will not be read and it will be up to
868 * an external IP to empty the output buffer.
869 * @param pOutputSize pointer to the size of the output buffer. The number of read data will be written here.
872 HAL_StatusTypeDef
HAL_FMAC_FilterStart(FMAC_HandleTypeDef
*hfmac
, int16_t *pOutput
, uint16_t *pOutputSize
)
874 uint32_t tmpcr
= 0UL;
875 HAL_StatusTypeDef status
;
877 /* Check the START bit state */
878 if (FMAC_GET_START_BIT(hfmac
) != 0UL)
883 /* Check that a valid configuration was done previously */
884 if (hfmac
->FilterParam
== 0UL)
889 /* Check handle state is ready */
890 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
892 /* Change the FMAC state */
893 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
895 /* CR: Configure the input access (error interruptions enabled only for IT or DMA) */
896 if (hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_DMA
)
898 tmpcr
|= FMAC_DMA_WEN
;
900 else if (hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_IT
)
902 tmpcr
|= FMAC_IT_WIEN
;
909 /* CR: Configure the output access (error interruptions enabled only for IT or DMA) */
910 if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_DMA
)
912 tmpcr
|= FMAC_DMA_REN
;
914 else if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_IT
)
916 tmpcr
|= FMAC_IT_RIEN
;
923 /* CR: Write the configuration */
924 MODIFY_REG(hfmac
->Instance
->CR
, \
925 FMAC_IT_RIEN
| FMAC_IT_WIEN
| FMAC_DMA_REN
| FMAC_CR_DMAWEN
, \
928 /* Register the new output buffer */
929 status
= FMAC_ConfigFilterOutputBufferUpdateState(hfmac
, pOutput
, pOutputSize
);
931 if (status
== HAL_OK
)
933 /* PARAM: Start the filter ( this can generate interrupts before the end of the HAL_FMAC_FilterStart ) */
934 WRITE_REG(hfmac
->Instance
->PARAM
, (uint32_t)(hfmac
->FilterParam
));
937 /* Reset the busy flag (do not overwrite the possible write and read flag) */
938 hfmac
->State
= HAL_FMAC_STATE_READY
;
940 /* Return function status */
945 /* Return function status */
951 * @brief Provide a new input buffer that will be loaded into the FMAC
953 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
954 * the configuration information for FMAC module.
955 * @param pInput New input vector (additional input data).
956 * @param pInputSize Size of the input vector (if all the data can't be
957 * written, it will be updated with the number of data read from FMAC).
960 HAL_StatusTypeDef
HAL_FMAC_AppendFilterData(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint16_t *pInputSize
)
962 /* Check the START bit state */
963 if (FMAC_GET_START_BIT(hfmac
) == 0UL)
968 /* Check the function parameters */
969 if ((pInput
== NULL
) || (pInputSize
== NULL
))
973 if (*pInputSize
== 0U)
978 /* Check the FMAC configuration */
979 if (hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_NONE
)
984 /* Check whether the previous input vector has been handled */
985 if ((hfmac
->pInputSize
!= NULL
) && (hfmac
->InputCurrentSize
< * (hfmac
->pInputSize
)))
990 /* Check that FMAC was initialized and that no writing is already ongoing */
991 if (hfmac
->WrState
== HAL_FMAC_STATE_READY
)
993 /* Register the new input buffer */
994 return (FMAC_AppendFilterDataUpdateState(hfmac
, pInput
, pInputSize
));
998 /* Return function status */
1004 * @brief Provide a new output buffer to be filled with the data
1005 * computed by FMAC unit.
1006 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1007 * the configuration information for FMAC module.
1008 * @param pOutput New output vector.
1009 * @param pOutputSize Size of the output vector (if the vector can't
1010 * be entirely filled, pOutputSize will be updated with the number
1011 * of data read from FMAC).
1012 * @retval HAL status
1014 HAL_StatusTypeDef
HAL_FMAC_ConfigFilterOutputBuffer(FMAC_HandleTypeDef
*hfmac
, int16_t *pOutput
, uint16_t *pOutputSize
)
1016 /* Check the START bit state */
1017 if (FMAC_GET_START_BIT(hfmac
) == 0UL)
1022 /* Check the function parameters */
1023 if ((pOutput
== NULL
) || (pOutputSize
== NULL
))
1027 if (*pOutputSize
== 0U)
1032 /* Check the FMAC configuration */
1033 if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_NONE
)
1038 /* Check whether the previous output vector has been handled */
1039 if ((hfmac
->pOutputSize
!= NULL
) && (hfmac
->OutputCurrentSize
< * (hfmac
->pOutputSize
)))
1044 /* Check that FMAC was initialized and that not reading is already ongoing */
1045 if (hfmac
->RdState
== HAL_FMAC_STATE_READY
)
1047 /* Register the new output buffer */
1048 return (FMAC_ConfigFilterOutputBufferUpdateState(hfmac
, pOutput
, pOutputSize
));
1052 /* Return function status */
1058 * @brief Write the previously provided user's input data and
1059 * fill the previously provided user's output buffer,
1060 * according to the existing FMAC configuration (polling mode only).
1061 * The function returns when the input data has been handled or
1062 * when the output data is filled. The possible unused data isn't
1063 * kept. It will be up to the user to handle it. The previously
1064 * provided pInputSize and pOutputSize will be used to indicate to the
1065 * size of the read/written data to the user.
1066 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1067 * the configuration information for FMAC module.
1068 * @param Timeout timeout value.
1069 * @retval HAL status
1071 HAL_StatusTypeDef
HAL_FMAC_PollFilterData(FMAC_HandleTypeDef
*hfmac
, uint32_t Timeout
)
1075 uint8_t inpollingover
= POLLING_NOT_STOPPED
;
1077 uint8_t outpollingover
= POLLING_NOT_STOPPED
;
1079 /* Check the START bit state */
1080 if (FMAC_GET_START_BIT(hfmac
) == 0UL)
1085 /* Check the configuration */
1087 /* Get the input and output mode (if no buffer was previously provided, nothing will be read/written) */
1088 if ((hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_POLLING
) && (hfmac
->pInput
!= NULL
))
1090 inpolling
= POLLING_ENABLED
;
1094 inpolling
= POLLING_DISABLED
;
1096 if ((hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_POLLING
) && (hfmac
->pOutput
!= NULL
))
1098 outpolling
= POLLING_ENABLED
;
1102 outpolling
= POLLING_DISABLED
;
1105 /* Check the configuration */
1106 if ((inpolling
== POLLING_DISABLED
) && (outpolling
== POLLING_DISABLED
))
1111 /* Check handle state is ready */
1112 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
1114 /* Change the FMAC state */
1115 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
1118 tickstart
= HAL_GetTick();
1120 /* Loop on reading and writing until timeout */
1121 while ((HAL_GetTick() - tickstart
) < Timeout
)
1123 /* X1: Check the mode: polling or none */
1124 if (inpolling
!= POLLING_DISABLED
)
1126 FMAC_WriteDataIncrementPtr(hfmac
, MAX_FILTER_DATA_SIZE_TO_HANDLE
);
1127 if (hfmac
->InputCurrentSize
== *(hfmac
->pInputSize
))
1129 inpollingover
= POLLING_STOPPED
;
1133 /* Y: Check the mode: polling or none */
1134 if (outpolling
!= POLLING_DISABLED
)
1136 FMAC_ReadDataIncrementPtr(hfmac
, MAX_FILTER_DATA_SIZE_TO_HANDLE
);
1137 if (hfmac
->OutputCurrentSize
== *(hfmac
->pOutputSize
))
1139 outpollingover
= POLLING_STOPPED
;
1143 /* Exit if there isn't data to handle anymore on one side or another */
1144 if ((inpollingover
!= POLLING_NOT_STOPPED
) || (outpollingover
!= POLLING_NOT_STOPPED
))
1150 /* Change the FMAC state; update the input and output sizes; reset the indexes */
1151 if (inpolling
!= POLLING_DISABLED
)
1153 (*(hfmac
->pInputSize
)) = hfmac
->InputCurrentSize
;
1154 FMAC_ResetInputStateAndDataPointers(hfmac
);
1156 if (outpolling
!= POLLING_DISABLED
)
1158 (*(hfmac
->pOutputSize
)) = hfmac
->OutputCurrentSize
;
1159 FMAC_ResetOutputStateAndDataPointers(hfmac
);
1162 /* Reset the busy flag (do not overwrite the possible write and read flag) */
1163 hfmac
->State
= HAL_FMAC_STATE_READY
;
1165 /* Return function status */
1166 if ((HAL_GetTick() - tickstart
) >= Timeout
)
1177 /* Return function status */
1183 * @brief Stop the FMAC processing.
1184 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1185 * the configuration information for FMAC module.
1186 * @retval HAL status
1188 HAL_StatusTypeDef
HAL_FMAC_FilterStop(FMAC_HandleTypeDef
*hfmac
)
1191 /* Check the START bit state */
1192 if (FMAC_GET_START_BIT(hfmac
) == 0UL)
1197 /* Check handle state is ready */
1198 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
1200 /* Set the START bit to 0 (stop the previously configured filter) */
1201 CLEAR_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
);
1203 /* Disable the interrupts in order to avoid crossing cases */
1204 CLEAR_BIT(hfmac
->Instance
->CR
, FMAC_DMA_REN
| FMAC_DMA_WEN
| FMAC_IT_RIEN
| FMAC_IT_WIEN
);
1206 /* In case of IT, update the sizes */
1207 if ((hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_IT
) && (hfmac
->pInput
!= NULL
))
1209 (*(hfmac
->pInputSize
)) = hfmac
->InputCurrentSize
;
1211 if ((hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_IT
) && (hfmac
->pOutput
!= NULL
))
1213 (*(hfmac
->pOutputSize
)) = hfmac
->OutputCurrentSize
;
1216 /* Reset FMAC unit (internal pointers) */
1217 if (FMAC_Reset(hfmac
) == HAL_TIMEOUT
)
1219 /* Update FMAC error code and FMAC peripheral state */
1220 hfmac
->ErrorCode
= HAL_FMAC_ERROR_RESET
;
1221 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
1225 /* Reset the data pointers */
1226 FMAC_ResetDataPointers(hfmac
);
1228 /* Return function status */
1233 /* Return function status */
1242 /** @defgroup FMAC_Exported_Functions_Group3 Callback functions
1243 * @brief Callback functions.
1246 ==============================================================================
1247 ##### Callback functions #####
1248 ==============================================================================
1249 [..] This section provides Interruption and DMA callback functions:
1250 (+) DMA or Interrupt: the user's input data is half written (DMA only)
1251 or completely written.
1252 (+) DMA or Interrupt: the user's output buffer is half filled (DMA only)
1253 or completely filled.
1254 (+) DMA or Interrupt: error handling.
1261 * @brief FMAC error callback.
1262 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1263 * the configuration information for FMAC module.
1266 __weak
void HAL_FMAC_ErrorCallback(FMAC_HandleTypeDef
*hfmac
)
1268 /* Prevent unused argument(s) compilation warning */
1271 /* NOTE : This function should not be modified; when the callback is needed,
1272 the HAL_FMAC_ErrorCallback can be implemented in the user file.
1277 * @brief FMAC get half data callback.
1278 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1279 * the configuration information for FMAC module.
1282 __weak
void HAL_FMAC_HalfGetDataCallback(FMAC_HandleTypeDef
*hfmac
)
1284 /* Prevent unused argument(s) compilation warning */
1287 /* NOTE : This function should not be modified; when the callback is needed,
1288 the HAL_FMAC_HalfGetDataCallback can be implemented in the user file.
1293 * @brief FMAC get data callback.
1294 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1295 * the configuration information for FMAC module.
1298 __weak
void HAL_FMAC_GetDataCallback(FMAC_HandleTypeDef
*hfmac
)
1300 /* Prevent unused argument(s) compilation warning */
1303 /* NOTE : This function should not be modified; when the callback is needed,
1304 the HAL_FMAC_GetDataCallback can be implemented in the user file.
1309 * @brief FMAC half output data ready callback.
1310 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1311 * the configuration information for FMAC module.
1314 __weak
void HAL_FMAC_HalfOutputDataReadyCallback(FMAC_HandleTypeDef
*hfmac
)
1316 /* Prevent unused argument(s) compilation warning */
1319 /* NOTE : This function should not be modified; when the callback is needed,
1320 the HAL_FMAC_HalfOutputDataReadyCallback can be implemented in the user file.
1325 * @brief FMAC output data ready callback.
1326 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1327 * the configuration information for FMAC module.
1330 __weak
void HAL_FMAC_OutputDataReadyCallback(FMAC_HandleTypeDef
*hfmac
)
1332 /* Prevent unused argument(s) compilation warning */
1335 /* NOTE : This function should not be modified; when the callback is needed,
1336 the HAL_FMAC_OutputDataReadyCallback can be implemented in the user file.
1341 * @brief FMAC filter configuration callback.
1342 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1343 * the configuration information for FMAC module.
1346 __weak
void HAL_FMAC_FilterConfigCallback(FMAC_HandleTypeDef
*hfmac
)
1348 /* Prevent unused argument(s) compilation warning */
1351 /* NOTE : This function should not be modified; when the callback is needed,
1352 the HAL_FMAC_FilterConfigCallback can be implemented in the user file.
1357 * @brief FMAC filter preload callback.
1358 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1359 * the configuration information for FMAC module.
1362 __weak
void HAL_FMAC_FilterPreloadCallback(FMAC_HandleTypeDef
*hfmac
)
1364 /* Prevent unused argument(s) compilation warning */
1367 /* NOTE : This function should not be modified; when the callback is needed,
1368 the HAL_FMAC_FilterPreloadCallback can be implemented in the user file.
1376 /** @defgroup FMAC_Exported_Functions_Group4 IRQ handler management
1377 * @brief IRQ handler.
1380 ==============================================================================
1381 ##### IRQ handler management #####
1382 ==============================================================================
1383 [..] This section provides IRQ handler function.
1390 * @brief Handle FMAC interrupt request.
1391 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1392 * the configuration information for FMAC module.
1395 void HAL_FMAC_IRQHandler(FMAC_HandleTypeDef
*hfmac
)
1399 /* Check if the read interrupt is enabled and if Y buffer empty flag isn't set */
1400 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_RIEN
);
1401 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_YEMPTY
) == 0U) && (itsource
!= 0UL))
1403 /* Read some data if possible (Y size is used as a pseudo timeout in order
1404 to not get stuck too long under IT if FMAC keeps on processing input
1405 data reloaded via DMA for instance). */
1406 if (hfmac
->pOutput
!= NULL
)
1408 FMAC_ReadDataIncrementPtr(hfmac
, (uint16_t)FMAC_GET_Y_SIZE(hfmac
));
1411 /* Indicate that data is ready to be read */
1412 if ((hfmac
->pOutput
== NULL
) || (hfmac
->OutputCurrentSize
== *(hfmac
->pOutputSize
)))
1414 /* Reset the pointers to indicate new data will be needed */
1415 FMAC_ResetOutputStateAndDataPointers(hfmac
);
1417 /* Call the output data ready callback */
1418 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
1419 hfmac
->OutputDataReadyCallback(hfmac
);
1421 HAL_FMAC_OutputDataReadyCallback(hfmac
);
1422 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
1426 /* Check if the write interrupt is enabled and if X1 buffer full flag isn't set */
1427 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_WIEN
);
1428 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_X1FULL
) == 0U) && (itsource
!= 0UL))
1430 /* Write some data if possible (X1 size is used as a pseudo timeout in order
1431 to not get stuck too long under IT if FMAC keep on processing input
1432 data whereas its output emptied via DMA for instance). */
1433 if (hfmac
->pInput
!= NULL
)
1435 FMAC_WriteDataIncrementPtr(hfmac
, (uint16_t)FMAC_GET_X1_SIZE(hfmac
));
1438 /* Indicate that new data will be needed */
1439 if ((hfmac
->pInput
== NULL
) || (hfmac
->InputCurrentSize
== *(hfmac
->pInputSize
)))
1441 /* Reset the pointers to indicate new data will be needed */
1442 FMAC_ResetInputStateAndDataPointers(hfmac
);
1444 /* Call the get data callback */
1445 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
1446 hfmac
->GetDataCallback(hfmac
);
1448 HAL_FMAC_GetDataCallback(hfmac
);
1449 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
1453 /* Check if the overflow error interrupt is enabled and if overflow error flag is raised */
1454 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_OVFLIEN
);
1455 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_OVFL
) != 0U) && (itsource
!= 0UL))
1457 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_OVFL
;
1460 /* Check if the underflow error interrupt is enabled and if underflow error flag is raised */
1461 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_UNFLIEN
);
1462 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_UNFL
) != 0U) && (itsource
!= 0UL))
1464 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_UNFL
;
1467 /* Check if the saturation error interrupt is enabled and if saturation error flag is raised */
1468 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_SATIEN
);
1469 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_SAT
) != 0U) && (itsource
!= 0UL))
1471 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_SAT
;
1474 /* Call the error callback if an error occurred */
1475 if (hfmac
->ErrorCode
!= HAL_FMAC_ERROR_NONE
)
1477 /* Call the error callback */
1478 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
1479 hfmac
->ErrorCallback(hfmac
);
1481 HAL_FMAC_ErrorCallback(hfmac
);
1482 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
1490 /** @defgroup FMAC_Exported_Functions_Group5 Peripheral State functions
1491 * @brief Peripheral State functions.
1494 ==============================================================================
1495 ##### Peripheral State functions #####
1496 ==============================================================================
1498 This subsection permits to get in run-time the status of the peripheral.
1505 * @brief Return the FMAC handle state.
1506 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1507 * the configuration information for FMAC module.
1510 HAL_FMAC_StateTypeDef
HAL_FMAC_GetState(FMAC_HandleTypeDef
*hfmac
)
1512 /* Return FMAC handle state */
1513 return hfmac
->State
;
1517 * @brief Return the FMAC peripheral error.
1518 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1519 * the configuration information for FMAC module.
1520 * @note The returned error is a bit-map combination of possible errors.
1521 * @retval Error bit-map
1523 uint32_t HAL_FMAC_GetError(FMAC_HandleTypeDef
*hfmac
)
1525 /* Return FMAC error code */
1526 return hfmac
->ErrorCode
;
1537 /** @defgroup FMAC_Private_Functions FMAC Private Functions
1542 ==============================================================================
1543 ##### FMAC Private Functions #####
1544 ==============================================================================
1547 * @brief Perform a reset of the FMAC unit.
1548 * @param hfmac FMAC handle.
1549 * @retval FMAC status
1551 static HAL_StatusTypeDef
FMAC_Reset(FMAC_HandleTypeDef
*hfmac
)
1555 /* Init tickstart for timeout management*/
1556 tickstart
= HAL_GetTick();
1558 /* Perform the reset */
1559 SET_BIT(hfmac
->Instance
->CR
, FMAC_CR_RESET
);
1561 /* Wait until flag is reset */
1562 while (READ_BIT(hfmac
->Instance
->CR
, FMAC_CR_RESET
) != 0UL)
1564 if ((HAL_GetTick() - tickstart
) > HAL_FMAC_RESET_TIMEOUT_VALUE
)
1570 hfmac
->ErrorCode
= HAL_FMAC_ERROR_NONE
;
1575 * @brief Reset the data pointers of the FMAC unit.
1576 * @param hfmac FMAC handle.
1577 * @retval FMAC status
1579 static void FMAC_ResetDataPointers(FMAC_HandleTypeDef
*hfmac
)
1581 FMAC_ResetInputStateAndDataPointers(hfmac
);
1582 FMAC_ResetOutputStateAndDataPointers(hfmac
);
1586 * @brief Reset the input data pointers of the FMAC unit.
1587 * @param hfmac FMAC handle.
1588 * @retval FMAC status
1590 static void FMAC_ResetInputStateAndDataPointers(FMAC_HandleTypeDef
*hfmac
)
1592 hfmac
->pInput
= NULL
;
1593 hfmac
->pInputSize
= NULL
;
1594 hfmac
->InputCurrentSize
= 0U;
1595 hfmac
->WrState
= HAL_FMAC_STATE_READY
;
1599 * @brief Reset the output data pointers of the FMAC unit.
1600 * @param hfmac FMAC handle.
1601 * @retval FMAC status
1603 static void FMAC_ResetOutputStateAndDataPointers(FMAC_HandleTypeDef
*hfmac
)
1605 hfmac
->pOutput
= NULL
;
1606 hfmac
->pOutputSize
= NULL
;
1607 hfmac
->OutputCurrentSize
= 0U;
1608 hfmac
->RdState
= HAL_FMAC_STATE_READY
;
1612 * @brief Configure the FMAC filter according to the parameters
1613 specified in the FMAC_FilterConfigTypeDef structure.
1614 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1615 * the configuration information for FMAC module.
1616 * @param sConfig pointer to a FMAC_FilterConfigTypeDef structure that
1617 * contains the FMAC configuration information.
1618 * @param PreloadAccess buffer preload method
1619 * This parameter can be one of the following values:
1620 * @arg @ref PRELOAD_ACCESS_POLLING preloading using CPU
1621 * @arg @ref PRELOAD_ACCESS_DMA Get preloading using DMA
1622 * @retval HAL status
1624 static HAL_StatusTypeDef
FMAC_FilterConfig(FMAC_HandleTypeDef
*hfmac
, FMAC_FilterConfigTypeDef
*sConfig
,
1625 uint8_t PreloadAccess
)
1629 #if defined(USE_FULL_ASSERT)
1631 #endif /* USE_FULL_ASSERT */
1633 /* Check the parameters */
1634 assert_param(IS_FMAC_THRESHOLD(sConfig
->InputThreshold
));
1635 assert_param(IS_FMAC_THRESHOLD(sConfig
->OutputThreshold
));
1636 assert_param(IS_FMAC_BUFFER_ACCESS(sConfig
->InputAccess
));
1637 assert_param(IS_FMAC_BUFFER_ACCESS(sConfig
->OutputAccess
));
1638 assert_param(IS_FMAC_CLIP_STATE(sConfig
->Clip
));
1639 assert_param(IS_FMAC_FILTER_FUNCTION(sConfig
->Filter
));
1640 assert_param(IS_FMAC_PARAM_P(sConfig
->Filter
, sConfig
->P
));
1641 assert_param(IS_FMAC_PARAM_Q(sConfig
->Filter
, sConfig
->Q
));
1642 assert_param(IS_FMAC_PARAM_R(sConfig
->Filter
, sConfig
->R
));
1644 /* Check the START bit state */
1645 if (FMAC_GET_START_BIT(hfmac
) != 0UL)
1650 /* Check handle state is ready */
1651 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
1653 /* Change the FMAC state */
1654 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
1657 tickstart
= HAL_GetTick();
1659 /* Indicate that there is no valid configuration done */
1660 hfmac
->FilterParam
= 0UL;
1662 /* FMAC_X1BUFCFG: Configure the input buffer within the internal memory if required */
1663 if (sConfig
->InputBufferSize
!= 0U)
1665 MODIFY_REG(hfmac
->Instance
->X1BUFCFG
, \
1666 (FMAC_X1BUFCFG_X1_BASE
| FMAC_X1BUFCFG_X1_BUF_SIZE
), \
1667 (((((uint32_t)(sConfig
->InputBaseAddress
)) << FMAC_X1BUFCFG_X1_BASE_Pos
) & FMAC_X1BUFCFG_X1_BASE
) | \
1668 ((((uint32_t)(sConfig
->InputBufferSize
)) << FMAC_X1BUFCFG_X1_BUF_SIZE_Pos
) & FMAC_X1BUFCFG_X1_BUF_SIZE
)));
1671 /* FMAC_X1BUFCFG: Configure the input threshold if valid when compared to the configured X1 size */
1672 if (sConfig
->InputThreshold
!= FMAC_THRESHOLD_NO_VALUE
)
1674 /* Check the parameter */
1675 assert_param(IS_FMAC_THRESHOLD_APPLICABLE(FMAC_GET_X1_SIZE(hfmac
), sConfig
->InputThreshold
, sConfig
->InputAccess
));
1677 MODIFY_REG(hfmac
->Instance
->X1BUFCFG
, \
1678 FMAC_X1BUFCFG_FULL_WM
, \
1679 ((sConfig
->InputThreshold
) & FMAC_X1BUFCFG_FULL_WM
));
1682 /* FMAC_X2BUFCFG: Configure the coefficient buffer within the internal memory */
1683 if (sConfig
->CoeffBufferSize
!= 0U)
1685 MODIFY_REG(hfmac
->Instance
->X2BUFCFG
, \
1686 (FMAC_X2BUFCFG_X2_BASE
| FMAC_X2BUFCFG_X2_BUF_SIZE
), \
1687 (((((uint32_t)(sConfig
->CoeffBaseAddress
)) << FMAC_X2BUFCFG_X2_BASE_Pos
) & FMAC_X2BUFCFG_X2_BASE
) | \
1688 ((((uint32_t)(sConfig
->CoeffBufferSize
)) << FMAC_X2BUFCFG_X2_BUF_SIZE_Pos
) & FMAC_X2BUFCFG_X2_BUF_SIZE
)));
1691 /* FMAC_YBUFCFG: Configure the output buffer within the internal memory if required */
1692 if (sConfig
->OutputBufferSize
!= 0U)
1694 MODIFY_REG(hfmac
->Instance
->YBUFCFG
, \
1695 (FMAC_YBUFCFG_Y_BASE
| FMAC_YBUFCFG_Y_BUF_SIZE
), \
1696 (((((uint32_t)(sConfig
->OutputBaseAddress
)) << FMAC_YBUFCFG_Y_BASE_Pos
) & FMAC_YBUFCFG_Y_BASE
) | \
1697 ((((uint32_t)(sConfig
->OutputBufferSize
)) << FMAC_YBUFCFG_Y_BUF_SIZE_Pos
) & FMAC_YBUFCFG_Y_BUF_SIZE
)));
1700 /* FMAC_YBUFCFG: Configure the output threshold if valid when compared to the configured Y size */
1701 if (sConfig
->OutputThreshold
!= FMAC_THRESHOLD_NO_VALUE
)
1703 /* Check the parameter */
1704 assert_param(IS_FMAC_THRESHOLD_APPLICABLE(FMAC_GET_Y_SIZE(hfmac
), sConfig
->OutputThreshold
, sConfig
->OutputAccess
));
1706 MODIFY_REG(hfmac
->Instance
->YBUFCFG
, \
1707 FMAC_YBUFCFG_EMPTY_WM
, \
1708 ((sConfig
->OutputThreshold
) & FMAC_YBUFCFG_EMPTY_WM
));
1711 /* CR: Configure the clip feature */
1712 tmpcr
= sConfig
->Clip
& FMAC_CR_CLIPEN
;
1714 /* CR: If IT or DMA will be used, enable error interrupts.
1715 * Being more a debugging feature, FMAC_CR_SATIEN isn't enabled by default. */
1716 if ((sConfig
->InputAccess
== FMAC_BUFFER_ACCESS_DMA
) || (sConfig
->InputAccess
== FMAC_BUFFER_ACCESS_IT
) ||
1717 (sConfig
->OutputAccess
== FMAC_BUFFER_ACCESS_DMA
) || (sConfig
->OutputAccess
== FMAC_BUFFER_ACCESS_IT
))
1719 tmpcr
|= FMAC_IT_UNFLIEN
| FMAC_IT_OVFLIEN
;
1722 /* CR: write the value */
1723 WRITE_REG(hfmac
->Instance
->CR
, tmpcr
);
1725 /* Save the input/output accesses in order to configure RIEN, WIEN, DMAREN and DMAWEN during filter start */
1726 hfmac
->InputAccess
= sConfig
->InputAccess
;
1727 hfmac
->OutputAccess
= sConfig
->OutputAccess
;
1729 /* Check whether the configured X2 is big enough for the filter */
1730 #if defined(USE_FULL_ASSERT)
1731 x2size
= FMAC_GET_X2_SIZE(hfmac
);
1732 #endif /* USE_FULL_ASSERT */
1733 assert_param(((sConfig
->Filter
== FMAC_FUNC_CONVO_FIR
) && (x2size
>= sConfig
->P
)) || \
1734 ((sConfig
->Filter
== FMAC_FUNC_IIR_DIRECT_FORM_1
) && (x2size
>= ((uint32_t)sConfig
->P
+ (uint32_t)sConfig
->Q
))));
1736 /* Build the PARAM value that will be used when starting the filter */
1737 hfmac
->FilterParam
= (FMAC_PARAM_START
| sConfig
->Filter
| \
1738 ((((uint32_t)(sConfig
->P
)) << FMAC_PARAM_P_Pos
) & FMAC_PARAM_P
) | \
1739 ((((uint32_t)(sConfig
->Q
)) << FMAC_PARAM_Q_Pos
) & FMAC_PARAM_Q
) | \
1740 ((((uint32_t)(sConfig
->R
)) << FMAC_PARAM_R_Pos
) & FMAC_PARAM_R
));
1742 /* Initialize the coefficient buffer if required (pCoeffA for FIR only) */
1743 if ((sConfig
->pCoeffB
!= NULL
) && (sConfig
->CoeffBSize
!= 0U))
1745 /* FIR/IIR: The provided coefficients should match X2 size */
1746 assert_param(((uint32_t)sConfig
->CoeffASize
+ (uint32_t)sConfig
->CoeffBSize
) <= x2size
);
1747 /* FIR/IIR: The size of pCoeffB should match the parameter P */
1748 assert_param(sConfig
->CoeffBSize
>= sConfig
->P
);
1749 /* pCoeffA should be provided for IIR but not for FIR */
1750 /* IIR : if pCoeffB is provided, pCoeffA should also be there */
1751 /* IIR: The size of pCoeffA should match the parameter Q */
1752 assert_param(((sConfig
->Filter
== FMAC_FUNC_CONVO_FIR
) &&
1753 (sConfig
->pCoeffA
== NULL
) && (sConfig
->CoeffASize
== 0U)) ||
1754 ((sConfig
->Filter
== FMAC_FUNC_IIR_DIRECT_FORM_1
) &&
1755 (sConfig
->pCoeffA
!= NULL
) && (sConfig
->CoeffASize
!= 0U) &&
1756 (sConfig
->CoeffASize
>= sConfig
->Q
)));
1758 /* Write number of values to be loaded, the data load function and start the operation */
1759 WRITE_REG(hfmac
->Instance
->PARAM
, \
1760 (((uint32_t)(sConfig
->CoeffBSize
) << FMAC_PARAM_P_Pos
) | \
1761 ((uint32_t)(sConfig
->CoeffASize
) << FMAC_PARAM_Q_Pos
) | \
1762 FMAC_FUNC_LOAD_X2
| FMAC_PARAM_START
));
1764 if (PreloadAccess
== PRELOAD_ACCESS_POLLING
)
1766 /* Load the buffer into the internal memory */
1767 FMAC_WritePreloadDataIncrementPtr(hfmac
, &(sConfig
->pCoeffB
), sConfig
->CoeffBSize
);
1769 /* Load pCoeffA if needed */
1770 if ((sConfig
->pCoeffA
!= NULL
) && (sConfig
->CoeffASize
!= 0U))
1772 /* Load the buffer into the internal memory */
1773 FMAC_WritePreloadDataIncrementPtr(hfmac
, &(sConfig
->pCoeffA
), sConfig
->CoeffASize
);
1776 /* Wait for the end of the writing */
1777 if (FMAC_WaitOnStartUntilTimeout(hfmac
, tickstart
, HAL_FMAC_TIMEOUT_VALUE
) != HAL_OK
)
1779 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
1783 /* Change the FMAC state */
1784 hfmac
->State
= HAL_FMAC_STATE_READY
;
1788 hfmac
->pInput
= sConfig
->pCoeffA
;
1789 hfmac
->InputCurrentSize
= sConfig
->CoeffASize
;
1791 /* Set the FMAC DMA transfer complete callback */
1792 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
1793 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterConfig
;
1794 /* Set the DMA error callback */
1795 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
1797 /* Enable the DMA stream managing FMAC preload data write */
1798 return (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)sConfig
->pCoeffB
, (uint32_t)&hfmac
->Instance
->WDATA
,
1799 sConfig
->CoeffBSize
));
1804 /* Change the FMAC state */
1805 hfmac
->State
= HAL_FMAC_STATE_READY
;
1810 /* Return function status */
1814 /* Return function status */
1819 * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
1820 * They will be used by FMAC as soon as HAL_FMAC_FilterStart is called.
1821 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1822 * the configuration information for FMAC module.
1823 * @param pInput Preloading of the first elements of the input buffer (X1).
1824 * If not needed (no data available when starting), it should be set to NULL.
1825 * @param InputSize Size of the input vector.
1826 * As pInput is used for preloading data, it cannot be bigger than the input memory area.
1827 * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
1828 * If not needed, it should be set to NULL.
1829 * @param OutputSize Size of the output vector.
1830 * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
1831 * @param PreloadAccess buffer preload method
1832 * This parameter can be one of the following values:
1833 * @arg @ref PRELOAD_ACCESS_POLLING preloading using CPU
1834 * @arg @ref PRELOAD_ACCESS_DMA Get preloading using DMA
1835 * @note The input and the output buffers can be filled by calling several times HAL_FMAC_FilterPreload
1836 * (each call filling partly the buffers). In case of overflow (too much data provided through
1837 * all these calls), an error will be returned.
1838 * @retval HAL status
1840 static HAL_StatusTypeDef
FMAC_FilterPreload(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint8_t InputSize
,
1841 int16_t *pOutput
, uint8_t OutputSize
, uint8_t PreloadAccess
)
1845 /* Check the START bit state */
1846 if (FMAC_GET_START_BIT(hfmac
) != 0UL)
1851 /* Check that a valid configuration was done previously */
1852 if (hfmac
->FilterParam
== 0UL)
1857 /* Check the preload input buffers isn't too big */
1858 if ((InputSize
> FMAC_GET_X1_SIZE(hfmac
)) && (pInput
!= NULL
))
1863 /* Check the preload output buffer isn't too big */
1864 if ((OutputSize
> FMAC_GET_Y_SIZE(hfmac
)) && (pOutput
!= NULL
))
1869 /* Check handle state is ready */
1870 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
1872 /* Change the FMAC state */
1873 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
1876 tickstart
= HAL_GetTick();
1878 /* Preload the input buffer if required */
1879 if ((pInput
!= NULL
) && (InputSize
!= 0U))
1881 /* Write number of values to be loaded, the data load function and start the operation */
1882 WRITE_REG(hfmac
->Instance
->PARAM
, \
1883 (((uint32_t)InputSize
<< FMAC_PARAM_P_Pos
) | FMAC_FUNC_LOAD_X1
| FMAC_PARAM_START
));
1885 if (PreloadAccess
== PRELOAD_ACCESS_POLLING
)
1887 /* Load the buffer into the internal memory */
1888 FMAC_WritePreloadDataIncrementPtr(hfmac
, &pInput
, InputSize
);
1890 /* Wait for the end of the writing */
1891 if (FMAC_WaitOnStartUntilTimeout(hfmac
, tickstart
, HAL_FMAC_TIMEOUT_VALUE
) != HAL_OK
)
1893 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
1899 hfmac
->pInput
= pOutput
;
1900 hfmac
->InputCurrentSize
= OutputSize
;
1902 /* Set the FMAC DMA transfer complete callback */
1903 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
1904 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterPreload
;
1905 /* Set the DMA error callback */
1906 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
1908 /* Enable the DMA stream managing FMAC preload data write */
1909 return (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)pInput
, (uint32_t)&hfmac
->Instance
->WDATA
, InputSize
));
1913 /* Preload the output buffer if required */
1914 if ((pOutput
!= NULL
) && (OutputSize
!= 0U))
1916 /* Write number of values to be loaded, the data load function and start the operation */
1917 WRITE_REG(hfmac
->Instance
->PARAM
, \
1918 (((uint32_t)OutputSize
<< FMAC_PARAM_P_Pos
) | FMAC_FUNC_LOAD_Y
| FMAC_PARAM_START
));
1920 if (PreloadAccess
== PRELOAD_ACCESS_POLLING
)
1922 /* Load the buffer into the internal memory */
1923 FMAC_WritePreloadDataIncrementPtr(hfmac
, &pOutput
, OutputSize
);
1925 /* Wait for the end of the writing */
1926 if (FMAC_WaitOnStartUntilTimeout(hfmac
, tickstart
, HAL_FMAC_TIMEOUT_VALUE
) != HAL_OK
)
1928 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
1934 hfmac
->pInput
= NULL
;
1935 hfmac
->InputCurrentSize
= 0U;
1937 /* Set the FMAC DMA transfer complete callback */
1938 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
1939 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterPreload
;
1940 /* Set the DMA error callback */
1941 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
1943 /* Enable the DMA stream managing FMAC preload data write */
1944 return (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)pOutput
, (uint32_t)&hfmac
->Instance
->WDATA
, OutputSize
));
1948 /* Update the error codes */
1949 if (__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_OVFL
))
1951 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_OVFL
;
1953 if (__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_UNFL
))
1955 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_UNFL
;
1958 /* Change the FMAC state */
1959 hfmac
->State
= HAL_FMAC_STATE_READY
;
1961 /* Return function status */
1962 if (hfmac
->ErrorCode
== HAL_FMAC_ERROR_NONE
)
1973 /* Return function status */
1979 * @brief Write data into FMAC internal memory through WDATA and increment input buffer pointer.
1980 * This function is only used with preload functions.
1981 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1982 * the configuration information for FMAC module.
1983 * @param ppData pointer to pointer to the data buffer.
1984 * @param Size size of the data buffer.
1987 static void FMAC_WritePreloadDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, int16_t **ppData
, uint8_t Size
)
1991 /* Load the buffer into the internal memory */
1992 for (index
= Size
; index
> 0U; index
--)
1994 WRITE_REG(hfmac
->Instance
->WDATA
, (((uint32_t)(*(*ppData
))) & FMAC_WDATA_WDATA
));
2000 * @brief Handle FMAC Function Timeout.
2001 * @param hfmac FMAC handle.
2002 * @param Tickstart Tick start value.
2003 * @param Timeout Timeout duration.
2004 * @retval HAL status
2006 static HAL_StatusTypeDef
FMAC_WaitOnStartUntilTimeout(FMAC_HandleTypeDef
*hfmac
, uint32_t Tickstart
, uint32_t Timeout
)
2008 /* Wait until flag changes */
2009 while (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) != 0UL)
2011 if ((HAL_GetTick() - Tickstart
) > Timeout
)
2013 /* Process Unlocked */
2014 __HAL_UNLOCK(hfmac
);
2023 * @brief Register the new input buffer, update DMA configuration
2024 * if needed and change the FMAC state.
2025 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
2026 * the configuration information for FMAC module.
2027 * @param pInput New input vector (additional input data).
2028 * @param pInputSize Size of the input vector (if all the data can't be
2029 * written, it will be updated with the number of data read from FMAC).
2030 * @retval HAL status
2032 static HAL_StatusTypeDef
FMAC_AppendFilterDataUpdateState(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
,
2033 uint16_t *pInputSize
)
2035 /* Change the FMAC state */
2036 hfmac
->WrState
= HAL_FMAC_STATE_BUSY_WR
;
2038 /* Reset the current size */
2039 hfmac
->InputCurrentSize
= 0U;
2041 /* Handle the pointer depending on the input access */
2042 if (hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_DMA
)
2044 hfmac
->pInput
= NULL
;
2045 hfmac
->pInputSize
= NULL
;
2047 /* Set the FMAC DMA transfer complete callback */
2048 hfmac
->hdmaIn
->XferHalfCpltCallback
= FMAC_DMAHalfGetData
;
2049 hfmac
->hdmaIn
->XferCpltCallback
= FMAC_DMAGetData
;
2050 /* Set the DMA error callback */
2051 hfmac
->hdmaIn
->XferErrorCallback
= FMAC_DMAError
;
2053 /* Enable the DMA stream managing FMAC input data write */
2054 return (HAL_DMA_Start_IT(hfmac
->hdmaIn
, (uint32_t)pInput
, (uint32_t)&hfmac
->Instance
->WDATA
, *pInputSize
));
2058 /* Update the input data information (polling, IT) */
2059 hfmac
->pInput
= pInput
;
2060 hfmac
->pInputSize
= pInputSize
;
2063 /* Return function status */
2068 * @brief Register the new output buffer, update DMA configuration
2069 * if needed and change the FMAC state.
2070 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
2071 * the configuration information for FMAC module.
2072 * @param pOutput New output vector.
2073 * @param pOutputSize Size of the output vector (if the vector can't
2074 * be entirely filled, pOutputSize will be updated with the number
2075 * of data read from FMAC).
2076 * @retval HAL status
2078 static HAL_StatusTypeDef
FMAC_ConfigFilterOutputBufferUpdateState(FMAC_HandleTypeDef
*hfmac
, int16_t *pOutput
,
2079 uint16_t *pOutputSize
)
2081 /* Reset the current size */
2082 hfmac
->OutputCurrentSize
= 0U;
2084 /* Check whether a valid pointer was provided */
2085 if ((pOutput
== NULL
) || (pOutputSize
== NULL
) || (*pOutputSize
== 0UL))
2087 /* The user will have to provide a valid configuration later */
2088 hfmac
->pOutput
= NULL
;
2089 hfmac
->pOutputSize
= NULL
;
2090 hfmac
->RdState
= HAL_FMAC_STATE_READY
;
2092 /* Handle the pointer depending on the input access */
2093 else if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_DMA
)
2095 hfmac
->pOutput
= NULL
;
2096 hfmac
->pOutputSize
= NULL
;
2097 hfmac
->RdState
= HAL_FMAC_STATE_BUSY_RD
;
2099 /* Set the FMAC DMA transfer complete callback */
2100 hfmac
->hdmaOut
->XferHalfCpltCallback
= FMAC_DMAHalfOutputDataReady
;
2101 hfmac
->hdmaOut
->XferCpltCallback
= FMAC_DMAOutputDataReady
;
2102 /* Set the DMA error callback */
2103 hfmac
->hdmaOut
->XferErrorCallback
= FMAC_DMAError
;
2105 /* Enable the DMA stream managing FMAC output data read */
2106 return (HAL_DMA_Start_IT(hfmac
->hdmaOut
, (uint32_t)&hfmac
->Instance
->RDATA
, (uint32_t)pOutput
, *pOutputSize
));
2108 else if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_NONE
)
2110 hfmac
->pOutput
= NULL
;
2111 hfmac
->pOutputSize
= NULL
;
2112 hfmac
->RdState
= HAL_FMAC_STATE_READY
;
2116 /* Update the output data information (polling, IT) */
2117 hfmac
->pOutput
= pOutput
;
2118 hfmac
->pOutputSize
= pOutputSize
;
2119 hfmac
->RdState
= HAL_FMAC_STATE_BUSY_RD
;
2122 /* Return function status */
2127 * @brief Read available output data until Y EMPTY is set.
2128 * @param hfmac FMAC handle.
2129 * @param MaxSizeToRead Maximum number of data to read (this serves as a timeout
2130 * if FMAC continuously writes into the output buffer).
2131 * @retval HAL status
2133 static void FMAC_ReadDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, uint16_t MaxSizeToRead
)
2139 /* Check if there is data to read */
2140 if (READ_BIT(hfmac
->Instance
->SR
, FMAC_SR_YEMPTY
) != 0UL)
2145 /* Get the maximum index (no wait allowed, no overstepping of the output buffer) */
2146 if ((hfmac
->OutputCurrentSize
+ MaxSizeToRead
) > *(hfmac
->pOutputSize
))
2148 maxsize
= *(hfmac
->pOutputSize
);
2152 maxsize
= hfmac
->OutputCurrentSize
+ MaxSizeToRead
;
2155 /* Read until there is no more room or no more data */
2158 /* If there is no more room, return */
2159 if (!(hfmac
->OutputCurrentSize
< maxsize
))
2164 /* Read the available data */
2165 tmpvalue
= ((READ_REG(hfmac
->Instance
->RDATA
))& FMAC_RDATA_RDATA
);
2166 *(hfmac
->pOutput
) = (int16_t)tmpvalue
;
2168 hfmac
->OutputCurrentSize
++;
2169 } while (READ_BIT(hfmac
->Instance
->SR
, FMAC_SR_YEMPTY
) == 0UL);
2171 /* Y buffer empty flag has just be raised, read the threshold */
2172 threshold
= (uint16_t)FMAC_GET_THRESHOLD_FROM_WM(FMAC_GET_Y_EMPTY_WM(hfmac
)) - 1U;
2174 /* Update the maximum size if needed (limited data available) */
2175 if ((hfmac
->OutputCurrentSize
+ threshold
) < maxsize
)
2177 maxsize
= hfmac
->OutputCurrentSize
+ threshold
;
2180 /* Read the available data */
2181 while (hfmac
->OutputCurrentSize
< maxsize
)
2183 tmpvalue
= ((READ_REG(hfmac
->Instance
->RDATA
))& FMAC_RDATA_RDATA
);
2184 *(hfmac
->pOutput
) = (int16_t)tmpvalue
;
2186 hfmac
->OutputCurrentSize
++;
2191 * @brief Write available input data until X1 FULL is set.
2192 * @param hfmac FMAC handle.
2193 * @param MaxSizeToWrite Maximum number of data to write (this serves as a timeout
2194 * if FMAC continuously empties the input buffer).
2195 * @retval HAL status
2197 static void FMAC_WriteDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, uint16_t MaxSizeToWrite
)
2202 /* Check if there is room in FMAC */
2203 if (READ_BIT(hfmac
->Instance
->SR
, FMAC_SR_X1FULL
) != 0UL)
2208 /* Get the maximum index (no wait allowed, no overstepping of the output buffer) */
2209 if ((hfmac
->InputCurrentSize
+ MaxSizeToWrite
) > *(hfmac
->pInputSize
))
2211 maxsize
= *(hfmac
->pInputSize
);
2215 maxsize
= hfmac
->InputCurrentSize
+ MaxSizeToWrite
;
2218 /* Write until there is no more room or no more data */
2221 /* If there is no more room, return */
2222 if (!(hfmac
->InputCurrentSize
< maxsize
))
2227 /* Write the available data */
2228 WRITE_REG(hfmac
->Instance
->WDATA
, (((uint32_t)(*(hfmac
->pInput
))) & FMAC_WDATA_WDATA
));
2230 hfmac
->InputCurrentSize
++;
2231 } while (READ_BIT(hfmac
->Instance
->SR
, FMAC_SR_X1FULL
) == 0UL);
2233 /* X1 buffer full flag has just be raised, read the threshold */
2234 threshold
= (uint16_t)FMAC_GET_THRESHOLD_FROM_WM(FMAC_GET_X1_FULL_WM(hfmac
)) - 1U;
2236 /* Update the maximum size if needed (limited data available) */
2237 if ((hfmac
->InputCurrentSize
+ threshold
) < maxsize
)
2239 maxsize
= hfmac
->InputCurrentSize
+ threshold
;
2242 /* Write the available data */
2243 while (hfmac
->InputCurrentSize
< maxsize
)
2245 WRITE_REG(hfmac
->Instance
->WDATA
, (((uint32_t)(*(hfmac
->pInput
))) & FMAC_WDATA_WDATA
));
2247 hfmac
->InputCurrentSize
++;
2252 * @brief DMA FMAC Input Data process half complete callback.
2253 * @param hdma DMA handle.
2256 static void FMAC_DMAHalfGetData(DMA_HandleTypeDef
*hdma
)
2258 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2260 /* Call half get data callback */
2261 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2262 hfmac
->HalfGetDataCallback(hfmac
);
2264 HAL_FMAC_HalfGetDataCallback(hfmac
);
2265 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2269 * @brief DMA FMAC Input Data process complete callback.
2270 * @param hdma DMA handle.
2273 static void FMAC_DMAGetData(DMA_HandleTypeDef
*hdma
)
2275 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2277 /* Reset the pointers to indicate new data will be needed */
2278 FMAC_ResetInputStateAndDataPointers(hfmac
);
2280 /* Call get data callback */
2281 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2282 hfmac
->GetDataCallback(hfmac
);
2284 HAL_FMAC_GetDataCallback(hfmac
);
2285 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2289 * @brief DMA FMAC Output Data process half complete callback.
2290 * @param hdma DMA handle.
2293 static void FMAC_DMAHalfOutputDataReady(DMA_HandleTypeDef
*hdma
)
2295 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2297 /* Call half output data ready callback */
2298 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2299 hfmac
->HalfOutputDataReadyCallback(hfmac
);
2301 HAL_FMAC_HalfOutputDataReadyCallback(hfmac
);
2302 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2306 * @brief DMA FMAC Output Data process complete callback.
2307 * @param hdma DMA handle.
2310 static void FMAC_DMAOutputDataReady(DMA_HandleTypeDef
*hdma
)
2312 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2314 /* Reset the pointers to indicate new data will be needed */
2315 FMAC_ResetOutputStateAndDataPointers(hfmac
);
2317 /* Call output data ready callback */
2318 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2319 hfmac
->OutputDataReadyCallback(hfmac
);
2321 HAL_FMAC_OutputDataReadyCallback(hfmac
);
2322 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2326 * @brief DMA FMAC Filter Configuration process complete callback.
2327 * @param hdma DMA handle.
2330 static void FMAC_DMAFilterConfig(DMA_HandleTypeDef
*hdma
)
2334 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2336 /* If needed, write CoeffA and exit */
2337 if (hfmac
->pInput
!= NULL
)
2339 /* Set the FMAC DMA transfer complete callback */
2340 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
2341 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterConfig
;
2342 /* Set the DMA error callback */
2343 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
2345 /* Enable the DMA stream managing FMAC preload data write */
2346 if (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)hfmac
->pInput
, (uint32_t)&hfmac
->Instance
->WDATA
,
2347 hfmac
->InputCurrentSize
) == HAL_OK
)
2349 hfmac
->pInput
= NULL
;
2350 hfmac
->InputCurrentSize
= 0U;
2354 /* If not exited, there was an error: set FMAC handle state to error */
2355 hfmac
->State
= HAL_FMAC_STATE_ERROR
;
2359 /* Wait for the end of the writing */
2360 for (index
= 0U; index
< 0xFFU
; index
++)
2362 if (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) == 0U)
2368 /* If 'START' is still set, there was an error: set FMAC handle state to error */
2369 if (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) != 0UL)
2371 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
2375 /* Change the FMAC state */
2376 hfmac
->State
= HAL_FMAC_STATE_READY
;
2378 /* Call output data ready callback */
2379 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2380 hfmac
->FilterConfigCallback(hfmac
);
2382 HAL_FMAC_FilterConfigCallback(hfmac
);
2383 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2388 /* If not exited, there was an error: set FMAC handle error code to DMA error */
2389 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_DMA
;
2391 /* Call user callback */
2392 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2393 hfmac
->ErrorCallback(hfmac
);
2395 HAL_FMAC_ErrorCallback(hfmac
);
2396 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2401 * @brief DMA FMAC Filter Configuration process complete callback.
2402 * @param hdma DMA handle.
2405 static void FMAC_DMAFilterPreload(DMA_HandleTypeDef
*hdma
)
2409 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2411 /* Wait for the end of the X1 writing */
2412 for (index
= 0U; index
< 0xFFU
; index
++)
2414 if (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) == 0UL)
2420 /* If 'START' is still set, there was an error: set FMAC handle state to error */
2421 if (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) != 0UL)
2423 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
2424 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_TIMEOUT
;
2426 /* If needed, preload Y buffer */
2427 else if ((hfmac
->pInput
!= NULL
) && (hfmac
->InputCurrentSize
!= 0U))
2429 /* Write number of values to be loaded, the data load function and start the operation */
2430 WRITE_REG(hfmac
->Instance
->PARAM
, \
2431 (((uint32_t)(hfmac
->InputCurrentSize
) << FMAC_PARAM_P_Pos
) | FMAC_FUNC_LOAD_Y
| FMAC_PARAM_START
));
2433 /* Set the FMAC DMA transfer complete callback */
2434 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
2435 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterPreload
;
2436 /* Set the DMA error callback */
2437 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
2439 /* Enable the DMA stream managing FMAC preload data write */
2440 if (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)hfmac
->pInput
, (uint32_t)&hfmac
->Instance
->WDATA
,
2441 hfmac
->InputCurrentSize
) == HAL_OK
)
2443 hfmac
->pInput
= NULL
;
2444 hfmac
->InputCurrentSize
= 0U;
2448 /* If not exited, there was an error */
2449 hfmac
->ErrorCode
= HAL_FMAC_ERROR_DMA
;
2450 hfmac
->State
= HAL_FMAC_STATE_ERROR
;
2457 /* Return function status */
2458 if (hfmac
->ErrorCode
== HAL_FMAC_ERROR_NONE
)
2460 /* Change the FMAC state */
2461 hfmac
->State
= HAL_FMAC_STATE_READY
;
2463 /* Call output data ready callback */
2464 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2465 hfmac
->FilterPreloadCallback(hfmac
);
2467 HAL_FMAC_FilterPreloadCallback(hfmac
);
2468 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2472 /* Call user callback */
2473 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2474 hfmac
->ErrorCallback(hfmac
);
2476 HAL_FMAC_ErrorCallback(hfmac
);
2477 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2483 * @brief DMA FMAC communication error callback.
2484 * @param hdma DMA handle.
2487 static void FMAC_DMAError(DMA_HandleTypeDef
*hdma
)
2489 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2491 /* Set FMAC handle state to error */
2492 hfmac
->State
= HAL_FMAC_STATE_ERROR
;
2494 /* Set FMAC handle error code to DMA error */
2495 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_DMA
;
2497 /* Call user callback */
2498 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2499 hfmac
->ErrorCallback(hfmac
);
2501 HAL_FMAC_ErrorCallback(hfmac
);
2502 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2517 #endif /* HAL_FMAC_MODULE_ENABLED */
2520 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/