2 ******************************************************************************
3 * @file stm32g4xx_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 "stm32g4xx_hal.h"
214 #ifdef HAL_FMAC_MODULE_ENABLED
216 /** @addtogroup STM32G4xx_HAL_Driver
220 /** @defgroup FMAC FMAC
221 * @brief FMAC HAL driver modules
225 /* External variables --------------------------------------------------------*/
226 /* Private typedef -----------------------------------------------------------*/
227 /* Private defines -----------------------------------------------------------*/
228 /** @defgroup FMAC_Private_Constants FMAC Private Constants
232 #define MAX_FILTER_DATA_SIZE_TO_HANDLE ((uint16_t) 0xFFU)
233 #define PRELOAD_ACCESS_DMA 0x00U
234 #define PRELOAD_ACCESS_POLLING 0x01U
235 #define POLLING_DISABLED 0U
236 #define POLLING_ENABLED 1U
237 #define POLLING_NOT_STOPPED 0U
238 #define POLLING_STOPPED 1U
244 /* Private macros ------------------------------------------------------------*/
245 /** @defgroup FMAC_Private_Macros FMAC Private Macros
250 * @brief Get the X1 memory area size.
251 * @param __HANDLE__ FMAC handle.
252 * @retval X1_BUF_SIZE
254 #define FMAC_GET_X1_SIZE(__HANDLE__) \
255 ((((__HANDLE__)->Instance->X1BUFCFG) & (FMAC_X1BUFCFG_X1_BUF_SIZE)) >> (FMAC_X1BUFCFG_X1_BUF_SIZE_Pos))
258 * @brief Get the X1 watermark.
259 * @param __HANDLE__ FMAC handle.
262 #define FMAC_GET_X1_FULL_WM(__HANDLE__) \
263 (((__HANDLE__)->Instance->X1BUFCFG) & (FMAC_X1BUFCFG_FULL_WM))
266 * @brief Get the X2 memory area size.
267 * @param __HANDLE__ FMAC handle.
268 * @retval X2_BUF_SIZE
270 #define FMAC_GET_X2_SIZE(__HANDLE__) \
271 ((((__HANDLE__)->Instance->X2BUFCFG) & (FMAC_X2BUFCFG_X2_BUF_SIZE)) >> (FMAC_X2BUFCFG_X2_BUF_SIZE_Pos))
274 * @brief Get the Y memory area size.
275 * @param __HANDLE__ FMAC handle.
278 #define FMAC_GET_Y_SIZE(__HANDLE__) \
279 ((((__HANDLE__)->Instance->YBUFCFG) & (FMAC_YBUFCFG_Y_BUF_SIZE)) >> (FMAC_YBUFCFG_Y_BUF_SIZE_Pos))
282 * @brief Get the Y watermark.
283 * @param __HANDLE__ FMAC handle.
286 #define FMAC_GET_Y_EMPTY_WM(__HANDLE__) \
287 (((__HANDLE__)->Instance->YBUFCFG) & (FMAC_YBUFCFG_EMPTY_WM))
290 * @brief Get the start bit state.
291 * @param __HANDLE__ FMAC handle.
294 #define FMAC_GET_START_BIT(__HANDLE__) \
295 ((((__HANDLE__)->Instance->PARAM) & (FMAC_PARAM_START)) >> (FMAC_PARAM_START_Pos))
298 * @brief Get the threshold matching the watermak.
299 * @param __WM__ Watermark value.
302 #define FMAC_GET_THRESHOLD_FROM_WM(__WM__) ((__WM__ == FMAC_THRESHOLD_1)? 1U: \
303 (__WM__ == FMAC_THRESHOLD_2)? 2U: \
304 (__WM__ == FMAC_THRESHOLD_4)? 4U:8U)
307 * @brief Check whether the threshold is applicable.
308 * @param __SIZE__ Size of the matching buffer.
309 * @param __WM__ Watermark value.
310 * @param __ACCESS__ Access to the buffer (polling, it, dma, none).
313 #define IS_FMAC_THRESHOLD_APPLICABLE(__SIZE__, __WM__, __ACCESS__) (( (__SIZE__) >= (((__WM__) == FMAC_THRESHOLD_1)? 1U: \
314 ((__WM__) == FMAC_THRESHOLD_2)? 2U: \
315 ((__WM__) == FMAC_THRESHOLD_4)? 4U:8U))&& \
316 ((((__ACCESS__) == FMAC_BUFFER_ACCESS_DMA)&&((__WM__) == FMAC_THRESHOLD_1))|| \
317 ((__ACCESS__ )!= FMAC_BUFFER_ACCESS_DMA)))
323 /* Private variables ---------------------------------------------------------*/
325 /* Private function prototypes -----------------------------------------------*/
327 static HAL_StatusTypeDef
FMAC_Reset(FMAC_HandleTypeDef
*hfmac
);
328 static void FMAC_ResetDataPointers(FMAC_HandleTypeDef
*hfmac
);
329 static void FMAC_ResetOutputStateAndDataPointers(FMAC_HandleTypeDef
*hfmac
);
330 static void FMAC_ResetInputStateAndDataPointers(FMAC_HandleTypeDef
*hfmac
);
331 static HAL_StatusTypeDef
FMAC_FilterConfig(FMAC_HandleTypeDef
*hfmac
, FMAC_FilterConfigTypeDef
*sConfig
,
332 uint8_t PreloadAccess
);
333 static HAL_StatusTypeDef
FMAC_FilterPreload(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint8_t InputSize
,
334 int16_t *pOutput
, uint8_t OutputSize
, uint8_t PreloadAccess
);
335 static void FMAC_WritePreloadDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, int16_t **ppData
, uint8_t Size
);
336 static HAL_StatusTypeDef
FMAC_WaitOnStartUntilTimeout(FMAC_HandleTypeDef
*hfmac
, uint32_t Tickstart
, uint32_t Timeout
);
337 static HAL_StatusTypeDef
FMAC_AppendFilterDataUpdateState(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
,
338 uint16_t *pInputSize
);
339 static HAL_StatusTypeDef
FMAC_ConfigFilterOutputBufferUpdateState(FMAC_HandleTypeDef
*hfmac
, int16_t *pOutput
,
340 uint16_t *pOutputSize
);
341 static void FMAC_WriteDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, uint16_t MaxSizeToWrite
);
342 static void FMAC_ReadDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, uint16_t MaxSizeToRead
);
343 static void FMAC_DMAHalfGetData(DMA_HandleTypeDef
*hdma
);
344 static void FMAC_DMAGetData(DMA_HandleTypeDef
*hdma
);
345 static void FMAC_DMAHalfOutputDataReady(DMA_HandleTypeDef
*hdma
);
346 static void FMAC_DMAOutputDataReady(DMA_HandleTypeDef
*hdma
);
347 static void FMAC_DMAFilterConfig(DMA_HandleTypeDef
*hdma
);
348 static void FMAC_DMAFilterPreload(DMA_HandleTypeDef
*hdma
);
349 static void FMAC_DMAError(DMA_HandleTypeDef
*hdma
);
351 /* Private functions ---------------------------------------------------------*/
353 /** @defgroup FMAC_Exported_Functions FMAC Exported Functions
357 /** @defgroup FMAC_Exported_Functions_Group1 Initialization and de-initialization functions
358 * @brief Initialization and Configuration functions
361 ===============================================================================
362 ##### Initialization and de-initialization functions #####
363 ===============================================================================
364 [..] This section provides functions allowing to:
365 (+) Initialize the FMAC peripheral and the associated handle
366 (+) DeInitialize the FMAC peripheral
367 (+) Initialize the FMAC MSP (MCU Specific Package)
368 (+) De-Initialize the FMAC MSP
377 * @brief Initialize the FMAC peripheral and the associated handle.
378 * @param hfmac pointer to a FMAC_HandleTypeDef structure.
381 HAL_StatusTypeDef
HAL_FMAC_Init(FMAC_HandleTypeDef
*hfmac
)
383 /* Check the FMAC handle allocation */
389 /* Check the instance */
390 assert_param(IS_FMAC_ALL_INSTANCE(hfmac
->Instance
));
392 if (hfmac
->State
== HAL_FMAC_STATE_RESET
)
394 /* Allocate lock resource and initialize it */
395 hfmac
->Lock
= HAL_UNLOCKED
;
397 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
398 /* Register the default callback functions */
399 hfmac
->ErrorCallback
= HAL_FMAC_ErrorCallback
;
400 hfmac
->HalfGetDataCallback
= HAL_FMAC_HalfGetDataCallback
;
401 hfmac
->GetDataCallback
= HAL_FMAC_GetDataCallback
;
402 hfmac
->HalfOutputDataReadyCallback
= HAL_FMAC_HalfOutputDataReadyCallback
;
403 hfmac
->OutputDataReadyCallback
= HAL_FMAC_OutputDataReadyCallback
;
404 hfmac
->FilterConfigCallback
= HAL_FMAC_FilterConfigCallback
;
405 hfmac
->FilterPreloadCallback
= HAL_FMAC_FilterPreloadCallback
;
407 if (hfmac
->MspInitCallback
== NULL
)
409 hfmac
->MspInitCallback
= HAL_FMAC_MspInit
;
412 /* Init the low level hardware */
413 hfmac
->MspInitCallback(hfmac
);
415 /* Init the low level hardware */
416 HAL_FMAC_MspInit(hfmac
);
417 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
420 /* Reset pInput and pOutput */
421 hfmac
->FilterParam
= 0UL;
422 FMAC_ResetDataPointers(hfmac
);
424 /* Reset FMAC unit (internal pointers) */
425 if (FMAC_Reset(hfmac
) == HAL_TIMEOUT
)
427 /* Update FMAC error code and FMAC peripheral state */
428 hfmac
->ErrorCode
= HAL_FMAC_ERROR_RESET
;
429 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
431 /* Process Unlocked */
437 /* Update FMAC error code and FMAC peripheral state */
438 hfmac
->ErrorCode
= HAL_FMAC_ERROR_NONE
;
439 hfmac
->State
= HAL_FMAC_STATE_READY
;
441 /* Process Unlocked */
448 * @brief De-initialize the FMAC peripheral.
449 * @param hfmac pointer to a FMAC structure.
452 HAL_StatusTypeDef
HAL_FMAC_DeInit(FMAC_HandleTypeDef
*hfmac
)
454 /* Check the FMAC handle allocation */
460 /* Check the parameters */
461 assert_param(IS_FMAC_ALL_INSTANCE(hfmac
->Instance
));
463 /* Change FMAC peripheral state */
464 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
466 /* Set FMAC error code to none */
467 hfmac
->ErrorCode
= HAL_FMAC_ERROR_NONE
;
469 /* Reset pInput and pOutput */
470 hfmac
->FilterParam
= 0UL;
471 FMAC_ResetDataPointers(hfmac
);
473 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
474 if (hfmac
->MspDeInitCallback
== NULL
)
476 hfmac
->MspDeInitCallback
= HAL_FMAC_MspDeInit
;
478 /* DeInit the low level hardware */
479 hfmac
->MspDeInitCallback(hfmac
);
481 /* DeInit the low level hardware: CLOCK, NVIC, DMA */
482 HAL_FMAC_MspDeInit(hfmac
);
483 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
485 /* Change FMAC peripheral state */
486 hfmac
->State
= HAL_FMAC_STATE_RESET
;
491 /* Return function status */
496 * @brief Initialize the FMAC MSP.
497 * @param hfmac FMAC handle.
500 __weak
void HAL_FMAC_MspInit(FMAC_HandleTypeDef
*hfmac
)
502 /* Prevent unused argument(s) compilation warning */
505 /* NOTE : This function should not be modified, when the callback is needed,
506 the HAL_FMAC_MspInit can be implemented in the user file
511 * @brief De-initialize the FMAC MSP.
512 * @param hfmac FMAC handle.
515 __weak
void HAL_FMAC_MspDeInit(FMAC_HandleTypeDef
*hfmac
)
517 /* Prevent unused argument(s) compilation warning */
520 /* NOTE : This function should not be modified, when the callback is needed,
521 the HAL_FMAC_MspDeInit can be implemented in the user file
525 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
527 * @brief Register a User FMAC Callback
528 * to be used instead of the weak predefined callback.
529 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
530 * the configuration information for FMAC module.
531 * @param CallbackID ID of the callback to be registered.
532 * This parameter can be one of the following values:
533 * @arg @ref HAL_FMAC_ERROR_CB_ID Error Callback ID
534 * @arg @ref HAL_FMAC_HALF_GET_DATA_CB_ID Get Half Data Callback ID
535 * @arg @ref HAL_FMAC_GET_DATA_CB_ID Get Data Callback ID
536 * @arg @ref HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID Half Output Data Ready Callback ID
537 * @arg @ref HAL_FMAC_OUTPUT_DATA_READY_CB_ID Output Data Ready Callback ID
538 * @arg @ref HAL_FMAC_FILTER_CONFIG_CB_ID Filter Configuration Callback ID
539 * @arg @ref HAL_FMAC_FILTER_PRELOAD_CB_ID Filter Preload Callback ID
540 * @arg @ref HAL_FMAC_MSPINIT_CB_ID FMAC MspInit ID
541 * @arg @ref HAL_FMAC_MSPDEINIT_CB_ID FMAC MspDeInit ID
542 * @param pCallback pointer to the Callback function.
545 HAL_StatusTypeDef
HAL_FMAC_RegisterCallback(FMAC_HandleTypeDef
*hfmac
, HAL_FMAC_CallbackIDTypeDef CallbackID
,
546 pFMAC_CallbackTypeDef pCallback
)
548 HAL_StatusTypeDef status
= HAL_OK
;
550 if (pCallback
== NULL
)
552 /* Update the error code */
553 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
560 if (HAL_FMAC_STATE_READY
== hfmac
->State
)
564 case HAL_FMAC_ERROR_CB_ID
:
565 hfmac
->ErrorCallback
= pCallback
;
568 case HAL_FMAC_HALF_GET_DATA_CB_ID
:
569 hfmac
->HalfGetDataCallback
= pCallback
;
572 case HAL_FMAC_GET_DATA_CB_ID
:
573 hfmac
->GetDataCallback
= pCallback
;
576 case HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID
:
577 hfmac
->HalfOutputDataReadyCallback
= pCallback
;
580 case HAL_FMAC_OUTPUT_DATA_READY_CB_ID
:
581 hfmac
->OutputDataReadyCallback
= pCallback
;
584 case HAL_FMAC_FILTER_CONFIG_CB_ID
:
585 hfmac
->FilterConfigCallback
= pCallback
;
588 case HAL_FMAC_FILTER_PRELOAD_CB_ID
:
589 hfmac
->FilterPreloadCallback
= pCallback
;
592 case HAL_FMAC_MSPINIT_CB_ID
:
593 hfmac
->MspInitCallback
= pCallback
;
596 case HAL_FMAC_MSPDEINIT_CB_ID
:
597 hfmac
->MspDeInitCallback
= pCallback
;
601 /* Update the error code */
602 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
604 /* Return error status */
609 else if (HAL_FMAC_STATE_RESET
== hfmac
->State
)
613 case HAL_FMAC_MSPINIT_CB_ID
:
614 hfmac
->MspInitCallback
= pCallback
;
617 case HAL_FMAC_MSPDEINIT_CB_ID
:
618 hfmac
->MspDeInitCallback
= pCallback
;
622 /* Update the error code */
623 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
625 /* Return error status */
632 /* Update the error code */
633 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
635 /* Return error status */
646 * @brief Unregister a FMAC CallBack.
647 * FMAC callback is redirected to the weak predefined callback.
648 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
649 * the configuration information for FMAC module
650 * @param CallbackID ID of the callback to be unregistered.
651 * This parameter can be one of the following values:
652 * @arg @ref HAL_FMAC_ERROR_CB_ID Error Callback ID
653 * @arg @ref HAL_FMAC_HALF_GET_DATA_CB_ID Get Half Data Callback ID
654 * @arg @ref HAL_FMAC_GET_DATA_CB_ID Get Data Callback ID
655 * @arg @ref HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID Half Output Data Ready Callback ID
656 * @arg @ref HAL_FMAC_OUTPUT_DATA_READY_CB_ID Output Data Ready Callback ID
657 * @arg @ref HAL_FMAC_FILTER_CONFIG_CB_ID Filter Configuration Callback ID
658 * @arg @ref HAL_FMAC_FILTER_PRELOAD_CB_ID Filter Preload Callback ID
659 * @arg @ref HAL_FMAC_MSPINIT_CB_ID FMAC MspInit ID
660 * @arg @ref HAL_FMAC_MSPDEINIT_CB_ID FMAC MspDeInit ID
663 HAL_StatusTypeDef
HAL_FMAC_UnRegisterCallback(FMAC_HandleTypeDef
*hfmac
, HAL_FMAC_CallbackIDTypeDef CallbackID
)
665 HAL_StatusTypeDef status
= HAL_OK
;
670 if (HAL_FMAC_STATE_READY
== hfmac
->State
)
674 case HAL_FMAC_ERROR_CB_ID
:
675 hfmac
->ErrorCallback
= HAL_FMAC_ErrorCallback
; /* Legacy weak ErrorCallback */
678 case HAL_FMAC_HALF_GET_DATA_CB_ID
:
679 hfmac
->HalfGetDataCallback
= HAL_FMAC_HalfGetDataCallback
; /* Legacy weak HalfGetDataCallback */
682 case HAL_FMAC_GET_DATA_CB_ID
:
683 hfmac
->GetDataCallback
= HAL_FMAC_GetDataCallback
; /* Legacy weak GetDataCallback */
686 case HAL_FMAC_HALF_OUTPUT_DATA_READY_CB_ID
:
687 hfmac
->HalfOutputDataReadyCallback
= HAL_FMAC_HalfOutputDataReadyCallback
; /* Legacy weak HalfOutputDataReadyCallback */
690 case HAL_FMAC_OUTPUT_DATA_READY_CB_ID
:
691 hfmac
->OutputDataReadyCallback
= HAL_FMAC_OutputDataReadyCallback
; /* Legacy weak OutputDataReadyCallback */
694 case HAL_FMAC_FILTER_CONFIG_CB_ID
:
695 hfmac
->FilterConfigCallback
= HAL_FMAC_FilterConfigCallback
; /* Legacy weak FilterConfigCallback */
698 case HAL_FMAC_FILTER_PRELOAD_CB_ID
:
699 hfmac
->FilterPreloadCallback
= HAL_FMAC_FilterPreloadCallback
; /* Legacy weak FilterPreloadCallback */
702 case HAL_FMAC_MSPINIT_CB_ID
:
703 hfmac
->MspInitCallback
= HAL_FMAC_MspInit
; /* Legacy weak MspInitCallback */
706 case HAL_FMAC_MSPDEINIT_CB_ID
:
707 hfmac
->MspDeInitCallback
= HAL_FMAC_MspDeInit
; /* Legacy weak MspDeInitCallback */
711 /* Update the error code */
712 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
714 /* Return error status */
719 else if (HAL_FMAC_STATE_RESET
== hfmac
->State
)
723 case HAL_FMAC_MSPINIT_CB_ID
:
724 hfmac
->MspInitCallback
= HAL_FMAC_MspInit
;
727 case HAL_FMAC_MSPDEINIT_CB_ID
:
728 hfmac
->MspDeInitCallback
= HAL_FMAC_MspDeInit
;
732 /* Update the error code */
733 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
735 /* Return error status */
742 /* Update the error code */
743 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_INVALID_CALLBACK
;
745 /* Return error status */
754 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
760 /** @defgroup FMAC_Exported_Functions_Group2 Peripheral Control functions
761 * @brief Control functions.
764 ==============================================================================
765 ##### Peripheral Control functions #####
766 ==============================================================================
767 [..] This section provides functions allowing to:
768 (+) Configure the FMAC peripheral: memory area, filter type and parameters,
769 way to access to the input and output memory area (none, polling, IT, DMA).
770 (+) Start the FMAC processing (filter).
771 (+) Handle the input data that will be provided into FMAC.
772 (+) Handle the output data provided by FMAC.
773 (+) Stop the FMAC processing (filter).
780 * @brief Configure the FMAC filter according to the parameters
781 * specified in the FMAC_FilterConfigTypeDef structure.
782 * The provided data will be loaded using polling mode.
783 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
784 * the configuration information for FMAC module.
785 * @param sConfig pointer to a FMAC_FilterConfigTypeDef structure that
786 * contains the FMAC configuration information.
789 HAL_StatusTypeDef
HAL_FMAC_FilterConfig(FMAC_HandleTypeDef
*hfmac
, FMAC_FilterConfigTypeDef
*sConfig
)
791 return (FMAC_FilterConfig(hfmac
, sConfig
, PRELOAD_ACCESS_POLLING
));
795 * @brief Configure the FMAC filter according to the parameters
796 * specified in the FMAC_FilterConfigTypeDef structure.
797 * The provided data will be loaded using DMA.
798 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
799 * the configuration information for FMAC module.
800 * @param sConfig pointer to a FMAC_FilterConfigTypeDef structure that
801 * contains the FMAC configuration information.
804 HAL_StatusTypeDef
HAL_FMAC_FilterConfig_DMA(FMAC_HandleTypeDef
*hfmac
, FMAC_FilterConfigTypeDef
*sConfig
)
806 return (FMAC_FilterConfig(hfmac
, sConfig
, PRELOAD_ACCESS_DMA
));
810 * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
811 * They will be used by FMAC as soon as HAL_FMAC_FilterStart is called.
812 * The provided data will be loaded using polling mode.
813 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
814 * the configuration information for FMAC module.
815 * @param pInput Preloading of the first elements of the input buffer (X1).
816 * If not needed (no data available when starting), it should be set to NULL.
817 * @param InputSize Size of the input vector.
818 * As pInput is used for preloading data, it cannot be bigger than the input memory area.
819 * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
820 * If not needed, it should be set to NULL.
821 * @param OutputSize Size of the output vector.
822 * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
823 * @note The input and the output buffers can be filled by calling several times HAL_FMAC_FilterPreload
824 * (each call filling partly the buffers). In case of overflow (too much data provided through
825 * all these calls), an error will be returned.
828 HAL_StatusTypeDef
HAL_FMAC_FilterPreload(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint8_t InputSize
,
829 int16_t *pOutput
, uint8_t OutputSize
)
831 return (FMAC_FilterPreload(hfmac
, pInput
, InputSize
, pOutput
, OutputSize
, PRELOAD_ACCESS_POLLING
));
835 * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
836 * They will be used by FMAC as soon as HAL_FMAC_FilterStart is called.
837 * The provided data will be loaded using DMA.
838 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
839 * the configuration information for FMAC module.
840 * @param pInput Preloading of the first elements of the input buffer (X1).
841 * If not needed (no data available when starting), it should be set to NULL.
842 * @param InputSize Size of the input vector.
843 * As pInput is used for preloading data, it cannot be bigger than the input memory area.
844 * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
845 * If not needed, it should be set to NULL.
846 * @param OutputSize Size of the output vector.
847 * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
848 * @note The input and the output buffers can be filled by calling several times HAL_FMAC_FilterPreload
849 * (each call filling partly the buffers). In case of overflow (too much data provided through
850 * all these calls), an error will be returned.
853 HAL_StatusTypeDef
HAL_FMAC_FilterPreload_DMA(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint8_t InputSize
,
854 int16_t *pOutput
, uint8_t OutputSize
)
856 return (FMAC_FilterPreload(hfmac
, pInput
, InputSize
, pOutput
, OutputSize
, PRELOAD_ACCESS_DMA
));
861 * @brief Start the FMAC processing according to the existing FMAC configuration.
862 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
863 * the configuration information for FMAC module.
864 * @param pOutput pointer to buffer where output data of FMAC processing will be stored
866 * If it is set to NULL, the output will not be read and it will be up to
867 * an external IP to empty the output buffer.
868 * @param pOutputSize pointer to the size of the output buffer. The number of read data will be written here.
871 HAL_StatusTypeDef
HAL_FMAC_FilterStart(FMAC_HandleTypeDef
*hfmac
, int16_t *pOutput
, uint16_t *pOutputSize
)
873 uint32_t tmpcr
= 0UL;
874 HAL_StatusTypeDef status
;
876 /* Check the START bit state */
877 if (FMAC_GET_START_BIT(hfmac
) != 0UL)
882 /* Check that a valid configuration was done previously */
883 if (hfmac
->FilterParam
== 0UL)
888 /* Check handle state is ready */
889 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
891 /* Change the FMAC state */
892 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
894 /* CR: Configure the input access (error interruptions enabled only for IT or DMA) */
895 if (hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_DMA
)
897 tmpcr
|= FMAC_DMA_WEN
;
899 else if (hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_IT
)
901 tmpcr
|= FMAC_IT_WIEN
;
908 /* CR: Configure the output access (error interruptions enabled only for IT or DMA) */
909 if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_DMA
)
911 tmpcr
|= FMAC_DMA_REN
;
913 else if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_IT
)
915 tmpcr
|= FMAC_IT_RIEN
;
922 /* CR: Write the configuration */
923 MODIFY_REG(hfmac
->Instance
->CR
, \
924 FMAC_IT_RIEN
| FMAC_IT_WIEN
| FMAC_DMA_REN
| FMAC_CR_DMAWEN
, \
927 /* Register the new output buffer */
928 status
= FMAC_ConfigFilterOutputBufferUpdateState(hfmac
, pOutput
, pOutputSize
);
930 if (status
== HAL_OK
)
932 /* PARAM: Start the filter ( this can generate interrupts before the end of the HAL_FMAC_FilterStart ) */
933 WRITE_REG(hfmac
->Instance
->PARAM
, (uint32_t)(hfmac
->FilterParam
));
936 /* Reset the busy flag (do not overwrite the possible write and read flag) */
937 hfmac
->State
= HAL_FMAC_STATE_READY
;
939 /* Return function status */
944 /* Return function status */
950 * @brief Provide a new input buffer that will be loaded into the FMAC
952 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
953 * the configuration information for FMAC module.
954 * @param pInput New input vector (additional input data).
955 * @param pInputSize Size of the input vector (if all the data can't be
956 * written, it will be updated with the number of data read from FMAC).
959 HAL_StatusTypeDef
HAL_FMAC_AppendFilterData(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint16_t *pInputSize
)
961 /* Check the START bit state */
962 if (FMAC_GET_START_BIT(hfmac
) == 0UL)
967 /* Check the function parameters */
968 if ((pInput
== NULL
) || (pInputSize
== NULL
))
972 if (*pInputSize
== 0U)
977 /* Check the FMAC configuration */
978 if (hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_NONE
)
983 /* Check whether the previous input vector has been handled */
984 if ((hfmac
->pInputSize
!= NULL
) && (hfmac
->InputCurrentSize
< * (hfmac
->pInputSize
)))
989 /* Check that FMAC was initialized and that no writing is already ongoing */
990 if (hfmac
->WrState
== HAL_FMAC_STATE_READY
)
992 /* Register the new input buffer */
993 return (FMAC_AppendFilterDataUpdateState(hfmac
, pInput
, pInputSize
));
997 /* Return function status */
1003 * @brief Provide a new output buffer to be filled with the data
1004 * computed by FMAC unit.
1005 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1006 * the configuration information for FMAC module.
1007 * @param pOutput New output vector.
1008 * @param pOutputSize Size of the output vector (if the vector can't
1009 * be entirely filled, pOutputSize will be updated with the number
1010 * of data read from FMAC).
1011 * @retval HAL status
1013 HAL_StatusTypeDef
HAL_FMAC_ConfigFilterOutputBuffer(FMAC_HandleTypeDef
*hfmac
, int16_t *pOutput
, uint16_t *pOutputSize
)
1015 /* Check the START bit state */
1016 if (FMAC_GET_START_BIT(hfmac
) == 0UL)
1021 /* Check the function parameters */
1022 if ((pOutput
== NULL
) || (pOutputSize
== NULL
))
1026 if (*pOutputSize
== 0U)
1031 /* Check the FMAC configuration */
1032 if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_NONE
)
1037 /* Check whether the previous output vector has been handled */
1038 if ((hfmac
->pOutputSize
!= NULL
) && (hfmac
->OutputCurrentSize
< * (hfmac
->pOutputSize
)))
1043 /* Check that FMAC was initialized and that not reading is already ongoing */
1044 if (hfmac
->RdState
== HAL_FMAC_STATE_READY
)
1046 /* Register the new output buffer */
1047 return (FMAC_ConfigFilterOutputBufferUpdateState(hfmac
, pOutput
, pOutputSize
));
1051 /* Return function status */
1057 * @brief Write the previously provided user's input data and
1058 * fill the previously provided user's output buffer,
1059 * according to the existing FMAC configuration (polling mode only).
1060 * The function returns when the input data has been handled or
1061 * when the output data is filled. The possible unused data isn't
1062 * kept. It will be up to the user to handle it. The previously
1063 * provided pInputSize and pOutputSize will be used to indicate to the
1064 * size of the read/written data to the user.
1065 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1066 * the configuration information for FMAC module.
1067 * @param Timeout timeout value.
1068 * @retval HAL status
1070 HAL_StatusTypeDef
HAL_FMAC_PollFilterData(FMAC_HandleTypeDef
*hfmac
, uint32_t Timeout
)
1074 uint8_t inpollingover
= POLLING_NOT_STOPPED
;
1076 uint8_t outpollingover
= POLLING_NOT_STOPPED
;
1078 /* Check the START bit state */
1079 if (FMAC_GET_START_BIT(hfmac
) == 0UL)
1084 /* Check the configuration */
1086 /* Get the input and output mode (if no buffer was previously provided, nothing will be read/written) */
1087 if ((hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_POLLING
) && (hfmac
->pInput
!= NULL
))
1089 inpolling
= POLLING_ENABLED
;
1093 inpolling
= POLLING_DISABLED
;
1095 if ((hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_POLLING
) && (hfmac
->pOutput
!= NULL
))
1097 outpolling
= POLLING_ENABLED
;
1101 outpolling
= POLLING_DISABLED
;
1104 /* Check the configuration */
1105 if ((inpolling
== POLLING_DISABLED
) && (outpolling
== POLLING_DISABLED
))
1110 /* Check handle state is ready */
1111 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
1113 /* Change the FMAC state */
1114 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
1117 tickstart
= HAL_GetTick();
1119 /* Loop on reading and writing until timeout */
1120 while ((HAL_GetTick() - tickstart
) < Timeout
)
1122 /* X1: Check the mode: polling or none */
1123 if (inpolling
!= POLLING_DISABLED
)
1125 FMAC_WriteDataIncrementPtr(hfmac
, MAX_FILTER_DATA_SIZE_TO_HANDLE
);
1126 if (hfmac
->InputCurrentSize
== *(hfmac
->pInputSize
))
1128 inpollingover
= POLLING_STOPPED
;
1132 /* Y: Check the mode: polling or none */
1133 if (outpolling
!= POLLING_DISABLED
)
1135 FMAC_ReadDataIncrementPtr(hfmac
, MAX_FILTER_DATA_SIZE_TO_HANDLE
);
1136 if (hfmac
->OutputCurrentSize
== *(hfmac
->pOutputSize
))
1138 outpollingover
= POLLING_STOPPED
;
1142 /* Exit if there isn't data to handle anymore on one side or another */
1143 if ((inpollingover
!= POLLING_NOT_STOPPED
) || (outpollingover
!= POLLING_NOT_STOPPED
))
1149 /* Change the FMAC state; update the input and output sizes; reset the indexes */
1150 if (inpolling
!= POLLING_DISABLED
)
1152 (*(hfmac
->pInputSize
)) = hfmac
->InputCurrentSize
;
1153 FMAC_ResetInputStateAndDataPointers(hfmac
);
1155 if (outpolling
!= POLLING_DISABLED
)
1157 (*(hfmac
->pOutputSize
)) = hfmac
->OutputCurrentSize
;
1158 FMAC_ResetOutputStateAndDataPointers(hfmac
);
1161 /* Reset the busy flag (do not overwrite the possible write and read flag) */
1162 hfmac
->State
= HAL_FMAC_STATE_READY
;
1164 /* Return function status */
1165 if ((HAL_GetTick() - tickstart
) >= Timeout
)
1176 /* Return function status */
1182 * @brief Stop the FMAC processing.
1183 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1184 * the configuration information for FMAC module.
1185 * @retval HAL status
1187 HAL_StatusTypeDef
HAL_FMAC_FilterStop(FMAC_HandleTypeDef
*hfmac
)
1190 /* Check the START bit state */
1191 if (FMAC_GET_START_BIT(hfmac
) == 0UL)
1196 /* Check handle state is ready */
1197 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
1199 /* Set the START bit to 0 (stop the previously configured filter) */
1200 CLEAR_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
);
1202 /* Disable the interrupts in order to avoid crossing cases */
1203 CLEAR_BIT(hfmac
->Instance
->CR
, FMAC_DMA_REN
| FMAC_DMA_WEN
| FMAC_IT_RIEN
| FMAC_IT_WIEN
);
1205 /* In case of IT, update the sizes */
1206 if ((hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_IT
) && (hfmac
->pInput
!= NULL
))
1208 (*(hfmac
->pInputSize
)) = hfmac
->InputCurrentSize
;
1210 if ((hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_IT
) && (hfmac
->pOutput
!= NULL
))
1212 (*(hfmac
->pOutputSize
)) = hfmac
->OutputCurrentSize
;
1215 /* Reset FMAC unit (internal pointers) */
1216 if (FMAC_Reset(hfmac
) == HAL_TIMEOUT
)
1218 /* Update FMAC error code and FMAC peripheral state */
1219 hfmac
->ErrorCode
= HAL_FMAC_ERROR_RESET
;
1220 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
1224 /* Reset the data pointers */
1225 FMAC_ResetDataPointers(hfmac
);
1227 /* Return function status */
1232 /* Return function status */
1241 /** @defgroup FMAC_Exported_Functions_Group3 Callback functions
1242 * @brief Callback functions.
1245 ==============================================================================
1246 ##### Callback functions #####
1247 ==============================================================================
1248 [..] This section provides Interruption and DMA callback functions:
1249 (+) DMA or Interrupt: the user's input data is half written (DMA only)
1250 or completely written.
1251 (+) DMA or Interrupt: the user's output buffer is half filled (DMA only)
1252 or completely filled.
1253 (+) DMA or Interrupt: error handling.
1260 * @brief FMAC error callback.
1261 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1262 * the configuration information for FMAC module.
1265 __weak
void HAL_FMAC_ErrorCallback(FMAC_HandleTypeDef
*hfmac
)
1267 /* Prevent unused argument(s) compilation warning */
1270 /* NOTE : This function should not be modified; when the callback is needed,
1271 the HAL_FMAC_ErrorCallback can be implemented in the user file.
1276 * @brief FMAC get half data callback.
1277 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1278 * the configuration information for FMAC module.
1281 __weak
void HAL_FMAC_HalfGetDataCallback(FMAC_HandleTypeDef
*hfmac
)
1283 /* Prevent unused argument(s) compilation warning */
1286 /* NOTE : This function should not be modified; when the callback is needed,
1287 the HAL_FMAC_HalfGetDataCallback can be implemented in the user file.
1292 * @brief FMAC get data callback.
1293 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1294 * the configuration information for FMAC module.
1297 __weak
void HAL_FMAC_GetDataCallback(FMAC_HandleTypeDef
*hfmac
)
1299 /* Prevent unused argument(s) compilation warning */
1302 /* NOTE : This function should not be modified; when the callback is needed,
1303 the HAL_FMAC_GetDataCallback can be implemented in the user file.
1308 * @brief FMAC half output data ready callback.
1309 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1310 * the configuration information for FMAC module.
1313 __weak
void HAL_FMAC_HalfOutputDataReadyCallback(FMAC_HandleTypeDef
*hfmac
)
1315 /* Prevent unused argument(s) compilation warning */
1318 /* NOTE : This function should not be modified; when the callback is needed,
1319 the HAL_FMAC_HalfOutputDataReadyCallback can be implemented in the user file.
1324 * @brief FMAC output data ready callback.
1325 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1326 * the configuration information for FMAC module.
1329 __weak
void HAL_FMAC_OutputDataReadyCallback(FMAC_HandleTypeDef
*hfmac
)
1331 /* Prevent unused argument(s) compilation warning */
1334 /* NOTE : This function should not be modified; when the callback is needed,
1335 the HAL_FMAC_OutputDataReadyCallback can be implemented in the user file.
1340 * @brief FMAC filter configuration callback.
1341 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1342 * the configuration information for FMAC module.
1345 __weak
void HAL_FMAC_FilterConfigCallback(FMAC_HandleTypeDef
*hfmac
)
1347 /* Prevent unused argument(s) compilation warning */
1350 /* NOTE : This function should not be modified; when the callback is needed,
1351 the HAL_FMAC_FilterConfigCallback can be implemented in the user file.
1356 * @brief FMAC filter preload callback.
1357 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1358 * the configuration information for FMAC module.
1361 __weak
void HAL_FMAC_FilterPreloadCallback(FMAC_HandleTypeDef
*hfmac
)
1363 /* Prevent unused argument(s) compilation warning */
1366 /* NOTE : This function should not be modified; when the callback is needed,
1367 the HAL_FMAC_FilterPreloadCallback can be implemented in the user file.
1375 /** @defgroup FMAC_Exported_Functions_Group4 IRQ handler management
1376 * @brief IRQ handler.
1379 ==============================================================================
1380 ##### IRQ handler management #####
1381 ==============================================================================
1382 [..] This section provides IRQ handler function.
1389 * @brief Handle FMAC interrupt request.
1390 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1391 * the configuration information for FMAC module.
1394 void HAL_FMAC_IRQHandler(FMAC_HandleTypeDef
*hfmac
)
1398 /* Check if the read interrupt is enabled and if Y buffer empty flag isn't set */
1399 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_RIEN
);
1400 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_YEMPTY
) == 0U) && (itsource
!= 0UL))
1402 /* Read some data if possible (Y size is used as a pseudo timeout in order
1403 to not get stuck too long under IT if FMAC keeps on processing input
1404 data reloaded via DMA for instance). */
1405 if (hfmac
->pOutput
!= NULL
)
1407 FMAC_ReadDataIncrementPtr(hfmac
, (uint16_t)FMAC_GET_Y_SIZE(hfmac
));
1410 /* Indicate that data is ready to be read */
1411 if ((hfmac
->pOutput
== NULL
) || (hfmac
->OutputCurrentSize
== *(hfmac
->pOutputSize
)))
1413 /* Reset the pointers to indicate new data will be needed */
1414 FMAC_ResetOutputStateAndDataPointers(hfmac
);
1416 /* Call the output data ready callback */
1417 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
1418 hfmac
->OutputDataReadyCallback(hfmac
);
1420 HAL_FMAC_OutputDataReadyCallback(hfmac
);
1421 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
1425 /* Check if the write interrupt is enabled and if X1 buffer full flag isn't set */
1426 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_WIEN
);
1427 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_X1FULL
) == 0U) && (itsource
!= 0UL))
1429 /* Write some data if possible (X1 size is used as a pseudo timeout in order
1430 to not get stuck too long under IT if FMAC keep on processing input
1431 data whereas its output emptied via DMA for instance). */
1432 if (hfmac
->pInput
!= NULL
)
1434 FMAC_WriteDataIncrementPtr(hfmac
, (uint16_t)FMAC_GET_X1_SIZE(hfmac
));
1437 /* Indicate that new data will be needed */
1438 if ((hfmac
->pInput
== NULL
) || (hfmac
->InputCurrentSize
== *(hfmac
->pInputSize
)))
1440 /* Reset the pointers to indicate new data will be needed */
1441 FMAC_ResetInputStateAndDataPointers(hfmac
);
1443 /* Call the get data callback */
1444 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
1445 hfmac
->GetDataCallback(hfmac
);
1447 HAL_FMAC_GetDataCallback(hfmac
);
1448 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
1452 /* Check if the overflow error interrupt is enabled and if overflow error flag is raised */
1453 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_OVFLIEN
);
1454 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_OVFL
) != 0U) && (itsource
!= 0UL))
1456 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_OVFL
;
1459 /* Check if the underflow error interrupt is enabled and if underflow error flag is raised */
1460 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_UNFLIEN
);
1461 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_UNFL
) != 0U) && (itsource
!= 0UL))
1463 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_UNFL
;
1466 /* Check if the saturation error interrupt is enabled and if saturation error flag is raised */
1467 itsource
= __HAL_FMAC_GET_IT_SOURCE(hfmac
, FMAC_IT_SATIEN
);
1468 if ((__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_SAT
) != 0U) && (itsource
!= 0UL))
1470 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_SAT
;
1473 /* Call the error callback if an error occurred */
1474 if (hfmac
->ErrorCode
!= HAL_FMAC_ERROR_NONE
)
1476 /* Call the error callback */
1477 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
1478 hfmac
->ErrorCallback(hfmac
);
1480 HAL_FMAC_ErrorCallback(hfmac
);
1481 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
1489 /** @defgroup FMAC_Exported_Functions_Group5 Peripheral State functions
1490 * @brief Peripheral State functions.
1493 ==============================================================================
1494 ##### Peripheral State functions #####
1495 ==============================================================================
1497 This subsection permits to get in run-time the status of the peripheral.
1504 * @brief Return the FMAC handle state.
1505 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1506 * the configuration information for FMAC module.
1509 HAL_FMAC_StateTypeDef
HAL_FMAC_GetState(FMAC_HandleTypeDef
*hfmac
)
1511 /* Return FMAC handle state */
1512 return hfmac
->State
;
1516 * @brief Return the FMAC peripheral error.
1517 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1518 * the configuration information for FMAC module.
1519 * @note The returned error is a bit-map combination of possible errors.
1520 * @retval Error bit-map
1522 uint32_t HAL_FMAC_GetError(FMAC_HandleTypeDef
*hfmac
)
1524 /* Return FMAC error code */
1525 return hfmac
->ErrorCode
;
1536 /** @defgroup FMAC_Private_Functions FMAC Private Functions
1541 ==============================================================================
1542 ##### FMAC Private Functions #####
1543 ==============================================================================
1546 * @brief Perform a reset of the FMAC unit.
1547 * @param hfmac FMAC handle.
1548 * @retval FMAC status
1550 static HAL_StatusTypeDef
FMAC_Reset(FMAC_HandleTypeDef
*hfmac
)
1554 /* Init tickstart for timeout management*/
1555 tickstart
= HAL_GetTick();
1557 /* Perform the reset */
1558 SET_BIT(hfmac
->Instance
->CR
, FMAC_CR_RESET
);
1560 /* Wait until flag is reset */
1561 while (READ_BIT(hfmac
->Instance
->CR
, FMAC_CR_RESET
) != 0UL)
1563 if ((HAL_GetTick() - tickstart
) > HAL_FMAC_RESET_TIMEOUT_VALUE
)
1569 hfmac
->ErrorCode
= HAL_FMAC_ERROR_NONE
;
1574 * @brief Reset the data pointers of the FMAC unit.
1575 * @param hfmac FMAC handle.
1576 * @retval FMAC status
1578 static void FMAC_ResetDataPointers(FMAC_HandleTypeDef
*hfmac
)
1580 FMAC_ResetInputStateAndDataPointers(hfmac
);
1581 FMAC_ResetOutputStateAndDataPointers(hfmac
);
1585 * @brief Reset the input data pointers of the FMAC unit.
1586 * @param hfmac FMAC handle.
1587 * @retval FMAC status
1589 static void FMAC_ResetInputStateAndDataPointers(FMAC_HandleTypeDef
*hfmac
)
1591 hfmac
->pInput
= NULL
;
1592 hfmac
->pInputSize
= NULL
;
1593 hfmac
->InputCurrentSize
= 0U;
1594 hfmac
->WrState
= HAL_FMAC_STATE_READY
;
1598 * @brief Reset the output data pointers of the FMAC unit.
1599 * @param hfmac FMAC handle.
1600 * @retval FMAC status
1602 static void FMAC_ResetOutputStateAndDataPointers(FMAC_HandleTypeDef
*hfmac
)
1604 hfmac
->pOutput
= NULL
;
1605 hfmac
->pOutputSize
= NULL
;
1606 hfmac
->OutputCurrentSize
= 0U;
1607 hfmac
->RdState
= HAL_FMAC_STATE_READY
;
1611 * @brief Configure the FMAC filter according to the parameters
1612 specified in the FMAC_FilterConfigTypeDef structure.
1613 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1614 * the configuration information for FMAC module.
1615 * @param sConfig pointer to a FMAC_FilterConfigTypeDef structure that
1616 * contains the FMAC configuration information.
1617 * @retval HAL status
1619 static HAL_StatusTypeDef
FMAC_FilterConfig(FMAC_HandleTypeDef
*hfmac
, FMAC_FilterConfigTypeDef
*sConfig
,
1620 uint8_t PreloadAccess
)
1624 #if defined(USE_FULL_ASSERT)
1626 #endif /* USE_FULL_ASSERT */
1628 /* Check the parameters */
1629 assert_param(IS_FMAC_THRESHOLD(sConfig
->InputThreshold
));
1630 assert_param(IS_FMAC_THRESHOLD(sConfig
->OutputThreshold
));
1631 assert_param(IS_FMAC_BUFFER_ACCESS(sConfig
->InputAccess
));
1632 assert_param(IS_FMAC_BUFFER_ACCESS(sConfig
->OutputAccess
));
1633 assert_param(IS_FMAC_CLIP_STATE(sConfig
->Clip
));
1634 assert_param(IS_FMAC_FILTER_FUNCTION(sConfig
->Filter
));
1635 assert_param(IS_FMAC_PARAM_P(sConfig
->Filter
, sConfig
->P
));
1636 assert_param(IS_FMAC_PARAM_Q(sConfig
->Filter
, sConfig
->Q
));
1637 assert_param(IS_FMAC_PARAM_R(sConfig
->Filter
, sConfig
->R
));
1639 /* Check the START bit state */
1640 if (FMAC_GET_START_BIT(hfmac
) != 0UL)
1645 /* Check handle state is ready */
1646 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
1648 /* Change the FMAC state */
1649 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
1652 tickstart
= HAL_GetTick();
1654 /* Indicate that there is no valid configuration done */
1655 hfmac
->FilterParam
= 0UL;
1657 /* FMAC_X1BUFCFG: Configure the input buffer within the internal memory if required */
1658 if (sConfig
->InputBufferSize
!= 0U)
1660 MODIFY_REG(hfmac
->Instance
->X1BUFCFG
, \
1661 (FMAC_X1BUFCFG_X1_BASE
| FMAC_X1BUFCFG_X1_BUF_SIZE
), \
1662 (((((uint32_t)(sConfig
->InputBaseAddress
)) << FMAC_X1BUFCFG_X1_BASE_Pos
) & FMAC_X1BUFCFG_X1_BASE
) | \
1663 ((((uint32_t)(sConfig
->InputBufferSize
)) << FMAC_X1BUFCFG_X1_BUF_SIZE_Pos
) & FMAC_X1BUFCFG_X1_BUF_SIZE
)));
1666 /* FMAC_X1BUFCFG: Configure the input threshold if valid when compared to the configured X1 size */
1667 if (sConfig
->InputThreshold
!= FMAC_THRESHOLD_NO_VALUE
)
1669 /* Check the parameter */
1670 assert_param(IS_FMAC_THRESHOLD_APPLICABLE(FMAC_GET_X1_SIZE(hfmac
), sConfig
->InputThreshold
, sConfig
->InputAccess
));
1672 MODIFY_REG(hfmac
->Instance
->X1BUFCFG
, \
1673 FMAC_X1BUFCFG_FULL_WM
, \
1674 ((sConfig
->InputThreshold
) & FMAC_X1BUFCFG_FULL_WM
));
1677 /* FMAC_X2BUFCFG: Configure the coefficient buffer within the internal memory */
1678 if (sConfig
->CoeffBufferSize
!= 0U)
1680 MODIFY_REG(hfmac
->Instance
->X2BUFCFG
, \
1681 (FMAC_X2BUFCFG_X2_BASE
| FMAC_X2BUFCFG_X2_BUF_SIZE
), \
1682 (((((uint32_t)(sConfig
->CoeffBaseAddress
)) << FMAC_X2BUFCFG_X2_BASE_Pos
) & FMAC_X2BUFCFG_X2_BASE
) | \
1683 ((((uint32_t)(sConfig
->CoeffBufferSize
)) << FMAC_X2BUFCFG_X2_BUF_SIZE_Pos
) & FMAC_X2BUFCFG_X2_BUF_SIZE
)));
1686 /* FMAC_YBUFCFG: Configure the output buffer within the internal memory if required */
1687 if (sConfig
->OutputBufferSize
!= 0U)
1689 MODIFY_REG(hfmac
->Instance
->YBUFCFG
, \
1690 (FMAC_YBUFCFG_Y_BASE
| FMAC_YBUFCFG_Y_BUF_SIZE
), \
1691 (((((uint32_t)(sConfig
->OutputBaseAddress
)) << FMAC_YBUFCFG_Y_BASE_Pos
) & FMAC_YBUFCFG_Y_BASE
) | \
1692 ((((uint32_t)(sConfig
->OutputBufferSize
)) << FMAC_YBUFCFG_Y_BUF_SIZE_Pos
) & FMAC_YBUFCFG_Y_BUF_SIZE
)));
1695 /* FMAC_YBUFCFG: Configure the output threshold if valid when compared to the configured Y size */
1696 if (sConfig
->OutputThreshold
!= FMAC_THRESHOLD_NO_VALUE
)
1698 /* Check the parameter */
1699 assert_param(IS_FMAC_THRESHOLD_APPLICABLE(FMAC_GET_Y_SIZE(hfmac
), sConfig
->OutputThreshold
, sConfig
->OutputAccess
));
1701 MODIFY_REG(hfmac
->Instance
->YBUFCFG
, \
1702 FMAC_YBUFCFG_EMPTY_WM
, \
1703 ((sConfig
->OutputThreshold
) & FMAC_YBUFCFG_EMPTY_WM
));
1706 /* CR: Configure the clip feature */
1707 tmpcr
= sConfig
->Clip
& FMAC_CR_CLIPEN
;
1709 /* CR: If IT or DMA will be used, enable error interrupts.
1710 * Being more a debugging feature, FMAC_CR_SATIEN isn't enabled by default. */
1711 if ((sConfig
->InputAccess
== FMAC_BUFFER_ACCESS_DMA
) || (sConfig
->InputAccess
== FMAC_BUFFER_ACCESS_IT
) ||
1712 (sConfig
->OutputAccess
== FMAC_BUFFER_ACCESS_DMA
) || (sConfig
->OutputAccess
== FMAC_BUFFER_ACCESS_IT
))
1714 tmpcr
|= FMAC_IT_UNFLIEN
| FMAC_IT_OVFLIEN
;
1717 /* CR: write the value */
1718 WRITE_REG(hfmac
->Instance
->CR
, tmpcr
);
1720 /* Save the input/output accesses in order to configure RIEN, WIEN, DMAREN and DMAWEN during filter start */
1721 hfmac
->InputAccess
= sConfig
->InputAccess
;
1722 hfmac
->OutputAccess
= sConfig
->OutputAccess
;
1724 /* Check whether the configured X2 is big enough for the filter */
1725 #if defined(USE_FULL_ASSERT)
1726 x2size
= FMAC_GET_X2_SIZE(hfmac
);
1727 #endif /* USE_FULL_ASSERT */
1728 assert_param(((sConfig
->Filter
== FMAC_FUNC_CONVO_FIR
) && (x2size
>= sConfig
->P
)) || \
1729 ((sConfig
->Filter
== FMAC_FUNC_IIR_DIRECT_FORM_1
) && (x2size
>= ((uint32_t)sConfig
->P
+ (uint32_t)sConfig
->Q
))));
1731 /* Build the PARAM value that will be used when starting the filter */
1732 hfmac
->FilterParam
= (FMAC_PARAM_START
| sConfig
->Filter
| \
1733 ((((uint32_t)(sConfig
->P
)) << FMAC_PARAM_P_Pos
) & FMAC_PARAM_P
) | \
1734 ((((uint32_t)(sConfig
->Q
)) << FMAC_PARAM_Q_Pos
) & FMAC_PARAM_Q
) | \
1735 ((((uint32_t)(sConfig
->R
)) << FMAC_PARAM_R_Pos
) & FMAC_PARAM_R
));
1737 /* Initialize the coefficient buffer if required (pCoeffA for FIR only) */
1738 if ((sConfig
->pCoeffB
!= NULL
) && (sConfig
->CoeffBSize
!= 0U))
1740 /* FIR/IIR: The provided coefficients should match X2 size */
1741 assert_param(((uint32_t)sConfig
->CoeffASize
+ (uint32_t)sConfig
->CoeffBSize
) <= x2size
);
1742 /* FIR/IIR: The size of pCoeffB should match the parameter P */
1743 assert_param(sConfig
->CoeffBSize
>= sConfig
->P
);
1744 /* pCoeffA should be provided for IIR but not for FIR */
1745 /* IIR : if pCoeffB is provided, pCoeffA should also be there */
1746 /* IIR: The size of pCoeffA should match the parameter Q */
1747 assert_param(((sConfig
->Filter
== FMAC_FUNC_CONVO_FIR
) &&
1748 (sConfig
->pCoeffA
== NULL
) && (sConfig
->CoeffASize
== 0U)) ||
1749 ((sConfig
->Filter
== FMAC_FUNC_IIR_DIRECT_FORM_1
) &&
1750 (sConfig
->pCoeffA
!= NULL
) && (sConfig
->CoeffASize
!= 0U) &&
1751 (sConfig
->CoeffASize
>= sConfig
->Q
)));
1753 /* Write number of values to be loaded, the data load function and start the operation */
1754 WRITE_REG(hfmac
->Instance
->PARAM
, \
1755 (((uint32_t)(sConfig
->CoeffBSize
) << FMAC_PARAM_P_Pos
) | \
1756 ((uint32_t)(sConfig
->CoeffASize
) << FMAC_PARAM_Q_Pos
) | \
1757 FMAC_FUNC_LOAD_X2
| FMAC_PARAM_START
));
1759 if (PreloadAccess
== PRELOAD_ACCESS_POLLING
)
1761 /* Load the buffer into the internal memory */
1762 FMAC_WritePreloadDataIncrementPtr(hfmac
, &(sConfig
->pCoeffB
), sConfig
->CoeffBSize
);
1764 /* Load pCoeffA if needed */
1765 if ((sConfig
->pCoeffA
!= NULL
) && (sConfig
->CoeffASize
!= 0U))
1767 /* Load the buffer into the internal memory */
1768 FMAC_WritePreloadDataIncrementPtr(hfmac
, &(sConfig
->pCoeffA
), sConfig
->CoeffASize
);
1771 /* Wait for the end of the writing */
1772 if (FMAC_WaitOnStartUntilTimeout(hfmac
, tickstart
, HAL_FMAC_TIMEOUT_VALUE
) != HAL_OK
)
1774 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
1778 /* Change the FMAC state */
1779 hfmac
->State
= HAL_FMAC_STATE_READY
;
1783 hfmac
->pInput
= sConfig
->pCoeffA
;
1784 hfmac
->InputCurrentSize
= sConfig
->CoeffASize
;
1786 /* Set the FMAC DMA transfer complete callback */
1787 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
1788 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterConfig
;
1789 /* Set the DMA error callback */
1790 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
1792 /* Enable the DMA stream managing FMAC preload data write */
1793 return (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)sConfig
->pCoeffB
, (uint32_t)&hfmac
->Instance
->WDATA
,
1794 sConfig
->CoeffBSize
));
1799 /* Change the FMAC state */
1800 hfmac
->State
= HAL_FMAC_STATE_READY
;
1805 /* Return function status */
1809 /* Return function status */
1814 * @brief Preload the input (FIR, IIR) and output data (IIR) of the FMAC filter.
1815 * They will be used by FMAC as soon as HAL_FMAC_FilterStart is called.
1816 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1817 * the configuration information for FMAC module.
1818 * @param pInput Preloading of the first elements of the input buffer (X1).
1819 * If not needed (no data available when starting), it should be set to NULL.
1820 * @param InputSize Size of the input vector.
1821 * As pInput is used for preloading data, it cannot be bigger than the input memory area.
1822 * @param pOutput [IIR] Preloading of the first elements of the output vector (Y).
1823 * If not needed, it should be set to NULL.
1824 * @param OutputSize Size of the output vector.
1825 * As pOutput is used for preloading data, it cannot be bigger than the output memory area.
1826 * @note The input and the output buffers can be filled by calling several times HAL_FMAC_FilterPreload
1827 * (each call filling partly the buffers). In case of overflow (too much data provided through
1828 * all these calls), an error will be returned.
1829 * @retval HAL status
1831 static HAL_StatusTypeDef
FMAC_FilterPreload(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
, uint8_t InputSize
,
1832 int16_t *pOutput
, uint8_t OutputSize
, uint8_t PreloadAccess
)
1836 /* Check the START bit state */
1837 if (FMAC_GET_START_BIT(hfmac
) != 0UL)
1842 /* Check that a valid configuration was done previously */
1843 if (hfmac
->FilterParam
== 0UL)
1848 /* Check the preload input buffers isn't too big */
1849 if ((InputSize
> FMAC_GET_X1_SIZE(hfmac
)) && (pInput
!= NULL
))
1854 /* Check the preload output buffer isn't too big */
1855 if ((OutputSize
> FMAC_GET_Y_SIZE(hfmac
)) && (pOutput
!= NULL
))
1860 /* Check handle state is ready */
1861 if (hfmac
->State
== HAL_FMAC_STATE_READY
)
1863 /* Change the FMAC state */
1864 hfmac
->State
= HAL_FMAC_STATE_BUSY
;
1867 tickstart
= HAL_GetTick();
1869 /* Preload the input buffer if required */
1870 if ((pInput
!= NULL
) && (InputSize
!= 0U))
1872 /* Write number of values to be loaded, the data load function and start the operation */
1873 WRITE_REG(hfmac
->Instance
->PARAM
, \
1874 (((uint32_t)InputSize
<< FMAC_PARAM_P_Pos
) | FMAC_FUNC_LOAD_X1
| FMAC_PARAM_START
));
1876 if (PreloadAccess
== PRELOAD_ACCESS_POLLING
)
1878 /* Load the buffer into the internal memory */
1879 FMAC_WritePreloadDataIncrementPtr(hfmac
, &pInput
, InputSize
);
1881 /* Wait for the end of the writing */
1882 if (FMAC_WaitOnStartUntilTimeout(hfmac
, tickstart
, HAL_FMAC_TIMEOUT_VALUE
) != HAL_OK
)
1884 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
1890 hfmac
->pInput
= pOutput
;
1891 hfmac
->InputCurrentSize
= OutputSize
;
1893 /* Set the FMAC DMA transfer complete callback */
1894 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
1895 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterPreload
;
1896 /* Set the DMA error callback */
1897 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
1899 /* Enable the DMA stream managing FMAC preload data write */
1900 return (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)pInput
, (uint32_t)&hfmac
->Instance
->WDATA
, InputSize
));
1904 /* Preload the output buffer if required */
1905 if ((pOutput
!= NULL
) && (OutputSize
!= 0U))
1907 /* Write number of values to be loaded, the data load function and start the operation */
1908 WRITE_REG(hfmac
->Instance
->PARAM
, \
1909 (((uint32_t)OutputSize
<< FMAC_PARAM_P_Pos
) | FMAC_FUNC_LOAD_Y
| FMAC_PARAM_START
));
1911 if (PreloadAccess
== PRELOAD_ACCESS_POLLING
)
1913 /* Load the buffer into the internal memory */
1914 FMAC_WritePreloadDataIncrementPtr(hfmac
, &pOutput
, OutputSize
);
1916 /* Wait for the end of the writing */
1917 if (FMAC_WaitOnStartUntilTimeout(hfmac
, tickstart
, HAL_FMAC_TIMEOUT_VALUE
) != HAL_OK
)
1919 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
1925 hfmac
->pInput
= NULL
;
1926 hfmac
->InputCurrentSize
= 0U;
1928 /* Set the FMAC DMA transfer complete callback */
1929 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
1930 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterPreload
;
1931 /* Set the DMA error callback */
1932 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
1934 /* Enable the DMA stream managing FMAC preload data write */
1935 return (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)pOutput
, (uint32_t)&hfmac
->Instance
->WDATA
, OutputSize
));
1939 /* Update the error codes */
1940 if (__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_OVFL
))
1942 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_OVFL
;
1944 if (__HAL_FMAC_GET_FLAG(hfmac
, FMAC_FLAG_UNFL
))
1946 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_UNFL
;
1949 /* Change the FMAC state */
1950 hfmac
->State
= HAL_FMAC_STATE_READY
;
1952 /* Return function status */
1953 if (hfmac
->ErrorCode
== HAL_FMAC_ERROR_NONE
)
1964 /* Return function status */
1970 * @brief Write data into FMAC internal memory through WDATA and increment input buffer pointer.
1971 * This function is only used with preload functions.
1972 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
1973 * the configuration information for FMAC module.
1974 * @param ppData pointer to pointer to the data buffer.
1975 * @param Size size of the data buffer.
1978 static void FMAC_WritePreloadDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, int16_t **ppData
, uint8_t Size
)
1982 /* Load the buffer into the internal memory */
1983 for (index
= Size
; index
> 0U; index
--)
1985 WRITE_REG(hfmac
->Instance
->WDATA
, (((uint32_t)(*(*ppData
))) & FMAC_WDATA_WDATA
));
1991 * @brief Handle FMAC Function Timeout.
1992 * @param hfmac FMAC handle.
1993 * @param Tickstart Tick start value.
1994 * @param Timeout Timeout duration.
1995 * @retval HAL status
1997 static HAL_StatusTypeDef
FMAC_WaitOnStartUntilTimeout(FMAC_HandleTypeDef
*hfmac
, uint32_t Tickstart
, uint32_t Timeout
)
1999 /* Wait until flag changes */
2000 while (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) != 0UL)
2002 if ((HAL_GetTick() - Tickstart
) > Timeout
)
2004 /* Process Unlocked */
2005 __HAL_UNLOCK(hfmac
);
2014 * @brief Register the new input buffer, update DMA configuration
2015 * if needed and change the FMAC state.
2016 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
2017 * the configuration information for FMAC module.
2018 * @param pInput New input vector (additional input data).
2019 * @param pInputSize Size of the input vector (if all the data can't be
2020 * written, it will be updated with the number of data read from FMAC).
2021 * @retval HAL status
2023 static HAL_StatusTypeDef
FMAC_AppendFilterDataUpdateState(FMAC_HandleTypeDef
*hfmac
, int16_t *pInput
,
2024 uint16_t *pInputSize
)
2026 /* Change the FMAC state */
2027 hfmac
->WrState
= HAL_FMAC_STATE_BUSY_WR
;
2029 /* Reset the current size */
2030 hfmac
->InputCurrentSize
= 0U;
2032 /* Handle the pointer depending on the input access */
2033 if (hfmac
->InputAccess
== FMAC_BUFFER_ACCESS_DMA
)
2035 hfmac
->pInput
= NULL
;
2036 hfmac
->pInputSize
= NULL
;
2038 /* Set the FMAC DMA transfer complete callback */
2039 hfmac
->hdmaIn
->XferHalfCpltCallback
= FMAC_DMAHalfGetData
;
2040 hfmac
->hdmaIn
->XferCpltCallback
= FMAC_DMAGetData
;
2041 /* Set the DMA error callback */
2042 hfmac
->hdmaIn
->XferErrorCallback
= FMAC_DMAError
;
2044 /* Enable the DMA stream managing FMAC input data write */
2045 return (HAL_DMA_Start_IT(hfmac
->hdmaIn
, (uint32_t)pInput
, (uint32_t)&hfmac
->Instance
->WDATA
, *pInputSize
));
2049 /* Update the input data information (polling, IT) */
2050 hfmac
->pInput
= pInput
;
2051 hfmac
->pInputSize
= pInputSize
;
2054 /* Return function status */
2059 * @brief Register the new output buffer, update DMA configuration
2060 * if needed and change the FMAC state.
2061 * @param hfmac pointer to a FMAC_HandleTypeDef structure that contains
2062 * the configuration information for FMAC module.
2063 * @param pOutput New output vector.
2064 * @param pOutputSize Size of the output vector (if the vector can't
2065 * be entirely filled, pOutputSize will be updated with the number
2066 * of data read from FMAC).
2067 * @retval HAL status
2069 static HAL_StatusTypeDef
FMAC_ConfigFilterOutputBufferUpdateState(FMAC_HandleTypeDef
*hfmac
, int16_t *pOutput
,
2070 uint16_t *pOutputSize
)
2072 /* Reset the current size */
2073 hfmac
->OutputCurrentSize
= 0U;
2075 /* Check whether a valid pointer was provided */
2076 if ((pOutput
== NULL
) || (pOutputSize
== NULL
) || (*pOutputSize
== 0UL))
2078 /* The user will have to provide a valid configuration later */
2079 hfmac
->pOutput
= NULL
;
2080 hfmac
->pOutputSize
= NULL
;
2081 hfmac
->RdState
= HAL_FMAC_STATE_READY
;
2083 /* Handle the pointer depending on the input access */
2084 else if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_DMA
)
2086 hfmac
->pOutput
= NULL
;
2087 hfmac
->pOutputSize
= NULL
;
2088 hfmac
->RdState
= HAL_FMAC_STATE_BUSY_RD
;
2090 /* Set the FMAC DMA transfer complete callback */
2091 hfmac
->hdmaOut
->XferHalfCpltCallback
= FMAC_DMAHalfOutputDataReady
;
2092 hfmac
->hdmaOut
->XferCpltCallback
= FMAC_DMAOutputDataReady
;
2093 /* Set the DMA error callback */
2094 hfmac
->hdmaOut
->XferErrorCallback
= FMAC_DMAError
;
2096 /* Enable the DMA stream managing FMAC output data read */
2097 return (HAL_DMA_Start_IT(hfmac
->hdmaOut
, (uint32_t)&hfmac
->Instance
->RDATA
, (uint32_t)pOutput
, *pOutputSize
));
2099 else if (hfmac
->OutputAccess
== FMAC_BUFFER_ACCESS_NONE
)
2101 hfmac
->pOutput
= NULL
;
2102 hfmac
->pOutputSize
= NULL
;
2103 hfmac
->RdState
= HAL_FMAC_STATE_READY
;
2107 /* Update the output data information (polling, IT) */
2108 hfmac
->pOutput
= pOutput
;
2109 hfmac
->pOutputSize
= pOutputSize
;
2110 hfmac
->RdState
= HAL_FMAC_STATE_BUSY_RD
;
2113 /* Return function status */
2118 * @brief Read available output data until Y EMPTY is set.
2119 * @param hfmac FMAC handle.
2120 * @param MaxSizeToRead Maximum number of data to read (this serves as a timeout
2121 * if FMAC continuously writes into the output buffer).
2122 * @retval HAL status
2124 static void FMAC_ReadDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, uint16_t MaxSizeToRead
)
2130 /* Check if there is data to read */
2131 if (READ_BIT(hfmac
->Instance
->SR
, FMAC_SR_YEMPTY
) != 0UL)
2136 /* Get the maximum index (no wait allowed, no overstepping of the output buffer) */
2137 if ((hfmac
->OutputCurrentSize
+ MaxSizeToRead
) > *(hfmac
->pOutputSize
))
2139 maxsize
= *(hfmac
->pOutputSize
);
2143 maxsize
= hfmac
->OutputCurrentSize
+ MaxSizeToRead
;
2146 /* Read until there is no more room or no more data */
2149 /* If there is no more room, return */
2150 if (!(hfmac
->OutputCurrentSize
< maxsize
))
2155 /* Read the available data */
2156 tmpvalue
= ((READ_REG(hfmac
->Instance
->RDATA
))& FMAC_RDATA_RDATA
);
2157 *(hfmac
->pOutput
) = (int16_t)tmpvalue
;
2159 hfmac
->OutputCurrentSize
++;
2160 } while (READ_BIT(hfmac
->Instance
->SR
, FMAC_SR_YEMPTY
) == 0UL);
2162 /* Y buffer empty flag has just be raised, read the threshold */
2163 threshold
= (uint16_t)FMAC_GET_THRESHOLD_FROM_WM(FMAC_GET_Y_EMPTY_WM(hfmac
)) - 1U;
2165 /* Update the maximum size if needed (limited data available) */
2166 if ((hfmac
->OutputCurrentSize
+ threshold
) < maxsize
)
2168 maxsize
= hfmac
->OutputCurrentSize
+ threshold
;
2171 /* Read the available data */
2172 while (hfmac
->OutputCurrentSize
< maxsize
)
2174 tmpvalue
= ((READ_REG(hfmac
->Instance
->RDATA
))& FMAC_RDATA_RDATA
);
2175 *(hfmac
->pOutput
) = (int16_t)tmpvalue
;
2177 hfmac
->OutputCurrentSize
++;
2182 * @brief Write available input data until X1 FULL is set.
2183 * @param hfmac FMAC handle.
2184 * @param MaxSizeToWrite Maximum number of data to write (this serves as a timeout
2185 * if FMAC continuously empties the input buffer).
2186 * @retval HAL status
2188 static void FMAC_WriteDataIncrementPtr(FMAC_HandleTypeDef
*hfmac
, uint16_t MaxSizeToWrite
)
2193 /* Check if there is room in FMAC */
2194 if (READ_BIT(hfmac
->Instance
->SR
, FMAC_SR_X1FULL
) != 0UL)
2199 /* Get the maximum index (no wait allowed, no overstepping of the output buffer) */
2200 if ((hfmac
->InputCurrentSize
+ MaxSizeToWrite
) > *(hfmac
->pInputSize
))
2202 maxsize
= *(hfmac
->pInputSize
);
2206 maxsize
= hfmac
->InputCurrentSize
+ MaxSizeToWrite
;
2209 /* Write until there is no more room or no more data */
2212 /* If there is no more room, return */
2213 if (!(hfmac
->InputCurrentSize
< maxsize
))
2218 /* Write the available data */
2219 WRITE_REG(hfmac
->Instance
->WDATA
, (((uint32_t)(*(hfmac
->pInput
))) & FMAC_WDATA_WDATA
));
2221 hfmac
->InputCurrentSize
++;
2222 } while (READ_BIT(hfmac
->Instance
->SR
, FMAC_SR_X1FULL
) == 0UL);
2224 /* X1 buffer full flag has just be raised, read the threshold */
2225 threshold
= (uint16_t)FMAC_GET_THRESHOLD_FROM_WM(FMAC_GET_X1_FULL_WM(hfmac
)) - 1U;
2227 /* Update the maximum size if needed (limited data available) */
2228 if ((hfmac
->InputCurrentSize
+ threshold
) < maxsize
)
2230 maxsize
= hfmac
->InputCurrentSize
+ threshold
;
2233 /* Write the available data */
2234 while (hfmac
->InputCurrentSize
< maxsize
)
2236 WRITE_REG(hfmac
->Instance
->WDATA
, (((uint32_t)(*(hfmac
->pInput
))) & FMAC_WDATA_WDATA
));
2238 hfmac
->InputCurrentSize
++;
2243 * @brief DMA FMAC Input Data process half complete callback.
2244 * @param hdma DMA handle.
2247 static void FMAC_DMAHalfGetData(DMA_HandleTypeDef
*hdma
)
2249 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2251 /* Call half get data callback */
2252 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2253 hfmac
->HalfGetDataCallback(hfmac
);
2255 HAL_FMAC_HalfGetDataCallback(hfmac
);
2256 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2260 * @brief DMA FMAC Input Data process complete callback.
2261 * @param hdma DMA handle.
2264 static void FMAC_DMAGetData(DMA_HandleTypeDef
*hdma
)
2266 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2268 /* Reset the pointers to indicate new data will be needed */
2269 FMAC_ResetInputStateAndDataPointers(hfmac
);
2271 /* Call get data callback */
2272 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2273 hfmac
->GetDataCallback(hfmac
);
2275 HAL_FMAC_GetDataCallback(hfmac
);
2276 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2280 * @brief DMA FMAC Output Data process half complete callback.
2281 * @param hdma DMA handle.
2284 static void FMAC_DMAHalfOutputDataReady(DMA_HandleTypeDef
*hdma
)
2286 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2288 /* Call half output data ready callback */
2289 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2290 hfmac
->HalfOutputDataReadyCallback(hfmac
);
2292 HAL_FMAC_HalfOutputDataReadyCallback(hfmac
);
2293 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2297 * @brief DMA FMAC Output Data process complete callback.
2298 * @param hdma DMA handle.
2301 static void FMAC_DMAOutputDataReady(DMA_HandleTypeDef
*hdma
)
2303 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2305 /* Reset the pointers to indicate new data will be needed */
2306 FMAC_ResetOutputStateAndDataPointers(hfmac
);
2308 /* Call output data ready callback */
2309 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2310 hfmac
->OutputDataReadyCallback(hfmac
);
2312 HAL_FMAC_OutputDataReadyCallback(hfmac
);
2313 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2317 * @brief DMA FMAC Filter Configuration process complete callback.
2318 * @param hdma DMA handle.
2321 static void FMAC_DMAFilterConfig(DMA_HandleTypeDef
*hdma
)
2325 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2327 /* If needed, write CoeffA and exit */
2328 if (hfmac
->pInput
!= NULL
)
2330 /* Set the FMAC DMA transfer complete callback */
2331 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
2332 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterConfig
;
2333 /* Set the DMA error callback */
2334 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
2336 /* Enable the DMA stream managing FMAC preload data write */
2337 if (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)hfmac
->pInput
, (uint32_t)&hfmac
->Instance
->WDATA
,
2338 hfmac
->InputCurrentSize
) == HAL_OK
)
2340 hfmac
->pInput
= NULL
;
2341 hfmac
->InputCurrentSize
= 0U;
2345 /* If not exited, there was an error: set FMAC handle state to error */
2346 hfmac
->State
= HAL_FMAC_STATE_ERROR
;
2350 /* Wait for the end of the writing */
2351 for (index
= 0U; index
< 0xFFU
; index
++)
2353 if (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) == 0U)
2359 /* If 'START' is still set, there was an error: set FMAC handle state to error */
2360 if (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) != 0UL)
2362 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
2366 /* Change the FMAC state */
2367 hfmac
->State
= HAL_FMAC_STATE_READY
;
2369 /* Call output data ready callback */
2370 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2371 hfmac
->FilterConfigCallback(hfmac
);
2373 HAL_FMAC_FilterConfigCallback(hfmac
);
2374 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2379 /* If not exited, there was an error: set FMAC handle error code to DMA error */
2380 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_DMA
;
2382 /* Call user callback */
2383 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2384 hfmac
->ErrorCallback(hfmac
);
2386 HAL_FMAC_ErrorCallback(hfmac
);
2387 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2392 * @brief DMA FMAC Filter Configuration process complete callback.
2393 * @param hdma DMA handle.
2396 static void FMAC_DMAFilterPreload(DMA_HandleTypeDef
*hdma
)
2400 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2402 /* Wait for the end of the X1 writing */
2403 for (index
= 0U; index
< 0xFFU
; index
++)
2405 if (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) == 0UL)
2411 /* If 'START' is still set, there was an error: set FMAC handle state to error */
2412 if (READ_BIT(hfmac
->Instance
->PARAM
, FMAC_PARAM_START
) != 0UL)
2414 hfmac
->State
= HAL_FMAC_STATE_TIMEOUT
;
2415 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_TIMEOUT
;
2417 /* If needed, preload Y buffer */
2418 else if ((hfmac
->pInput
!= NULL
) && (hfmac
->InputCurrentSize
!= 0U))
2420 /* Write number of values to be loaded, the data load function and start the operation */
2421 WRITE_REG(hfmac
->Instance
->PARAM
, \
2422 (((uint32_t)(hfmac
->InputCurrentSize
) << FMAC_PARAM_P_Pos
) | FMAC_FUNC_LOAD_Y
| FMAC_PARAM_START
));
2424 /* Set the FMAC DMA transfer complete callback */
2425 hfmac
->hdmaPreload
->XferHalfCpltCallback
= NULL
;
2426 hfmac
->hdmaPreload
->XferCpltCallback
= FMAC_DMAFilterPreload
;
2427 /* Set the DMA error callback */
2428 hfmac
->hdmaPreload
->XferErrorCallback
= FMAC_DMAError
;
2430 /* Enable the DMA stream managing FMAC preload data write */
2431 if (HAL_DMA_Start_IT(hfmac
->hdmaPreload
, (uint32_t)hfmac
->pInput
, (uint32_t)&hfmac
->Instance
->WDATA
,
2432 hfmac
->InputCurrentSize
) == HAL_OK
)
2434 hfmac
->pInput
= NULL
;
2435 hfmac
->InputCurrentSize
= 0U;
2439 /* If not exited, there was an error */
2440 hfmac
->ErrorCode
= HAL_FMAC_ERROR_DMA
;
2441 hfmac
->State
= HAL_FMAC_STATE_ERROR
;
2448 /* Return function status */
2449 if (hfmac
->ErrorCode
== HAL_FMAC_ERROR_NONE
)
2451 /* Change the FMAC state */
2452 hfmac
->State
= HAL_FMAC_STATE_READY
;
2454 /* Call output data ready callback */
2455 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2456 hfmac
->FilterPreloadCallback(hfmac
);
2458 HAL_FMAC_FilterPreloadCallback(hfmac
);
2459 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2463 /* Call user callback */
2464 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2465 hfmac
->ErrorCallback(hfmac
);
2467 HAL_FMAC_ErrorCallback(hfmac
);
2468 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2474 * @brief DMA FMAC communication error callback.
2475 * @param hdma DMA handle.
2478 static void FMAC_DMAError(DMA_HandleTypeDef
*hdma
)
2480 FMAC_HandleTypeDef
*hfmac
= (FMAC_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
2482 /* Set FMAC handle state to error */
2483 hfmac
->State
= HAL_FMAC_STATE_ERROR
;
2485 /* Set FMAC handle error code to DMA error */
2486 hfmac
->ErrorCode
|= HAL_FMAC_ERROR_DMA
;
2488 /* Call user callback */
2489 #if (USE_HAL_FMAC_REGISTER_CALLBACKS == 1)
2490 hfmac
->ErrorCallback(hfmac
);
2492 HAL_FMAC_ErrorCallback(hfmac
);
2493 #endif /* USE_HAL_FMAC_REGISTER_CALLBACKS */
2508 #endif /* HAL_FMAC_MODULE_ENABLED */
2510 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/